3
votes

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.

1

1 Answers

0
votes

The Reference Manual has dedicated paragraph on the matter:

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