Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if JZMQ socket is connected

Tags:

java

zeromq

jzmq

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.

like image 303
Michal Z m u d a Avatar asked Mar 03 '13 10:03

Michal Z m u d a


People also ask

What is Zmq socket?

ZeroMQ (also known as ØMQ, 0MQ, or zmq) looks like an embeddable networking library but acts like a concurrency framework. It gives you sockets that carry atomic messages across various transports like in-process, inter-process, TCP, and multicast.

Is Zmq asynchronous?

ZeroMQ is an asynchronous network messaging library known for its high performance.

Does Zmq use TCP?

A socket of type ZMQ_STREAM is used to send and receive TCP data from a non-ØMQ peer, when using the tcp:// transport.

Is ZeroMQ synchronous?

ZeroMQ is asynchronous brokerless signalling / messaging framework.


1 Answers

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/

like image 118
raffian Avatar answered Sep 28 '22 04:09

raffian