zeromq.node
zeromq.node copied to clipboard
Issues with inproc && pubsub
I don't know if this is an issue with the driver, with zeromq or if I'm doing something wrong. Anyway, the pub/sub within an 'inproc' is not working at all, however if I change address to an tcp address it does work, also xrep andrep works perfectly fine with 'inproc'.
var ZMQ = require('zeromq');
var Broadcast = ZMQ.createSocket('pub');
var address = 'inproc://foobar';
Broadcast.bind(address, function(err) {
if (err) {
throw err;
}
var repeater = ZMQ.createSocket('sub');
repeater.connect(address);
repeater.subscribe('');
repeater.on('message', function (message) {
console.log(message.toString());
});
setInterval(function() {
Broadcast.send('foo');
}, 1000);
});
Am I doing something wrong?
Cheers,
There's a long discussion on inproc pub/sub here: http://lists.zeromq.org/pipermail/zeromq-dev/2010-November/008005.html. Does that answer any of your questions?
I have this problem too: the problem you mention seems to be connected with threading, however here we do not use multithread so I don't think this is related.
Perhaps it could still be a zeromq problem?
Edit:
It also does not seem to work with IPC
Reedit:
NM, works with ipc
I also have the inproc and pub/sub problem. Same code works fine when the transport's switched to tcp, but with inproc the subscriber never receives the message. I'm actually using pub -> xsub -> xpub -> sub; the pub -> xsub bit works fine (and I can also see the subscription getting created), but the message sent via xpub.send(…)
never reaches the sub
socket. This is with the current master and ZeroMQ 3.2.2.
- In the tests , there is also a pub/sub using inproc, and that one succeeds. (with a hack of the timeout).
- in the above example pub & sub are doing the inverse as in the test (pub = bind, sub = connect).
- in my testing both sub & pub connect to an xpub/xsub and I hit the same problem as above (tcp works but inproc not)
Yo has anyone solved this issue? I am trying to make an app, and my thinking is that an inproc socket connection will be faster than a tcp socket. Since speed and resource efficiency is a factor i'd like to try out xpub/xsub as blalor... can this be solved?
Or can I have my xpub on tcp while the xsub on inproc?
So after a bunch of investigation, this appears to be a problem with libuv
not firing a callback when a read is ready. The tests only check sub.bind
then pub.connect
, but I need pub.bind
then sub.connect
because I will have multiple subscribers.
I found a nasty workaround that seems to work consistently. If you add a sub.read()
call immediately after connect()
, it seems to force the socket into a working state.
var sub = zmq.socket('sub');
sub.on('message', handler);
sub.connect('inproc://internal');
// make sure to handle the return value in case you actually get a message
var msg = sub.read();
if (msg) {
sub._emitMessage(msg);
}