How to implement an ApplicationListener in DirectMessageListenerContainer

柔情痞子 提交于 2019-12-11 10:55:44

问题


Can anyone please guide on how to programatically register an ApplicationListener in DirectMessageListenerContainer(spring rabbitmq) to handle the ListenerContainerConsumerFailedEvent

Thanks In Advance.


回答1:


The listener is not registered to the container; it is simply added as a @Bean to the Spring application context; the container publishes the event and Spring dispatches it to each registered listener.

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; 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.

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().

In this case you would call setApplicationEventPublisher() with your custom publisher which will receive the event(s).



来源:https://stackoverflow.com/questions/58370414/how-to-implement-an-applicationlistener-in-directmessagelistenercontainer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!