1
當我的Spring AMQP消息偵聽器識別錯誤時,我想停止從隊列接收消息。當我將ListenerContainer配置爲bean時,我可以在其上調用stop()。如何阻止Spring AMQP註釋的消息偵聽器接收消息
當我使用端點註釋配置偵聽器時,可以做類似的事嗎?例如。有可能注入容器爲我創建的ListenerContainer?
THX, tchick
當我的Spring AMQP消息偵聽器識別錯誤時,我想停止從隊列接收消息。當我將ListenerContainer配置爲bean時,我可以在其上調用stop()。如何阻止Spring AMQP註釋的消息偵聽器接收消息
當我使用端點註釋配置偵聽器時,可以做類似的事嗎?例如。有可能注入容器爲我創建的ListenerContainer?
THX, tchick
請找@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
。
工程就像一個魅力! – tchick