If you need simple two-way communication, you simply configure the publication socket on each node and each of them connects to the other.
In many settings, it quickly becomes difficult to handle. Basically, it looks like you need some kind of central node that all nodes can “connect” to receive messages and, if some conditions for the subscriber are met, send messages.
Since ZeroMq is a simple "power-socket" and not a message queue (hence its name, ZeroMQ is Zero Message Queue), it is not feasible out of the box.
A simple alternative could be to allow each node to configure a UDP broadcast socket (without using ZeroMq, only regular sockets). All nodes can listen to everything that is happening and "publish" their own messages on the socket, effectively sending them to listen to any nodes. This setting works in the local network and in the settings where the error message becomes lost (for example, periodic status update). If messages need to be reliable (and possibly durable), you need a more advanced, full-blown message queue.
If you can do without long message queues, you can create a solution based on a central node, a central message handler to which all nodes can subscribe and send data. Basically, create a “server” with one REP (Response) juice (for incoming data) and one PUB (Publisher) socket (for outgoing data). Each client then publishes the data to the server’s REP connector (query) through the REQ connector (query) and installs the SUB (Subscriber) jack on the server’s PUB jack.
Check out the ZeroMq guide for various message templates .
To add it a little, you can add “topics” of events, including server-side filtering, by splitting outgoing messages (on the PUB socket server) into two parts of the message (see multicast messages ), where the first part indicates the “subject”, and the second part contains the payload (for example, temp | 46.2, speed | 134). Thus, each client can register their interest in any topic (or all) and allow the server to filter only relevant messages. See this example for more details.
Basically, ZeroMq is a “simple” abstraction over regular sockets, providing a couple of messaging templates to build your solution on top of. Nevertheless, it saves you from tedious work and provides scalability and performance from the usual. It takes some getting used to though. See the ZeroMq Guide for more information .