如何防止Spring AMQP阻止未经处理的消息?

时间:2016-05-09 10:04:53

标签: java spring spring-amqp spring-rabbit

我有一个@RabbitListener注释方法,Spring AMQP在从方法返回后阻塞。基础SimpleRabbitListenerContainerFactory使用AcknowledgeMode.MANUAL。我还不想在侦听器方法中确认消息。

在这种情况下,有没有办法没有Spring AMQP阻止?

更详细

我使用这样的监听器:

@RabbitListener(queues = "#{ @myQueue }")
void recordRequestsFromMyMessages(
        @Payload MyMessage myMessagePayload,
        @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag,
        Channel channel) {

    // record relevant parts of the given message and combine them with
    // parts from previous/future messages
    // DON'T acknowledge the consumed message, yet; instead only keep a
    // record of the channel and the delivery tag
}

由于我在以后实际处理它们(异步)之前批量/组合多个消息,我不想立即确认消息消息。相反,我只想在以后成功处理消息后才这样做。

使用我当前的方法,Spring AMQP在从上面调用recordRequestsFromMyMessages方法返回之后阻塞,并且不再从同一队列中消耗更多消息。

This SO answer建议批量处理应该有效,但是,我不确定如何。

1 个答案:

答案 0 :(得分:2)

这不是容器“阻塞”。

您需要增加容器上的prefetchCount(默认值为1) - 代理只允许未完成数量的未应用消息。

相关问题