简体   繁体   中英

How can i detect that publisher is disconnected with ZeroMQ and Node.js

I am using Node.js + ZeroMQ for subscribing to a certain feed using the PUB/SUB pattern. How could i detect the condition where my publisher is disconnected? (I am connected as a subscriber)

Another thing: is there a way to get automatically messages from the past when i first connected to the publisher?

Thanks in advance

You could publish a heartbeat and if your subscriber misses one or more in-a-row you can assume that you lost the connection and try to reconnect.

To get the messages from the past you need to use a different pattern, like REQuesting those missing messages. In this case you need a way to identify which messages are missing.

In ZeroMQ's default pubsub model, there's no way for the subscriber to get messages from the past. See the ZeroMQ documentation , where you find statements like

If you start the SUB socket (ie, establish a connection to a PUB socket) after the PUB socket has started sending out data, you will lose whatever it published before the connection was made. If this is a problem, set up your architecture so the SUB socket starts first, then the PUB socket starts publishing.

and

Pub-sub is like a radio broadcast; you miss everything before you join, and then how much information you get depends on the quality of your reception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM