This version is still in development and is not considered stable yet. For the latest stable version, please use Spring AMQP 3.2.0!spring-doc.cn

Consumer Events

The containers publish application events whenever a listener (consumer) experiences a failure of some kind. The event ListenerContainerConsumerFailedEvent has the following properties:spring-doc.cn

  • container: The listener container where the consumer experienced the problem.spring-doc.cn

  • reason: A textual reason for the failure.spring-doc.cn

  • fatal: A boolean indicating whether the failure was fatal. With non-fatal exceptions, the container tries to restart the consumer, according to the recoveryInterval or recoveryBackoff (for the SimpleMessageListenerContainer) or the monitorInterval (for the DirectMessageListenerContainer).spring-doc.cn

  • throwable: The Throwable that was caught.spring-doc.cn

These events can be consumed by implementing ApplicationListener<ListenerContainerConsumerFailedEvent>.spring-doc.cn

System-wide events (such as connection failures) are published by all consumers when concurrentConsumers is greater than 1.

If a consumer fails because one if its queues is being used exclusively, by default, as well as publishing the event, a DEBUG log is issued (since 3.1, previously WARN). To change this logging behavior, provide a custom ConditionalExceptionLogger in the AbstractMessageListenerContainer instance’s exclusiveConsumerExceptionLogger property. In addition, the SimpleMessageListenerContainer consumer restart after such an exception is now logged at DEBUG level by default (previously INFO). A new method logRestart() has been added to the ConditionalExceptionLogger to allow this to be changed.spring-doc.cn

Also, the AbstractMessageListenerContainer.DefaultExclusiveConsumerLogger is now public, allowing it to be sub classed.spring-doc.cn

Fatal errors are always logged at the ERROR level. This it not modifiable.spring-doc.cn

Several other events are published at various stages of the container lifecycle:spring-doc.cn

  • AsyncConsumerStartedEvent: When the consumer is started.spring-doc.cn

  • AsyncConsumerRestartedEvent: When the consumer is restarted after a failure - SimpleMessageListenerContainer only.spring-doc.cn

  • AsyncConsumerTerminatedEvent: When a consumer is stopped normally.spring-doc.cn

  • AsyncConsumerStoppedEvent: When the consumer is stopped - SimpleMessageListenerContainer only.spring-doc.cn

  • ConsumeOkEvent: When a consumeOk is received from the broker, contains the queue name and consumerTagspring-doc.cn

  • ListenerContainerIdleEvent: See Detecting Idle Asynchronous Consumers.spring-doc.cn

  • MissingQueueEvent: When a missing queue is detected.spring-doc.cn