Question

I am programming an ActiveMq 5.9 MessageListener. I'm able to get the messages from the broker properly, but my concern is about how to handle exception cases. For instance when the ActiveMq broker is shutdown while the listener is still up, the listener prints the following log:

2014-04-16 17:38:50,559 DEBUG [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616@55509] ActiveMQConnection - Async exception with no   exception listener: java.io.EOFException
java.io.EOFException
   at java.io.DataInputStream.readInt(DataInputStream.java:392)
   at org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:275)
   at   org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:221)
at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:213)
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:196)
at java.lang.Thread.run(Thread.java:744) 

The problem is that I am not able to catch the exception, even when I tried to catch(Throwable) in the main method of the process. So, my question is:

How I am supposed to catch these kind of problems in the listener so I can program something to recover from the error or at least terminate the process?

Thanks!

Was it helpful?

Solution

That's what the ExceptionListener is for. You can set an ExceptionListener on your Connection instance and then when an out of band failure like this occurs you will be notified.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top