首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重置监听器中的预取计数(rabbitmq,spring-amqp)

重置监听器中的预取计数(rabbitmq,spring-amqp)
EN

Stack Overflow用户
提问于 2017-06-30 15:47:56
回答 1查看 667关注 0票数 0

我使用的是spring-amqp。

如何在实现ChannelAwareMessageListener的监听器中重置预取计数。

代码语言:javascript
复制
public class TestListener implements ChannelAwareMessageListener {

    @Override
    public void onMessage(Message message, Channel channel) throws IOException {
           channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

           if (some conditions) {
              // the prefetch count has been initialized to 1 in the SimpleMessageListenerContainer
              // here I want to reset the prefetch count
              channel.basicQos(10, true); // not working, I want to request 10 messages next time

              // I can do this way, following code work as expected, but is this the right way?
              container.stop(); // SimpleMessageListenerContainer
              container.setPrefetchCount(10);
              container.start();
           }
    }
}

简而言之,我想在监听程序中动态地重置预取计数。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-30 21:53:17

更改通道上的预取只会影响在该通道上创建的新使用者。现有的使用者获取创建时在通道上的qos预取。

是的,停止并重新启动容器将会起作用。

但是,您不应该在侦听器线程上这样做,您应该使用任务执行器来停止/启动;否则stop()将延迟5秒(默认情况下),等待使用者线程返回容器(因此您不应该在侦听器线程上运行stop() )。

或者,您可以减少shutdownTimeout

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44841327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档