Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscribe example? #22

Open
paul-shannon opened this issue Jan 23, 2016 · 2 comments
Open

subscribe example? #22

paul-shannon opened this issue Jan 23, 2016 · 2 comments

Comments

@paul-shannon
Copy link

?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,

  • Paul
@armstrtw
Copy link
Contributor

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
Copy link
Author

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!

  • Paul

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants