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

Pub/Sub on a particular topic? #31

Closed
pselden opened this issue May 21, 2014 · 4 comments · Fixed by #65
Closed

Pub/Sub on a particular topic? #31

pselden opened this issue May 21, 2014 · 4 comments · Fixed by #65

Comments

@pselden
Copy link

pselden commented May 21, 2014

I'm having trouble subscribing/publishing to a particular socket. Whatever I do, my subscriber ends up receiving all messages.

Is this not implemented?

// subscriber.js
var nano = require('nanomsg');

var sub = nano.socket('sub');
var nn = nano._bindings;

var addr = 'tcp://127.0.0.1:7789'
sub.setsockopt(nn.NN_SUB, nn.NN_SUB_SUBSCRIBE, 'my.topic');
sub.connect(addr);

sub.on('message', function (buf) {
    console.log(buf.toString());
});

// publisher.js
var nano = require('nanomsg');
var pub = nano.socket('pub');
var addr = 'tcp://127.0.0.1:7789'
pub.bind(addr);

setInterval(function () {
    pub.send("my.topic This is a topic");
    pub.send("my.dog My dog's name is Spot");
}, 1000);
@tcr
Copy link
Collaborator

tcr commented May 21, 2014

@pselden Right now, this is hardcoded: https://github.com/nickdesaulniers/node-nanomsg/blob/master/src/node_nanomsg.cc#L31

We should instead be doing this from JavaScript: https://github.com/nickdesaulniers/node-nanomsg/blob/master/lib/index.js#L230

It would involve adding case NN_SUB_SUBSCRIBE: above this line: https://github.com/nickdesaulniers/node-nanomsg/blob/master/src/node_nanomsg.cc#L52

And calling setsockopt after a sub socket is created, probably: https://github.com/nickdesaulniers/node-nanomsg/blob/master/lib/index.js#L86

If you have time, we'd gladly accept a PR fixing this and running your test given case. :)

@mingfai
Copy link

mingfai commented Sep 8, 2014

+1 notice that people may use binary protocol so the filter/topic-prefix better support Buffer/ArrayBuffer

@asafyish
Copy link

asafyish commented Mar 9, 2015

+1

@nickdesaulniers
Copy link
Owner

I think this might actually be broken upstream. See #51 (comment)

reqshark added a commit that referenced this issue Mar 16, 2015
reqshark added a commit that referenced this issue Mar 16, 2015
reqshark added a commit that referenced this issue Mar 26, 2015
reqshark added a commit that referenced this issue Mar 27, 2015
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

Successfully merging a pull request may close this issue.

5 participants