Consumer Events
无论何时监听器(消费者)遇到某种故障,容器都会发布应用程序事件。ListenerContainerConsumerFailedEvent
事件具有以下属性:
The containers publish application events whenever a listener
(consumer) experiences a failure of some kind.
The event ListenerContainerConsumerFailedEvent
has the following properties:
-
container
: The listener container where the consumer experienced the problem. -
reason
: A textual reason for the failure. -
fatal
: A boolean indicating whether the failure was fatal. With non-fatal exceptions, the container tries to restart the consumer, according to therecoveryInterval
orrecoveryBackoff
(for theSimpleMessageListenerContainer
) or themonitorInterval
(for theDirectMessageListenerContainer
). -
throwable
: TheThrowable
that was caught.
可以通过实现 ApplicationListener<ListenerContainerConsumerFailedEvent>
来消耗这些事件。
These events can be consumed by implementing ApplicationListener<ListenerContainerConsumerFailedEvent>
.
当 |
System-wide events (such as connection failures) are published by all consumers when |
如果消费者失败是因为它的一个队列正在被独占使用,默认情况下,除了发布事件外,还会发出 DEBUG
日志(从 3.1 开始,此前为 WARN)。要更改此日志行为,请在 AbstractMessageListenerContainer
实例的 exclusiveConsumerExceptionLogger
属性中提供一个自定义的 ConditionalExceptionLogger
。此外,SimpleMessageListenerContainer
消费者在遇到此类异常后的重新启动现在默认情况下记录在 DEBUG 级别(以前为 INFO)。已将新方法 logRestart()
添加到 ConditionalExceptionLogger
以允许对其进行更改。
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.
此外,AbstractMessageListenerContainer.DefaultExclusiveConsumerLogger
现在是公开的,允许对其进行子类化。
Also, the AbstractMessageListenerContainer.DefaultExclusiveConsumerLogger
is now public, allowing it to be sub classed.
See also Logging Channel Close Events.
致命错误始终在 ERROR
级别记录。此项不可修改。
Fatal errors are always logged at the ERROR
level.
This it not modifiable.
容器生命周期不同阶段会发布其他一些事件:
Several other events are published at various stages of the container lifecycle:
-
AsyncConsumerStartedEvent
: When the consumer is started. -
AsyncConsumerRestartedEvent
: When the consumer is restarted after a failure -SimpleMessageListenerContainer
only. -
AsyncConsumerTerminatedEvent
: When a consumer is stopped normally. -
AsyncConsumerStoppedEvent
: When the consumer is stopped -SimpleMessageListenerContainer
only. -
ConsumeOkEvent
: When aconsumeOk
is received from the broker, contains the queue name andconsumerTag
-
ListenerContainerIdleEvent
: See Detecting Idle Asynchronous Consumers. -
MissingQueueEvent
: When a missing queue is detected.