[zeromq-dev] Auto-reconnect functionality

Martin Sustrik sustrik at fastmq.com
Mon Jan 26 10:41:53 CET 2009

Hi all,

In case anybody is interested in auto-reconnect functionality, it have 
been merged into the trunk.

If network connection between two application breaks 0MQ will try to 
reestablish the connection automatically. This behaviour was made _default_.

Aside of that, 0MQ is still fully backward compatible. What follows is a 
description of how you can hook-up into the auto-reconnect mechanism.

set_error_handler functionality still works as it used to. When 
connection is broken, error handler you've supplied is invoked 
immediately. You can do whatever work needed in the error handler, 
however, keep in mind that error handle is called in asynchronous manner 
and thus you need to synchronise it manually with your application 
threads. If error handler returns false, application crashes. If it 
returns true disconnection is ignored silently and auto-reconnect 
functionality is invoked.

Moreover, there's a new notification mechanism that allows you to spot 
the place in the queue where reconnection happened and where thus some 
messages may be missing. This kind of functionality is important when 
messages are dependent on preceeding messages. Imagine a video feed 
being passed via 0MQ where full frame is send once a second while 
intermediate frames are sent only in a form of diff from a previous 
frame. In this case, when reconnection happens, you want to be notified 
that there are messages missing at a particular point so that you can 
start dropping diffs until you get a full frame.

To get this functionality, you have to swich "gap notifications" on 
first (they are disabled by default to keep backward compatibility):

     api->set_notification_filter (notification_gap);

Now you can receive messages in a standard manner. However, the message 
received can actually be a gap notification. You can test it like this:

     if (message.is_gap ()) ...

We'll appreciate any feedback on the functionality!


More information about the zeromq-dev mailing list