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
:使用者遇到问题的监听器容器。 -
container
: The listener container where the consumer experienced the problem. -
reason
:失败的文字原因。 -
reason
: A textual reason for the failure. -
fatal
:一个布尔值,指示失败是否致命。对于非致命异常,容器会根据recoveryInterval
或recoveryBackoff
(对于SimpleMessageListenerContainer
)或monitorInterval
(对于DirectMessageListenerContainer
)尝试重启使用者。 -
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
:捕获的Throwable
。 -
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
:在消费者启动时。 -
AsyncConsumerStartedEvent
: When the consumer is started. -
AsyncConsumerRestartedEvent
:在消费者因故障而重启后——仅SimpleMessageListenerContainer
。 -
AsyncConsumerRestartedEvent
: When the consumer is restarted after a failure -SimpleMessageListenerContainer
only. -
AsyncConsumerTerminatedEvent
:在消费者正常停止时。 -
AsyncConsumerTerminatedEvent
: When a consumer is stopped normally. -
AsyncConsumerStoppedEvent
:在消费者停止时——仅SimpleMessageListenerContainer
。 -
AsyncConsumerStoppedEvent
: When the consumer is stopped -SimpleMessageListenerContainer
only. -
ConsumeOkEvent
:当从代理收到一个consumeOk
时,它包含队列名称和consumerTag
。 -
ConsumeOkEvent
: When aconsumeOk
is received from the broker, contains the queue name andconsumerTag
-
ListenerContainerIdleEvent
:参见 Detecting Idle Asynchronous Consumers。 -
ListenerContainerIdleEvent
: See Detecting Idle Asynchronous Consumers. -
MissingQueueEvent
:当检测到丢失的队列时。 -
MissingQueueEvent
: When a missing queue is detected.