简体   繁体   中英

How to acknowledge rabbitmq message manually using spring intergration

I have created bean for inbound channel with acknowledge property as manual, and chain method for publishing the output message ,

<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>

Can you please help me with the way to acknowledge messages processed with the manual acknowledge mode,

Thanks in advance.

The Reference Manual has dedicated paragraph on the matter:

Setting the mode to MANUAL 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM