使用 Spring Cloud Stream RabbitMQ 手动确认 [英] Manual ack with Spring Cloud Stream RabbitMQ
问题描述
我正在尝试设置一个场景,其中侦听器将手动向 RabbitMQ 发送 ACK.我的 application.properties 中有这个
I'm trying to setup a scenario where the listeners will manually send ACK to RabbitMQ. I have this in my application.properties
spring.cloud.stream.rabbit.bindings.input.consumer.acknowledge-mode=MANUAL
我如何从侦听器发送 ack?我从 手动确认消息:Spring Cloud Stream Kafka 中看到对于 Kafka,我们创建了一个 Acknowledgment 对象并在其中调用acknowledgment().有没有RabbitMQ做同样的例子?
How do I send an ack from the listener? I see from Manual Acknowledgement of Messages : Spring Cloud Stream Kafka that for Kafka, we create an Acknowledgement object and call acknowledge() in it. Is there an example for RabbitMQ to do the same?
推荐答案
@StreamListener(target = BAR)
public void handlerMethod(@Payload Foo foo,
@Header(AmqpHeaders.CHANNEL) Channel channel,
@Header(AmqpHeaders.DELIVERY_TAG) Long deliveryTag) {
...
channel.basickAck(deliveryTag, false);
}
RabbitMQ 以自动方式添加标头,因此您可以在设置中开箱即用.
The headers are added in automatic way by RabbitMQ so you can use them out of the box with your setting.
这篇关于使用 Spring Cloud Stream RabbitMQ 手动确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!