How to get missed messages for 1 of N subscribers in ZeroMQ?

I want to use the AMPQ service in Python applications, but did not work with ZeroMQ. So I want to know if this can be done:

  • receiver1.py and receiver2.py subscribe to "common_messages" from one host and port
  • alarms receiver2.py
  • sender sends a message
  • receiver1.py successfully receives it
  • restart2.py rebooted
  • receiver2.py receives the message that was sent while it was missing.

Can this be done? Does ZeroMQ send messages? If you subscribe after sending messages, ZMQ detects which old messages should be received and which should not?

+4
source share
2 answers

If you are using a PUB-SUB connection (which seems like you are describing), then the quick answer is no. Publishing a socket discards messages instead of their queue.

Even if you change the socket types to PUSH and PULL, you will still have problems. Yes, the PUSH socket will be blocked for messages not received, but since you will have another client connected, the message will be sent and thus will not be blocked if one of the clients falls. With PUSH-PULL types, you cannot “subscribe” to certain messages, as you can connect to PUB-SUB.

You can implement some logic to do what you describe. Checkout the zmq guide (second marker item) to see what they recommend for a reliable connection. What is being described is essentially a method for tracking messages that a client receives (by increasing the identifier?), And a second connection that the client can “request so that the missed messages are resent.”


The above section can also be implemented with the client to the heartbeat server, which gives the last message received. The server checks this to ensure that the client is not lagging behind and re-publishes messages, if any.

+2
source

g19fanatic has already answered your question.

Adding to the answer:

ZeroMq provides super sockets. The key advantage of using this is that once you identify the communication pattern, it is very easy to use. You do not need to worry about

  • Read whole messages unlike regular sockets
  • You don’t worry about creating a socket and its details in the same way as regular sockets
  • Unlike regular sockets, a zeromq socket can connect to multiple zeromq sockets. This is very beneficial.

Be that as it may, ZeroMq does not solve the problem of saving messages. (ZeroMQ stands for Zero Message Queue). Message queues, such as AMQP implementations, provide message queuing and delivery assurance. It saves the message until it is delivered. For this, a more complex protocol (AMQP) is used. ZeroMQ provides only messaging templates.

It leaves you to implement any protocol, persistence, or other properties on top of it.

+3
source

All Articles