Monitoring sockets in ZeroMQ (Java)

Source: Internet
Author: User



Basically ZEROMQ (Java) in the basic code is a once again, but think it in the log this piece seemingly basically did not do what work, that is, we log to know what happened to Zeromq.



And because of the ZEROMQ connection in the establishment and reconnection are isolated, the user does not need to do anything to maintain the connection, of course, the benefits of this is to make the programmer's coding less, but of course there is a downside, that is, the user has lost control of the entire ZEROMQ operation phase.



For example, when we take the initiative to connect to a remote address, or if the connection is interrupted, no logs tell us that these things have happened ... At the time, these logs, or the monitoring of events, were critical to a message communication system.



Of course, there is no log to record these things, does not mean that we do not know what is happening in the current operation, ZEROMQ in the use of another way to monitor the situation of the socket, but this method is more disgusting, need to create additional sockets to monitor their interests of the socket ...



Let's not talk about the gossip here, let's see what listening events are defined in ZEROMQ:


[Java]View Plaincopy


public static final int event_connected = ZMQ. ZMQ.   zmq_event_connected; Events after a successful connection establishment

public static final int event_delayed = ZMQ. ZMQ.   zmq_event_connect_delayed; Connection delay

public static final int event_retried = ZMQ. ZMQ.    zmq_event_connect_retried; Try connecting again

public static final int event_connect_failed = ZMQ. ZMQ.   zmq_event_connect_failed; Connection failed

public static final int event_listening = ZMQ. ZMQ.    zmq_event_listening; Set up a monitoring

public static final int event_bind_failed = ZMQ. ZMQ.  zmq_event_bind_failed; Bind failed

public static final int event_accepted = ZMQ. ZMQ.   zmq_event_accepted; Receive the Accept Event

public static final int event_accept_failed = ZMQ. ZMQ.   zmq_event_accept_failed; Accept events with errors

public static final int event_closed = ZMQ. ZMQ.   zmq_event_closed; Close Event

public static final int event_close_failed = ZMQ. ZMQ.     zmq_event_close_failed; Shutdown failed

public static final int event_disconnected = ZMQ. ZMQ.   zmq_event_disconnected; Connection Disconnect

public static final int event_all = ZMQ. ZMQ.   Zmq_event_all; All the events







Above is the definition of all possible events, each of which the meaning of the following comments are explained, of course, I think the most important events are connected to disconnect, the establishment of connections, as well as reconnection and other events ...



Now let's look at how to monitor these events in Zeromq (Java), directly on the code:


[Java]View Plaincopy


public static final int event_connected = ZMQ. ZMQ.   zmq_event_connected; Events after a successful connection establishment

public static final int event_delayed = ZMQ. ZMQ.   zmq_event_connect_delayed; Connection delay

public static final int event_retried = ZMQ. ZMQ.    zmq_event_connect_retried; Try connecting again

public static final int event_connect_failed = ZMQ. ZMQ.   zmq_event_connect_failed; Connection failed

public static final int event_listening = ZMQ. ZMQ.    zmq_event_listening; Set up a monitoring

public static final int event_bind_failed = ZMQ. ZMQ.  zmq_event_bind_failed; Bind failed

public static final int event_accepted = ZMQ. ZMQ.   zmq_event_accepted; Receive the Accept Event

public static final int event_accept_failed = ZMQ. ZMQ.   zmq_event_accept_failed; Accept events with errors

public static final int event_closed = ZMQ. ZMQ.   zmq_event_closed; Close Event

public static final int event_close_failed = ZMQ. ZMQ.     zmq_event_close_failed; Shutdown failed

public static final int event_disconnected = ZMQ. ZMQ.   zmq_event_disconnected; Connection Disconnect

public static final int event_all = ZMQ. ZMQ.   Zmq_event_all; All the events





Here the code with Req/rep for example, in fact, it is relatively simple to use, when the connection is established, will be output:



1 tcp://127.0.0.1:5000



1 is the event that is established on behalf of the connection, followed by the address that establishes the connection,



If you close response at this time, the output will be as follows:



tcp://127.0.0.1:5000



512 is the event that the connection is disconnected ...






Well, as for the monitoring of the source code is how to achieve, here is not elaborate, in fact, is very simple, if you are interested to see for yourself.






To this ZEROMQ (Java) code is to be read almost, is an over, then take a good look at the book ... In addition, you want to engage in the C + + aspect of things ... Preliminary plan to see the source of Redis ....



Monitoring sockets in ZeroMQ (Java)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.