zeromq.node icon indicating copy to clipboard operation
zeromq.node copied to clipboard

Issues with inproc && pubsub

Open crodas opened this issue 13 years ago • 7 comments

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,

crodas avatar Apr 13 '11 06:04 crodas

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?

JustinTulloss avatar Jul 17 '11 21:07 JustinTulloss

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

stelcheck avatar Jul 21 '11 09:07 stelcheck

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.

blalor avatar Jul 15 '13 22:07 blalor

  • 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)

jedi4ever avatar Sep 23 '13 14:09 jedi4ever

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?

its2mc avatar Jun 10 '15 16:06 its2mc

Or can I have my xpub on tcp while the xsub on inproc?

its2mc avatar Jun 10 '15 16:06 its2mc

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);
}

brycekahle avatar Oct 31 '16 22:10 brycekahle