如何停止 Spring AMQP 注释消息侦听器接收消息
how to stop Spring AMQP annotated message listener from receiving messages
当我的 Spring AMQP 消息侦听器识别到错误时,我想停止从队列接收消息。当我将 ListenerContainer 配置为 bean 时,我可以对其调用 stop()。
当我用端点注释配置我的侦听器时,我可以做类似的事情吗?例如。是否可以注入容器为我创建的 ListenerContainer?
谢谢,
小鸡
请找到 @RabbitListener#id()
JavaDocs:
/**
* 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
当我的 Spring AMQP 消息侦听器识别到错误时,我想停止从队列接收消息。当我将 ListenerContainer 配置为 bean 时,我可以对其调用 stop()。
当我用端点注释配置我的侦听器时,我可以做类似的事情吗?例如。是否可以注入容器为我创建的 ListenerContainer?
谢谢, 小鸡
请找到 @RabbitListener#id()
JavaDocs:
/**
* 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