JustinTulloss / zeromq.node

Node.js bindings to the zeromq library
MIT License
1.65k stars 284 forks source link

Fix multipart messages for xpub/xsub #593

Closed BryceCicada closed 7 years ago

BryceCicada commented 7 years ago

The following code snippet demonstrates that proxy is only forwarding the first part of a multipart message:

let zmq = require('zmq');
let subs = zmq.socket('xpub');
let pubs = zmq.socket('xsub');

subs.bindSync('tcp://127.0.0.1:3000');
pubs.bindSync('tcp://127.0.0.1:3001');
console.log('Proxy bound to to ports 3000 and 3001');
zmq.proxy(subs, pubs);

let subscriber = zmq.socket('sub');
subscriber.connect('tcp://127.0.0.1:3000');
subscriber.subscribe('');
console.log('Subscriber connected to port 3000');
subscriber.on('message', function (part1, part2) {
    console.log(part1.toString(), ':', part2 && part2.toString());
});

let publisher = zmq.socket('pub');
publisher.connect('tcp://127.0.0.1:3001');
console.log('Publisher connected to port 3001');
setInterval(() => {
    publisher.send(['foo', 'bar']);
}, 500);

wherein the publisher sends two parts, but the subscriber only receives the first part.

This change fixes the proxy so that it sends all parts to the subscriber.

Related issue https://github.com/JustinTulloss/zeromq.node/issues/412

BryceCicada commented 7 years ago

@reqshark Syntax changed as requested.

reqshark commented 7 years ago

thanks @BryceCicada!

ronkorving commented 7 years ago

LGTM, thanks! @reqshark welcome back, it's been a while ;)