ashish nagar
ashish nagar

Reputation: 69

zeromq DEALER client to multiple servers (ROUTER)

I am using ZEROMQ for distributed messaging application. Need to connect client (DEALER socket) to multiple servers (ROUTER socket on server side). What are my options on CLIENT side ?

  1. Create DEALER socket on client side for each server endpoint (ROUTER socket).
  2. Create only ONE DEALER socket on client side and add multiple endpoints.

I tried option 2 - connecting to multiple endpoints but message always goes to the first connected endpoint. followed following steps:

In DEALER socket, there is no option to send message on a particular endpoint in case it is connected to multiple endpoints.

Any idea?

Upvotes: 6

Views: 5235

Answers (1)

minrk
minrk

Reputation: 38588

ZeroMQ encodes certain behaviors into socket types. These mainly deal with:

  1. handling multiple peers
  2. handling undeliverable messages
  3. handling excessive throughput (HWM)

A DEALER socket is one that can connect to multiple peers, and uses LRU (least recently used, aka round-robin) to decide which peer gets each message. If you do not want this behavior, then you do not want a DEALER socket with multiple peers.

If you want to decide which peer gets a message, there are two options for this:

  1. create a DEALER per peer, and send on the appropriate socket
  2. create a single ROUTER connected to all peers, and use IDENTITY prefixes to route messages. You may need to pass IDENTITIES via a side channel, in order to use ROUTER-ROUTER connections.

at run time, add another endpoint to the socket by using socket.connect(endpoint). Do I need to reconnect?

No, you do not need to reconnect. You can add (and remove) peers at any time during the program.

Upvotes: 5

Related Questions