node.js - ZMQ pub/sub subscribe -


i having trouble figuring out how subscribe particularly "channel" zmq regard pub/sub functionality.

here publisher:

var zmq = require('zmq'); var pub = zmq.socket('pub');  pub.bindsync('tcp://127.0.0.1:5555');  setinterval(function(){     pub.send('pub msg'); },500); 

here subscriber:

 var sub = zmq.socket('sub');  sub.connect('tcp://127.0.0.1:5555');   sub.subscribe('');  //herein lies question   sub.on('message',function(msg){         console.log('received msg:',msg);  } 

this works is, problem if change argument sub.subscribe empty string (''), subscriber doesn't receive messages publisher.

how configure pub/sub zmq correctly?

sub.subscribe('topic') adds filter subscriber socket receive messages starting string topic. can add multiple filters calling more once. sub.subscribe('') removes existing filter subscriber gets messages sent publisher.

in code using sub.subscribe('pub') yield messages on subscriber side.

the pub/sub example in zeromq.node github place understand how subscriptions work.