[zeromq-dev] Error handling in client code.

Martin Sustrik sustrik at fastmq.com
Thu May 7 19:00:02 CEST 2009


Hi Theo,

> I'm attempting to prototype an application using zeromq for  
> interprocess messaging.  I have a C client and a Java Client.  I've  
> got the code working, but I'm running into a wall with some of the  
> assertions in the code.
> 
> In my Java process, when I: Zmq zmq = new Zmq("localhost"); it works  
> fine when zmq_server is running.  However, when zmq_server isn't  
> running I don't seem to have an opportunity to robustly handle this  
> failure condition in my application -- it abort()s within JNI.  Much  
> to my surprise, I also get asserts in stead of errors for my client  
> code to compensate for.  What's the correct approach here?  I need to  
> able to robustly continue my application when zmq isn't around.

The primary use case for 0MQ are distributed 24/7 applications. In such 
an environment not having access to central repository of services is as 
severe a problem as say not having operating system installed. The idea 
is that the component asserts and gets repetitively restarted by a 
watchdog process until it ultimately succeeds to connect. Optionally, 
the watchdog process can send a red emergency alert (email, SMS) to the 
admin.

Other applications, however, where messaging is a nice-to-have rather 
then a unconditionally-critical feature, would benefit from soft error 
handling in this scenario.

At the moment there are 2 possible solutions:

1. Tweak the code to return error instead of assertion.
2. Replace zmq_server-based name resolving by a dummy resolver. In that 
case there'll be no need for zmq_server, but you'll have to supply IP 
addresses/hostnames instead of symbolic names (say "server001:5555" 
instead of "MyQueue" etc.)

If you are interested in trying one of the two, I'll explain further.

Systematic solution of the issue - one that can be incorporated into the 
official codebase - would require more design work. I can elaborate on 
the use cases and prospective solutions if you are interested.

Regards.
Martin



More information about the zeromq-dev mailing list