javazeromqjzmq

How to check if JZMQ socket is connected


Is there way to check if JZMQ (java binding of zmq) socket is connected?

ZContext zmqContext = new ZContext();
ZMQ.Socket workerSocket = zmqContext.createSocket(ZMQ.DEALER);
workerSocket.setIdentity("ID".getBytes());
workerSocket.connect("tcp://localhost:5556");

After code above I would like to check if workerSocket is connected. It would be nice to check connection status.


Solution

  • No, there's no method in the API to check if a socket is connected.

    ZeroMq abstracts the network; client and server connections are completely transparent to the peer making the connection. A client or server may send messages to non-existent peers; no errors will be generated; instead, they'll queue up in socket buffers based on HWM config.

    To check for peer availability, do it manually using a synchronous request/reply heartbeat with a timeout factor; here's an example, hope it helps!

    Check out samples for request/reply here! https://github.com/imatix/zguide/tree/master/examples/