title: IBM MQ provider for JMS : How to automatically roll back messages?
body: <p>Working versions in the app</p>
  <ul>
  <li>IBM AllClient version           : 'com.ibm.mq:com.ibm.mq.allclient:9.1.1.0'</li>
  <li>org.springframework:spring-jms  :  4.3.9.RELEASE</li>
  <li>javax.jms:javax.jms-api         :  2.0.1</li>
  </ul>
  <p>My requirement is that in case of the failure of a message processing due to say, consumer not being available (eg. DB is unavailable), the message remains in the queue or put back on the queue (if that is even possible). This is because the order of the messages is important, messages have to be consumed in the same order that they are received. The Java app is single-threaded.</p>
  <p>I have tried the following</p>
  <pre class="lang-java prettyprint-override"><code>@Override
  public void onMessage(Message message)
  {
     try{
        if(message instanceOf Textmessage)
        {
        }
     
        :
  
        : 
        throw new Exception(&quot;Test&quot;);// Just to test the retry
      }
      catch(Exception ex)
      {
              try
              {
                  int temp = message.getIntProperty(&quot;JMSXDeliveryCount&quot;);
                  throw new RuntimeException(&quot;Redlivery attempted &quot;);
                  // At this point, I am expecting JMS to put the message back into the queue.
                  // But it is actually put into the Bakout queue.
              }
              catch(JMSException ef)
              {
                  String temp = ef.getMessage();
              }
  
      }
  }
  </code></pre>
  <p>I have set this in my spring.xml for the jmsContainer bean.</p>
  <pre class="lang-xml prettyprint-override"><code>    &lt;property name=&quot;sessionTransacted&quot; value=&quot;true&quot; /&gt;
  </code></pre>
  <p>What is wrong with the code above ?</p>
  <p>And if putting the message back in the queue is not practical, how can one browse the message, process it and, if successful, pull the message (so it is consumed and no longer on the queue) ? Is this scenario supported in IBM provider for JMS?</p>
  <p>The IBM MQ Local queue has <code>BOTHRESH(1)</code>.</p>