ZeroMQ Round Robin Connect

225 views Asked by At

I have been trying out samples and examples in ZeroMQ for building an distributed MQ system.

Could we possibly create a round robin of the connections made (not the messages sent out):

{
...
...
  zmq::context_t context (1);
  zmq::socket_t subscriber (context, ZMQ_SUB);
  int rc = subscriber.connect("tcp://primary_host:5556");
  // I don't want to do this till the first one fails! 
  // int rc1 = subscriber.connect("tcp://failover_host:5557");
...
}

I visualise my code would ideally look something like this -

{
... 
... 
std::vector<std::string> urls = SomeServiceRegistry.getMeMessageServerUrls("SomeTopics_OR_FILTERS"); 

   zmq::context_t context (1);
   zmq::socket_t subscriber (context, ZMQ_SUB);

   // I would expect this guy to essentially - 
   // handle - disconnects, and pick up and connect 
   // to the next one in the vector, eventually, rolling back to the 0th index.
   zmq::connect_round_robin(urls);
...  
}

Wondering if there are pre-built patterns functions to achieve this. Couldn't find any. Happy to be corrected (... or bashed!) if I am missing out on anything. Following is what I am trying to achieve --

  1. PUB are in multiple redundant instances. All of them doing same thing. (we dont' worry about sync between PUB's right now)
  2. SUB doesn't need to make multiple connections/sockets -- I don't want to pay for something that it might not use. The PUB might never fail!
  3. SUB has more than one PUB to connect to - so I would have multiple such connects made.

I was worried about the excessive socket cluter I might end-up with at the SUB side, bad part - half of them I might never use!

Am I missing something too obvious here?

Thanks Mho

0

There are 0 answers