<table><tbody><tr><td class="votecell"><div class="vote">
    <span class="vote-count-post">0</span>
    <a class="vote-down-off" title="This question does not show any research effort; it is unclear or not useful (click again to undo)">down vote</a>
    <a class="star-off" href="http://stackoverflow.com/questions/11951508/spring-amqp-would-like-to-put-message-to-queue-and-send-ack-immediately#" title="This is a favorite question (click again to undo)">favorite</a>
       
 
</div>

    </td>
<td class="postcell">
<div>          
    <div class="post-text" itemprop="description">
        <p>I wrote Java application, that sends messages to RabbitMQ.
Then Flume picks messages up from RabbitMQ queue.
I'm interested that nobody pulls messages from the queue, except flume.</p>

<p>My application uses Spring AMQP Java plugin.</p>

<h2>The problem:</h2>

<p>With the code below, message comes to RabbitMQ queue and stays 'Unknowledges' for ever.
As I understand, RabbitMQ is waiting for ACK from MessageListener, but MessageListener will never ACK.
Does anybody have idea how to fix it?</p>

<p>The code:</p>

<pre class="lang-java prettyprint"><code><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">MyAmqpConfiguration</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br><br>&nbsp; &nbsp; </span><span class="lit">@Autowired</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="typ">ConnectionFactory</span><span class="pln"> connectionFactory</span><span class="pun">;</span><span class="pln"><br><br>&nbsp; &nbsp; </span><span class="lit">@Bean</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="kwd">public</span><span class="pln"> </span><span class="typ">SimpleMessageListenerContainer</span><span class="pln"> messageListenerContainer</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br><br>&nbsp; &nbsp; </span><span class="typ">SimpleMessageListenerContainer</span><span class="pln"> container </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">SimpleMessageListenerContainer</span><span class="pun">(</span><span class="pln">connectionFactory</span><span class="pun">);</span><span class="pln"><br>&nbsp; &nbsp; container</span><span class="pun">.</span><span class="pln">setQueues</span><span class="pun">(</span><span class="pln">activityLogsQueue</span><span class="pun">());</span><span class="pln"><br>&nbsp; &nbsp; container</span><span class="pun">.</span><span class="pln">setMessageListener</span><span class="pun">(</span><span class="typ">MyMessageListener</span><span class="pun">());</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; container</span><span class="pun">.</span><span class="pln">setConcurrentConsumers</span><span class="pun">(</span><span class="lit">3</span><span class="pun">);</span><span class="pln"><br><br>&nbsp; &nbsp; </span><span class="kwd">return</span><span class="pln"> container</span><span class="pun">;</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="lit">@Bean</span><span class="pun">(</span><span class="pln">name</span><span class="pun">=</span><span class="str">"myTemplate"</span><span class="pun">)</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="kwd">public</span><span class="pln"> </span><span class="typ">RabbitTemplate</span><span class="pln"> rabbitTemplate</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="typ">RabbitTemplate</span><span class="pln"> template </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">RabbitTemplate</span><span class="pun">(</span><span class="pln">connectionFactory</span><span class="pun">);</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; template</span><span class="pun">.</span><span class="pln">setMessageConverter</span><span class="pun">(</span><span class="typ">MyMessageConverter</span><span class="pun">());</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="kwd">return</span><span class="pln"> template</span><span class="pun">;</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br></span><span class="pun">}</span><span class="pln"><br><br><br></span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">MyMessageListener</span><span class="pln"> </span><span class="kwd">implements</span><span class="pln"> </span><span class="typ">MessageListener</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br><br><br>&nbsp; &nbsp;</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">MyMessageListener</span><span class="pun">(</span><span class="typ">MessageConverter</span><span class="pln"> converter</span><span class="pun">,</span><span class="pln"> </span><span class="typ">MyMessageHandler</span><span class="pun">&lt;</span><span class="typ">MyObject</span><span class="pun">&gt;</span><span class="pln"> messageHandler</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">converter </span><span class="pun">=</span><span class="pln"> converter</span><span class="pun">;</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; </span><span class="kwd">this</span><span class="pun">.</span><span class="pln">messageHandler </span><span class="pun">=</span><span class="pln"> messageHandler</span><span class="pun">;</span><span class="pln"><br>&nbsp; &nbsp; </span><span class="pun">}</span><span class="pln"><br><br>&nbsp; &nbsp;</span><span class="lit">@Override</span><span class="pln"><br>&nbsp; &nbsp;</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onMessage</span><span class="pun">(</span><span class="typ">Message</span><span class="pln"> message</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp;</span><span class="kwd">this</span><span class="pun">.</span><span class="pln">messageHandler</span><span class="pun">.</span><span class="pln">doThings</span><span class="pun">();</span><span class="pln"><br>&nbsp; &nbsp;</span><span class="pun">}</span><span class="pln"><br><br></span><span class="pun">}</span><span class="pln"><br><br></span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">MyMessageHandler</span><span class="pln"> &nbsp;</span><span class="pun">{</span><span class="pln"><br><br>&nbsp; &nbsp; &nbsp;</span><span class="lit">@Autowired</span><span class="pln"><br>&nbsp; &nbsp; &nbsp;</span><span class="lit">@Qualifier</span><span class="pun">(</span><span class="str">"myTemplate"</span><span class="pun">)</span><span class="pln"><br>&nbsp; &nbsp; &nbsp;</span><span class="typ">RabbitTemplate</span><span class="pln"> template</span><span class="pun">;</span><span class="pln"><br><br>&nbsp; &nbsp; &nbsp;</span><span class="lit">@Override</span><span class="pln"><br>&nbsp; &nbsp; &nbsp;</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> handleMessage</span><span class="pun">(</span><span class="typ">MyObject</span><span class="pln"> thing</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;template</span><span class="pun">.</span><span class="pln">convertAndSend</span><span class="pun">(</span><span class="pln">exchange</span><span class="pun">,</span><span class="pln"> routingKey</span><span class="pun">,</span><span class="pln"> thing</span><span class="pun">);</span><span class="pln"><br>&nbsp; &nbsp; &nbsp;</span><span class="pun">}</span><span class="pln"><br><br></span><span class="pun">}</span><span class="pln"><br><br><br></span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">MyMessageConverter</span><span class="pln"> </span><span class="kwd">extends</span><span class="pln"> </span><span class="typ">JsonMessageConverter</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br><br>&nbsp; &nbsp; </span><span class="lit">@Override</span><span class="pln"><br>&nbsp; &nbsp; &nbsp;</span><span class="kwd">protected</span><span class="pln"> </span><span class="typ">Message</span><span class="pln"> createMessage</span><span class="pun">(</span><span class="typ">Object</span><span class="pln"> object</span><span class="pun">,</span><span class="pln"> </span><span class="typ">MessageProperties</span><span class="pln"> messageProperties</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> <br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="com">//do things</span><span class="pln"><br>&nbsp; &nbsp; &nbsp;</span><span class="pun">}</span><span class="pln"><br><br>&nbsp; &nbsp; &nbsp;</span><span class="lit">@Override</span><span class="pln"><br>&nbsp; &nbsp; &nbsp;</span><span class="kwd">public</span><span class="pln"> </span><span class="typ">Object</span><span class="pln"> fromMessage</span><span class="pun">(</span><span class="typ">Message</span><span class="pln"> message</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">throws</span><span class="pln"> </span><span class="typ">MessageConversionException</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span class="kwd">throw</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">UnsupportedOperationException</span><span class="pun">(</span><span class="str">"fromMessage is not supported in "</span><span class="pun">+</span><span class="kwd">this</span><span class="pun">.</span><span class="pln">getClass</span><span class="pun">().</span><span class="pln">getName</span><span class="pun">());</span><span class="pln"><br>&nbsp; &nbsp; &nbsp;</span><span class="pun">}</span><span class="pln"><br><br><br></span><span class="pun">}</span><span class="pln"><br></span></code></pre>

    </div></div></td></tr></tbody></table>