demo/tasksink.r

### Task sink from two workers as in the ZeroMQ guide.
# SHELL> Rscript taskwork.r &
# SHELL> Rscript taskvent.r; Rscript tasksink.r
### Remember to kill two worker processors at the end, such as
# SHELL> ps -x|grep "file=task.*\.r"|sed "s/\(.*\) pts.*/\1/"|xargs kill -9

suppressMessages(library(pbdZMQ, quietly = TRUE))

### Initial.
context <- zmq.ctx.new()
receiver <- zmq.socket(context, ZMQ.ST()$PULL)
zmq.bind(receiver, "tcp://*:5558")

### Wait for start of batch.
string <- zmq.recv(receiver)

### Process 100 confirmations.
start.time <- Sys.time()
for(i in 1:50){
  string <- zmq.recv(receiver)
  cat(i, ":", string$buf, "\n")
}
cat("Total elapsed time:", Sys.time() - start.time, "\n")

### Finish.
zmq.close(receiver)
zmq.ctx.destroy(context)

Try the pbdZMQ package in your browser

Any scripts or data that you put into this service are public.

pbdZMQ documentation built on Sept. 8, 2023, 6:06 p.m.