title: Spring AMQP Integration - Consumer Manual Acknowledgement
body: <p>I am testing <code>Spring-AMQP</code> with <code>Spring-Integration</code> support, I've following configuration and test:</p>
  
  <pre><code>&lt;rabbit:connection-factory id="connectionFactory" /&gt;
  &lt;rabbit:queue name="durableQ"/&gt;
  &lt;int:channel id="consumingChannel"&gt;
      &lt;int:queue capacity="2"/&gt; &lt;!-- Message get Acked as-soon-as filled in Q --&gt;
  &lt;/int:channel&gt;
  
  &lt;int-amqp:inbound-channel-adapter 
      channel="consumingChannel"
      queue-names="durableQ" 
      connection-factory="connectionFactory"
      concurrent-consumers="1"
      acknowledge-mode="AUTO"
      /&gt;
  
  
  public static void main(String[] args) {
  System.out.println("Starting consumer with integration..");
      AbstractApplicationContext context = new ClassPathXmlApplicationContext(
      "classpath:META-INF/spring/integration/spring-integration-context-consumer.xml");
  
      PollableChannel consumingChannel = context.getBean("consumingChannel",   
                                                            PollableChannel.class);           
          int count = 0;
          while (true) {
              Message&lt;?&gt; msg = consumingChannel.receive(1000);
              System.out.println((count++) + " \t -&gt; " + msg);
  
              try { //sleep to check number of messages in queue
                  Thread.sleep(50000);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          }
      }
  </code></pre>
  
  <p>In this configuration it was evident that as soon as message arrives at <code>consumingChannel</code> they are Acked and hence removed from queue. I validated this by placing a high <code>sleep</code> after <code>receive</code> and check <code>queue-size</code>. There are no further control on it.</p>
  
  <p>Now if I set <code>acknowledge-mode=MANUAL</code>, there are no ways seems to do manual <code>ack</code> via spring integration. </p>
  
  <p>My need is to process message and after processing do a <code>manual-ack</code> so till <code>ack</code> message remains persisted at <code>durableQ</code>. </p>
  
  <p>Is there any way to handle <code>MANUAL</code> ack with <code>spring-amqp-integration</code>? I want to avoid passing <code>ChannelAwareMessageListener</code> to <code>inbound-channel-adapter</code> since I want to have control of consumer's <code>receive</code>.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>It even doesn't seems to be possible when using own <code>listener-container</code> with <code>inbound-channel-adapter</code>:</p>
  
  <pre><code>// Below creates a default direct-channel (spring-integration channel) named "adapter", to receive poll this channel which is same as above
  &lt;int-amqp:inbound-channel-adapter id="adapter" listener-container="amqpListenerContainer" /&gt; 
  
  &lt;bean id="amqpListenerContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer"&gt;
      &lt;property name="connectionFactory" ref="connectionFactory" /&gt;
      &lt;property name="queueNames" value="durableQ" /&gt;
      &lt;property name="acknowledgeMode" value="MANUAL" /&gt;
  
  // messageListener not allowed when using with adapter, so no way of having own ChannelAwareMessageListener, so no channel exposed onMessage, hence no way to ack
      &lt;property name="messageListener" ref="listener"/&gt;
  &lt;/bean&gt;
  &lt;bean id="listener" class="com.sd.springint.rmq.MsgListener"/&gt;
  </code></pre>
  
  <p>Above configuration throws error as <code>messageListener</code> property is not allowed, see inline comment on tag. So purpose of using <code>listner-container</code> got defeated (for exposing <code>channel</code> via <code>ChannelAwareMessageListener</code>).</p>
  
  <p>To me <code>spring-integration</code> cannot be used for <code>manual-acknowledgement</code> (I know, this is a hard saying!),  Can anyone help me in validating this or Is there any specific approach/configuration required for this which I am missing?</p>