简体   繁体   中英

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

Thanks In Advance.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM