首页 文章

如何阻止Spring AMQP带注释的消息监听器接收消息

提问于
浏览
1

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

当我使用 endpoints 注释配置我的侦听器时,我可以执行类似的操作吗?例如 . 是否可以注入容器为我创建的ListenerContainer?

thx,tchick

1 回答

  • 2

    请找 @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 .

相关问题