Rishabh Jain
Rishabh Jain

Reputation: 31

ZMQ Losing subscribe connection

Am using ZMQ publish and multiple subscribe.Am Publishing every 10 sec.At first all subscribe works fine. But later the connection is broken.

How to alive connection without broken.Am using zmq npm 2.15.0 version.

Upvotes: 2

Views: 477

Answers (2)

Rishabh Jain
Rishabh Jain

Reputation: 31

Thanks for answer its fixed now with this code

const zmq = require("zmq");
const sock = zmq.socket("sub");
sock.setsockopt(zmq.ZMQ_TCP_KEEPALIVE, 1);
sock.setsockopt(zmq.ZMQ_TCP_KEEPALIVE_IDLE, 300);
sock.setsockopt(zmq.ZMQ_TCP_KEEPALIVE_CNT, 10)
sock.setsockopt(zmq.ZMQ_TCP_KEEPALIVE_INTVL, 300);
sock.connect("tcp://mdata-pub-01:3000");

Upvotes: 1

user3666197
user3666197

Reputation: 1

ZeroMQ L3-level connection maintenance is hidden "inside" or "behind" the published API and runs behind the scene.

Whenever some intermittent errors appear, the both sides' Context()-instances of the "so-far-connected" peers pay (internally) due attention and try to re-establish their Line-of-Sight ( LoS ), as needed for some transport.

Best re-read the documented API details for { .setsockopt() | .getsockopt() }-methods, where many parameters have effects on how the re-establishment(s) of the LoS actually take place "inside" the internal, service-side connection-maintenance.

May get inspired by experimenting with ZMQ_HEARTBEAT_IVL != 0 and configuring ZMQ_HEARTBEAT_TIMEOUT and ZMQ_HEARTBEAT_TTL values.

Upvotes: 0

Related Questions