简体   繁体   English

如何在 DirectMessageListenerContainer 中实现 ApplicationListener

[英]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.

相关问题 使用DirectMessageListenerContainer压缩和解压缩Spring RabbitMQ消息 - Compressing and decompressing Spring RabbitMQ messages with a DirectMessageListenerContainer DirectMessageListenerContainer在TomCat上没有配置的任务执行器? - DirectMessageListenerContainer without a configured Task Executor on TomCat? Spring AMQP中的SimpleMessageListenerContainer和DirectMessageListenerContainer有什么区别? - What's the difference between SimpleMessageListenerContainer and DirectMessageListenerContainer in Spring AMQP? 使用RabbitMQ实现Push和Pull - implement both Push and Pull with RabbitMQ 如何在Spring上接收和回复 - How to receive and reply on Spring 如何通过Spring Integration从RabbitMQ获取标头 - How to get header from RabbitMQ with spring integration 如何在SimpleMessageListenerContainer.java中记录队列名称 - How to log Queue name in SimpleMessageListenerContainer.java RabbitMQ如何在AmqpIOException UnknownHostException之后停止重新连接 - RabbitMQ how to stop reconnecting after AmqpIOException UnknownHostException 如何确保我与RabbitMQ的应用程序连接是健康的 - How to make sure that my Application connection to RabbitMQ is healthy 如何将所有收到的答复队列消息添加到列表 - how to add all received messages of reply queue to List
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM