gpt4 book ai didi

java - 如何使用 spring 集成手动确认 rabbitmq 消息

转载 作者:行者123 更新时间:2023-12-04 17:07:44 25 4
gpt4 key购买 nike

我已经为入站 channel 创建了 bean,确认属性为手动,并使用链方法发布输出消息,

<int-amqp:inbound-channel-adapter channel="InputChannel" 
queue-names="Input" connection-factory="connectionFactory" concurrent-consumers="1" message-converter="Converter"
acknowledge-mode="MANUAL" prefetch-count="5"/>

<int:chain input-channel="InputChannel" output-channel="OutputChannel">

<int:transformer method = "transform" >
<bean class="com.sampleconverter" />
</int:transformer>
<int:service-activator method="transform">
<bean class="com.Transformer" />
</int:service-activator>
<int:object-to-string-transformer />
</int:chain>

能否请您帮助我确认使用手动确认模式处理的消息的方式,

提前致谢。

最佳答案

Reference Manual有关于此事的专门段落:

Setting the mode toMANUAL allows user code to ack the message at some other point during processing. To support this, with this mode, the endpoints provide the Channel and deliveryTag in the amqp_channel and amqp_deliveryTag headers respectively.

@ServiceActivator(inputChannel = "foo", outputChannel = "bar")
public Object handle(@Payload String payload, @Header(AmqpHeaders.CHANNEL) Channel channel,
@Header(AmqpHeaders.DELIVERY_TAG) Long deliveryTag) throws Exception {

// Do some processing

if (allOK) {
channel.basicAck(deliveryTag, false);

// perhaps do some more processing

}
else {
channel.basicNack(deliveryTag, false, true);
}
return someResultForDownStreamProcessing;
}

关于java - 如何使用 spring 集成手动确认 rabbitmq 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45306540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com