ZMQ sockets with custom load-balancing

2019-07-04 19:18发布

问题:

I looked at ZMQ PUSH/PULL sockets and even though I quite like the simplicity (especially compared to custom fragmentation/ack I am implementing right now in a system over UDP sockets), I would like to have custom load balancing instead of the naive round-robin (I believe) that ZMQ PUSH/PULL sockets are using.

I am new to ZQM and not sure how I can implement it using ZMQ sockets and if it's even possible at all. What I would ideally like is, the serving PUSH socket (or some other socket type) determines (based on the messages etc.) which machine to send the message to.

So my questions are:

  1. Is this possible?
  2. If so, what ZMQ pattern would work best for it?
  3. How can I use those sockets?

回答1:

If you want to have custom routing, you have to use ROUTER sockets, and then use IDENTITY-based routing. There is an example in the Guide illustrating how to build simple LRU routing with a ROUTER socket (i.e. behaves the same as PUSH). You would just need to write your own logic for deciding which worker IDENTITY gets each message.