我使用的是spring-amqp。
如何在实现ChannelAwareMessageListener的监听器中重置预取计数。
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();
}
}
}简而言之,我想在监听程序中动态地重置预取计数。
发布于 2017-06-30 21:53:17
更改通道上的预取只会影响在该通道上创建的新使用者。现有的使用者获取创建时在通道上的qos预取。
是的,停止并重新启动容器将会起作用。
但是,您不应该在侦听器线程上这样做,您应该使用任务执行器来停止/启动;否则stop()将延迟5秒(默认情况下),等待使用者线程返回容器(因此您不应该在侦听器线程上运行stop() )。
或者,您可以减少shutdownTimeout
https://stackoverflow.com/questions/44841327
复制相似问题