zmq-xpub-xsub
Central hub for ZeroMQ that allows multiple publisher and subscribers on same port.
Dependencies
Options
- xSubPort - defaults to 8700 if not provided
- xPubPort - default to 8701 if not provided
Starting zmq-xpub-xsub
zmq-xpub-xsub can be started directly from terminal or it can be required and started from hosted application.
Host application can be used for purpose of deploying to different environments
where host application will define deployment configuration.
- Starting zmq-xpub-xsub with host application
const ZmqPs= require('zmq-xpub-xsub');
ZmqPs.set('debug', true);
ZmqPs.run({ xSubPort: 8000, xPubPort: 8001 });
- Starting zmq-xpub-xsub from console (after running npm install zmq-xpub-xsub -g)
>> zqm-xpub-xsub --xSubPort 8000 --xPubPort 8001
>> zmq-xpub-xsub --debug
Example of usage
- Install and configure ZeroMq.
- Start zmq-xpub-xsub lib
- Example below illustrate usage of xpub/xsub application as a messaging hub.
const zmq = require('zmq');
const subscriber = zmq.socket('sub');
subscriber.connect('xpub-address');
subscriber.on('message', (key, message) => {
console.log('Message is recived:', key, message);
}));
const publisher = zmq.socket('pub');
publisher.connect('xsub-address');
publisher.send(['key', 'message'])