[英]How to implement an ApplicationListener in DirectMessageListenerContainer
Can anyone please guide on how to programatically register an ApplicationListener in DirectMessageListenerContainer(spring rabbitmq) to handle the ListenerContainerConsumerFailedEvent任何人都可以指导如何在 DirectMessageListenerContainer(spring rabbitmq) 中以编程方式注册 ApplicationListener 来处理 ListenerContainerConsumerFailedEvent
Thanks In Advance.提前致谢。
The listener is not registered to the container;监听器没有注册到容器中; it is simply added as a
@Bean
to the Spring application context;它只是作为
@Bean
添加到 Spring 应用程序上下文中; the container publishes the event and Spring dispatches it to each registered listener.容器发布事件,Spring 将其分派给每个注册的侦听器。
EDIT编辑
Don't put code in comments;不要将代码放在注释中; they don't render well - always edit the question instead and add a comment that you have done so.
它们呈现不佳 - 始终编辑问题并添加您已完成的评论。
Creating containers like that means you will miss all the Spring goodness and injected dependencies;创建这样的容器意味着您将错过所有 Spring 的优点和注入的依赖项; it's better to add a
DirectRabbitListenerContainerFactory
@Bean
to the application context and use it to create containers - that way the event publisher will be injected.最好将
DirectRabbitListenerContainerFactory
@Bean
添加到应用程序上下文并使用它来创建容器 - 这样事件发布者将被注入。
You only need one listener;你只需要一个听众; it will receive events from all containers.
它将接收来自所有容器的事件。
If you are not using Spring at all (except spring-rabbit) then you need to satisfy all of the container's ...Aware
interfaces yourself and call afterPropertiesSet()
.如果您根本不使用 Spring(spring-rabbit 除外),那么您需要自己满足所有容器的
...Aware
接口并调用afterPropertiesSet()
。
In this case you would call setApplicationEventPublisher()
with your custom publisher which will receive the event(s).在这种情况下,您将使用您的自定义发布者调用
setApplicationEventPublisher()
,该发布者将接收事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.