2015-07-21 55 views
1

当我的Spring AMQP消息侦听器识别错误时,我想停止从队列接收消息。当我将ListenerContainer配置为bean时,我可以在其上调用stop()。如何阻止Spring AMQP注释的消息侦听器接收消息

当我使用端点注释配置侦听器时,可以做类似的事吗?例如。有可能注入容器为我创建的ListenerContainer?

THX, tchick

回答

2

请找@RabbitListener#id()的JavaDoc:

/** 
* The unique identifier of the container managing for this endpoint. 
* <p>If none is specified an auto-generated one is provided. 
* @return the {@code id} for the container managing for this endpoint. 
* @see org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry#getListenerContainer(String) 
*/ 
String id() default ""; 

所以,你必须注入到目标服务RabbitListenerEndpointRegistry并使用它通过其id以访问所需ListenerContainer

+0

工程就像一个魅力! – tchick

相关问题