ropensci / rzmq

R package for ZMQ
https://docs.ropensci.org/rzmq
84 stars 30 forks source link

subscribe example? #22

Open paul-shannon opened 8 years ago

paul-shannon commented 8 years ago

?subscribe does not show an example (as far as I could see).
experimentation failed:

context <- init.context() socket <- init.socket(context, "ZMQ_REQ") connect.socket(socket, "tcp://localhost:5432") subscribe(socket, "") # following node.js example --> Invalid argument

I'd be very grateful for a small working example!

Thanks,

armstrtw commented 8 years ago

Hmm, I haven't tried it with an empty string.

Have a look at this pdf for now starting on page 13: http://www.rinfinance.com/agenda/2013/workshop/Armstrong+Lewis.pdf

paul-shannon commented 8 years ago

Hi Whit,

The pdf is very helpful. It turns out that the empty string DOES work - and appears to be interpreted as “subscribe to all messages”. I had failed to specify “ZMQ_SUB” in my init.socket call.

For what it’s worth, my learning exercise is a companion piece to the zmq chapter in

Node.js the Right Way: Practical, Server-Side JavaScript That Scales by Jim R. Wilson

Your library works great now that I am using it properly. Many thanks.

My working version (on the off chance you’d find it interesting) subscribing to the messages published in Wilson’s zmq-watcher-pub.js:

library(rzmq) library(jsonlite) context = init.context() socket = init.socket(context,"ZMQ_SUB") connect.socket(socket,"tcp://localhost:5432”) subscribe(socket, “”) # all messages

i <- 0 while (i < 5) { res <- receive.socket(socket, unserialize=FALSE) x <- fromJSON(rawToChar(res)) print(x) i <- i + 1 }

Many thanks!

On Jan 23, 2016, at 1:54 PM, Whit Armstrong notifications@github.com wrote:

Hmm, I haven't tried it with an empty string.

Have a look at this pdf for now starting on page 13: http://www.rinfinance.com/agenda/2013/workshop/Armstrong+Lewis.pdf

— Reply to this email directly or view it on GitHub.