How to confirm rabbitmq message manually with spring intergration

I have created a bean for an inbound channel with a confirmation property both manually and a chained method to post the outbound 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 to validate messages processed in manual confirmation mode,

Thanks in advance.

+3


source to share


1 answer


The Reference Guide contains a highlighted item on this subject:

Setting the mode MANUAL

allows user code to invoke the message at some other point during processing. To support this, in this mode, the endpoints provide a Channel and delivery target 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;
}

      

0


source







All Articles