Reputation: 1405
I started with zeromq just a few days ago. My aim is to design a publish subscribe system with multiple brokers (a network of brokers). I have read the relevant sections of the zeromq guide, and have written code for simple pub sub systems. If someone could please help me with the following questions:
From what I can conceive, the brokers(xpub-xsub sockets) will also have push/pull sockets to communicate the pub-sub messages. Is that correct? Any help in terms of how the brokers should communicate would be appreciated. Should there be any intermediaries between brokers?
Any design guidelines would be very helpful. Thank you.
Upvotes: 3
Views: 4085
Reputation: 32066
The guide says that we should use xpub and xsub sockets when dynamic discovery is required. Can someone please explain the difference between the sockets: xpub and pub, and xsub and sub.
XPUB
just means many publishers , compared to PUB
, which means single publisher.
XSUB
means many subscribers, compared to SUB
, meaning single subscriber.
If you want to connect many subscribers to many publishers while still having the benefit dynamic discovery, you need a proxy in the middle; something like illustration below. PUB sockets sending messages to a proxy; the XSUB forwards message to XPUB, which then distributes those messages to all SUBs listening.
The code for creating such a proxy is simple (below), and the PUB and SUB ends are trivial, check the example code.
Socket xsub = ctx.createSocket(ZMQ.XSUB);
input.bind( "tcp://*:5500");
Socket xpub = ctx.createSocket(ZMQ.XPUB);
xpub.bind( "tcp://*:5600");
ZMQ.proxy( xsub, xpub, null);
From what I can conceive, the brokers will also have push/pull sockets to communicate the pub-sub messages. Is that correct? Any help in terms of how the brokers should communicate would be appreciated. Should there be any intermediaries between brokers?
Check the guide for Inter-Broker Routing example
Upvotes: 3