[rabbitmq-discuss] Consumers and exceptions

Steve Powell steve at rabbitmq.com
Tue Feb 21 17:41:07 GMT 2012


Hi Jon,

I can't see Consumer Exceptions discussed in that thread, but in any case: if a
Consumer callback throws an Exception, it is caught (on the Consumer callback
thread) and passed to the connection's ExceptionHandler
handleConsumerException() method.

This setting is not exposed on the newConnection() call but is accessible on
one of the low-level, public AMQConnection() constructors. It is a final
attribute.

By default this is set to the DefaultExceptionHandler, which implements methods:

  handleUnexpectedConnectionDriverException -- and is a no-op
and
  handleReturnListenerException
  handleFlowListenerException
  handleConfirmListenerException
  handleConsumerException
each of which kills the connection.

The basic idea is that Consumer callbacks and Listeners should NOT throw
exceptions except in the direst of circumstances.

The connection.close() ought to drive the ShutdownListeners for the connection
and for any open channels on that connection, but there was a bug in this area
(which is fixed and will be in the next release).

It is entirely possible that Consumers will continue to be called (there may be
consumer callbacks queued up), and the last call should be handleCancel().

But the connection and all its channels will need to be recreated to continue.

Does this help?

Steve Powell  (a happy bunny)
----------some more definitions from the SPD----------
vermin (v.) Treating the dachshund for roundworm.
chinchilla (n.) Cooling device for the lower jaw.
socialcast (n.) Someone to whom everyone is speaking but nobody likes.

On 19 Feb 2012, at 18:01, Jon Hill wrote:

> Hi
> 
> I've just been reading this post:
> http://groups.google.com/group/rabbitmq-discuss/browse_thread/thread/77bc5f0329fa61c4/bf0c15a0502555ae?lnk=gst&q=defaultconsumer#bf0c15a0502555ae
> 
> It tells me that if an Exception is thrown from a Consumer the
> expected behaviour is to close the connection (my shutdown listener
> doesn't kick in when this occurs either).
> 
> So, should I return immediately once the consumption has finished and
> handle the application layer processing of the messages in a separate
> thread?
> 
> Best,
> 
> Jon
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss



More information about the rabbitmq-discuss mailing list