重置侦听器中的预取计数(rabbitmq、spring amqp)
我正在使用spring amqp 如何在实现ChannelAwareMessageListener的侦听器中重置预取计数重置侦听器中的预取计数(rabbitmq、spring amqp),rabbitmq,spring-amqp,Rabbitmq,Spring Amqp,我正在使用spring amqp 如何在实现ChannelAwareMessageListener的侦听器中重置预取计数 public class TestListener implements ChannelAwareMessageListener { @Override public void onMessage(Message message, Channel channel) throws IOException { channel.basicAc
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();
}
}
}
简而言之,我希望在侦听器中动态重置预回迁计数。更改频道上的预回迁只会影响在该频道上创建的新使用者。现有使用者获取创建通道时通道上的qos预取 是的,停止并重新启动容器将起作用 但是,您不应该在侦听器线程上这样做,您应该使用任务执行器来停止/启动;否则,stop()将延迟5秒(默认情况下)等待使用者线程返回容器(因此您不应该在侦听器线程上运行
stop()
)
或者您可以减少关闭超时时间