title: Getting a simple Spring JMS client acknowledge to work
body: <p>Just starting to get my head around getting <code>JMS ActiveMQ Acknowledgements</code> working in Spring. So far I have a consumer working perfectly, with the exception that when I don't acknowledge the message, it's still taken from the queue (I expect it to stay there or end in a dead letter queue).</p>
  
  <p>
          </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:jms="http://www.springframework.org/schema/jms"
         xmlns:p="http://www.springframework.org/schema/p"
         xsi:schemaLocation="
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd"&gt;
  
      &lt;!-- A JMS connection factory for ActiveMQ --&gt;
      &lt;bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
      p:brokerURL="failover://(tcp://jms1:61616,tcp://jms2:61616)?randomize=false&amp;amp;jms.redeliveryPolicy.maximumRedeliveries=5" /&gt;
  
      &lt;!-- A POJO that implements the JMS message listener --&gt;
      &lt;bean id="simpleMessageListener" class="com.company.ConsumerClass" /&gt;
  
      &lt;!-- A JMS namespace aware Spring configuration for the message listener container --&gt;
      &lt;jms:listener-container
              container-type="default"
              connection-factory="connectionFactory"
              acknowledge="client"
              concurrency="10-50"
              cache="consumer"&gt;
          &lt;jms:listener destination="someQueue" ref="simpleMessageListener" method="onMessage" /&gt;
      &lt;/jms:listener-container&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>In the ConsumerClass, my simple consumer looks something like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>@Override public final void onMessage(Message message) {
      Object postedMessage = null;
      try {
          postedMessage = ((ObjectMessage) message).getObject();
  
          if (postedMessage.getClass() == SomeMessageType.class) {
              try {
                  //Some logic here
  
                  message.acknowledge();
                  return; //Success Here
              } catch (MyException e) {
                  logger.error("Could not process message, but as I didn't call acknowledge I expect it to end up in the dead message queue");
              }
          }
      } catch (JMSException e) {
          logger.error("Error occurred pulling Message from Queue", e);
      }
  
      //Also worth noting, if I throw new RuntimeException("Aww Noos"); here then it won't take it from the queue, but it won't get consumed (or end up as dead letter)...
  }
  </code></pre>