How to implement an active & standby queue job-pro

2019-04-21 08:29发布

Using ZeroMQ .Context and .Socket instances, I am able to push/pull messages
for example below my code for a Queue like setup:

 ZMQ.Context context = ZMQ.context(1);

 //  Socket to send messages on
 ZMQ.Socket sender = context.socket(ZMQ.PUSH);
 sender.bind("tcp://*:5557");

 // Send messages
 sender.send("0", 0);

 ZMQ.Socket receiver = context.socket(ZMQ.PULL);
 receiver.connect("tcp://localhost:5557");

 // receive messages
 String string = new String(receiver.recv(0)).trim();

My questions are:

Q1: How to implement an active / standby mode in queues?

I mean there will be 2 queues, created for one host and port, if one queue ( the active ) fails, another ( i.e. the standby ) queue, will be started immediately to listen/pull messages.

Any example or guidance to implement it, will be more helpful.

Q2: Is there any built-in Class to do this type of task?

1条回答
ゆ 、 Hurt°
2楼-- · 2019-04-21 09:05

you may implement some kind of binary start pattern. your queues need a discovery service (on another pair of sockets) to know about each other's state. if i'm not mistaken, there is no standard feature to make such queues.

查看更多
登录 后发表回答