Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZeroMQ Pub/Sub on Unreliable Connection

Tags:

zeromq

I've implemented a simple ZeroMQ Pub/Sub architecture using zmq 4.0.4. Everything works great, sub's receive messages from pub's.

All is great and I rejoiced with many beer.

HOWEVER .. 24 hours after keeping having the sub & pub sit idle over an unreliable network connection the sub wasn't able to receive any messages from the pub. I was able to reproduce the issue by blocking the sub's connection port with the pub temporarily after connection with the pub. Not only did the sub miss all messages during the time behind the firewall (expected due to the nature of pub/sub) but ALSO it failed to receive ANY messages from pub after that.

A similar (but old) question was posted that actually had the sub throw an exception when this happened. But appeared to be a bug that was fixed. ZMQ Pub-Sub Program Failure When Losing Network Connectivity

Short of implementing a heartbeat to determine if the connection is severed is there any way for a sub to auto-reconnect when the connection is severed with a pub?

like image 273
Chad Brown Avatar asked Sep 06 '25 03:09

Chad Brown


1 Answers

Posted an issue on the zmq core github page and it was answered by the projects owner.

It is possible that the PUB socket sees the error while the SUB socket does not.

The ZMTP RFC has a proposal for heartbeating that would solve this problem. The current best solution is for PUB sockets to send heartbeats (e.g. 1 per second) when traffic is low, and for SUB sockets to disconnect / reconnect if they stop getting these.

Implemented a simple heartbeat and it worked like a charm.

More Info Here

like image 74
Chad Brown Avatar answered Sep 07 '25 22:09

Chad Brown