bgarcial
bgarcial

Reputation: 3183

Bidirectional Communication Async with ZeroMQ

I am understanding the different socket and patterns types because I am interested in having several clients talking to each other in a collaborative way, having maybe a server broker or middleware .Will be useful to receive and forward messages beetween entities related.

My study/situation case is the following: I've want to denote the workflow via step numbers interaction in my diagram. I hope not to be inconvenient with my diagram, I only refer it to better illustrate my situation

enter image description here

What it would be an appropriate pattern to achieve bidirectional, asynchronous messages between two client nodes to exchange messages?

Because all of this ... I have been reading and the ZMQ_ROUTER and ZMQ_DEALER sockets they seem to be a good option because the ongoing and incoming routing strategy.

I understand that the process of queuing each received message from all peers connected (in ZMQ_DEALER) and and each message sent is round-robined among all connected peers

What mean round-robined in this context?

With the ZMQ_ROUTER happen something similar in relation to incoming routing strategy ...

I have been testing the Shared Queue Dealer and Router sockets samples but the process is synchronous, because I've used it in a REQ-ROUTER-DEALER-REP set up but in that case the REQ -> ROUTER send does not target a particular handler on the other side, it just goes to an arbitrary one and the ROUTER makes sure the reply goes back to the original sender.

I think that my situation is similar to this Jake's question in zeromq mailing list

The broker approach ROUTER-DEALER ... is right think about it? Or the communication may be client to client directly?

I ask all this with the order to share my considerations and learn and receive some orientation of you ZMQ people in relation to the appropriate pattern to achieve bidirectional, asynchronous messages between two client nodes.

Upvotes: 1

Views: 2688

Answers (1)

const_ref
const_ref

Reputation: 4096

On your server code you want to run a zmq_router and bind it to a well known port.

Each client app should then create a zmq_dealer socket and connect to the ip and port the router bound to. Before connecting you may wish to set an id on the socket that can be used to identify each client.

To ensure clients send messages to the correct place then we need to append the id of the client they wish to speak to as the first message part to allow it to route to the correct client through the router.

You will only hit issues with round robin if you do multiple connects per dealer socket i.e. connecting directly to other client dealer sockets.

Upvotes: 1

Related Questions