Last active
June 27, 2023 15:03
-
-
Save chasset/e297d2c5e6c6dbf4802670d75ee2904d to your computer and use it in GitHub Desktop.
zeromq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* | |
!*.R | |
!*.js | |
!package.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PORT=55555 | |
R_VERSION="4.3.1" | |
R_USER="docker" | |
R_WORKDIR="/home/${R_USER}/app" | |
R_ZMQ_IMAGE="acisel-fr/r-zmq:latest" | |
NODE_VERSION="18.16.0" | |
JS_ZMQ_IMAGE="acisel-fr/js-zmq:latest" | |
JS_USER="node" | |
JS_WORKDIR="/home/${JS_USER}/app" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
replier: | |
build: | |
context: . | |
dockerfile: r.Dockerfile | |
target: r | |
args: | |
VERSION: ${R_VERSION} | |
USER: ${R_USER} | |
WORKDIR: ${R_WORKDIR} | |
image: ${R_ZMQ_IMAGE} | |
environment: | |
PORT: | |
command: Rscript replier.R | |
js-requester: | |
build: | |
context: . | |
dockerfile: js.Dockerfile | |
target: js | |
args: | |
NODE_VERSION: | |
USER: ${JS_USER} | |
WORKDIR: ${JS_WORKDIR} | |
image: ${JS_ZMQ_IMAGE} | |
depends_on: | |
- replier | |
working_dir: ${JS_WORKDIR} | |
environment: | |
PORT: | |
command: node requester.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG NODE_VERSION | |
FROM node:${NODE_VERSION} AS js | |
ARG USER | |
USER ${USER} | |
ARG WORKDIR | |
WORKDIR ${WORKDIR} | |
COPY --chown=${USER}:${USER} package.json ./ | |
RUN npm install | |
COPY --chown=${USER}:${USER} requester.js ./ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "zeromq-r", | |
"version": "1.0.0", | |
"main": "requester.js", | |
"dependencies": { | |
"zeromq": "6.0.0-beta.17" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG VERSION | |
FROM r-base:${VERSION} AS r | |
# Dependencies | |
RUN apt-get update \ | |
&& apt-get install -y \ | |
# rzmq | |
libzmq3-dev \ | |
&& rm -rf /var/lib/apt/lists/* | |
RUN Rscript -e 'install.packages("pbdZMQ")' | |
ARG USER | |
USER ${USER} | |
ARG WORKDIR | |
WORKDIR ${WORKDIR} | |
COPY --chown=${USER}:${USER} replier.R ./ | |
COPY --chown=${USER}:${USER} requester.R ./ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Rscript | |
library(pbdZMQ) | |
ctxt <- init.context() | |
socket <- init.socket(ctxt, "ZMQ_REP") | |
bind.socket(socket, "tcp://*:55555") | |
cat("Client command: ") | |
msg <- receive.socket(socket, unserialize=F) | |
cat("Message:", msg, "\n") | |
send.socket(socket, "Message received!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const zmq = require("zeromq"); | |
async function run() { | |
const sock = new zmq.Request(); | |
console.log("Wait a few seconds") | |
setTimeout(async ()=> { | |
console.log("Sending request") | |
sock.connect("tcp://replier:55555"); | |
await sock.send("rnorm"); | |
console.log("Request sended. Waiting for response") | |
const [result] = await sock.receive(); | |
console.log(result.toString()); | |
},2000) | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment