![](/img/trans.png)
[英]How to manually ack messages from rabbitmq using spring integration
[英]Ack messages on receipt with Spring Integration
我有一個用例,我想在應用程序收到消息后立即確認消息,而不是等待流程完成。 流程如下。 當前,簡單消息偵聽器容器配置為 AUTO 確認模式。
@Bean
public IntegrationFlow processAggregateEventFlow(SimpleMessageListenerContainer messageListenerContainer,
@Qualifier("errorChannel") MessageChannel eventErrorChannel) {
return IntegrationFlows
// Create message listener container and queueEvent error channel
.from(Amqp.inboundAdapter(messageListenerContainer).errorChannel(eventErrorChannel))
.transform(new JsonToObjectTransformer(Request.class, jacksonConfiguration.jsonObjectMapper()))
.filter(Request.class, e -> true)
.handle(requestMessageHandler)
.get();
}
請參閱AcknowledgeMode.NONE
並閱讀他們的 JavaDocs:
public enum AcknowledgeMode {
/**
* No acks - {@code autoAck=true} in {@code Channel.basicConsume()}.
*/
NONE,
/**
* Manual acks - user must ack/nack via a channel aware listener.
*/
MANUAL,
/**
* Auto - the container will issue the ack/nack based on whether
* the listener returns normally, or throws an exception.
* <p><em>Do not confuse with RabbitMQ {@code autoAck} which is
* represented by {@link #NONE} here</em>.
*/
AUTO;
使用MANUAL
,有幾個標題添加到來自該 AMQP 入站通道適配器的消息中:
headers.put(AmqpHeaders.DELIVERY_TAG, deliveryTag);
headers.put(AmqpHeaders.CHANNEL, channel);
所以你可以在from(Amqp)
之后使用.handle()
from(Amqp)
來調用channel.basicAck(deliveryTag, false);
. 在文檔中查看更多信息: https : //docs.spring.io/spring-integration/docs/current/reference/html/amqp.html#amqp-inbound-ack
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.