我已经使用 zmq 4.0.4 实现了一个简单的 ZeroMQ Pub/Sub 架构。一切正常,sub 接收来自 pub 的消息。
一切都很好,我很高兴喝了很多啤酒。
然而 .. 在让潜艇和酒吧在不可靠的网络连接上闲置 24 小时后,潜艇无法从酒吧接收任何消息。在与酒吧连接后,我可以通过暂时阻止 sub 与酒吧的连接端口来重现该问题。 sub 不仅在防火墙后面错过了所有消息(由于 pub/sub 的性质,这是预期的)而且在那之后它也没有从 pub 接收任何消息。
发布了一个类似(但很旧)的问题,当发生这种情况时,实际上子程序抛出了异常。但似乎是一个已修复的错误。 ZMQ Pub-Sub Program Failure When Losing Network Connectivity
如果没有实现心跳来确定连接是否被切断,当与 pub 的连接被切断时,sub 是否有任何方法可以自动重新连接?
最佳答案
在 zmq core github page 上发布了一个问题项目所有者回答了这个问题。
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.
实现了一个简单的心跳,效果非常好。
关于不可靠连接上的 ZeroMQ Pub/Sub,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26112992/