title: Websphere MQ message redelivery
body: <p>I have a Websphere MQ and a java app receiveng messages from it. I want to make redelivering system if any exceptions is thrown in my app. I'm using spring transaction manager, but the problem is if the message cause an exception in my app, the app is trying to resend the same message. Can i put a broken message in the end of the queue if there were some (2,3 etc) unsuccessful attempts of redelivery?</p>
  
  <p>here's my spring configuration:
      
          
      </p>
  
  <pre><code>&lt;bean id="mqMessageListener" class="ru.mos.notification.controller.MQNotificationListener"&gt;
      &lt;property name="mqwsUrl" value="${mqws.url}" /&gt;
      &lt;property name="mqwsSoapAction" value="${mqws.soapAction}" /&gt;
      &lt;property name="mqwsSoapStart" value="${mqws.soapStart}" /&gt;
      &lt;property name="mqwsSoapEnd" value="${mqws.soapEnd}" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="mqQueueConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory"&gt;
      &lt;property name="hostName" value="${mq.hostName}" /&gt;
      &lt;property name="port" value="${mq.port}" /&gt;
      &lt;property name="queueManager" value="${mq.queueManager}" /&gt;
      &lt;property name="transportType" value="1" /&gt;
      &lt;property name="channel" value="${mq.channel}" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jmsConnectionFactory"
      class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter"&gt;
      &lt;property name="targetConnectionFactory" ref="mqQueueConnectionFactory" /&gt;
      &lt;property name="username" value="${mq.username}" /&gt;
      &lt;property name="password" value="${mq.password}" /&gt;
  &lt;/bean&gt;
  
  &lt;bean
      class="org.springframework.jms.listener.DefaultMessageListenerContainer"&gt;       
      &lt;property name="destinationName" value="${mq.destinationName}" /&gt;
      &lt;property name="destinationResolver"&gt;
          &lt;bean
              class="org.springframework.jms.support.destination.DynamicDestinationResolver" /&gt;
      &lt;/property&gt;
      &lt;property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE" /&gt;
      &lt;property name="sessionTransacted" value="true" /&gt;
      &lt;property name="messageListener" ref="mqMessageListener" /&gt;
      &lt;property name="transactionManager" ref="transactionManager"/&gt;
      &lt;property name="connectionFactory" ref="jmsConnectionFactory" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>here's the code of onMessage method:</p>
  
  <pre><code>public void onMessage(Message mess) {
      try {
          if (mess instanceof TextMessage) {
              String m = ((TextMessage) mess).getText();
              logger.info("MQNotificationListener.onMessage TextMessage=" + m);
  
              Properties prop = new Properties();
              prop.setProperty("SOAPAction", mqwsSoapAction);
  
              HTTPSend.sendHTTP(mqwsUrl, mqwsSoapStart + m + mqwsSoapEnd,
                      "UTF-8", prop);
  
              String response = HTTPSend.sendHTTP(mqwsUrl, mqwsSoapStart + m
                      + mqwsSoapEnd, "UTF-8", prop);
  
              checkResponse(response);
  
          } else if (mess instanceof BytesMessage) {
              /*
               * byte[] body = new byte[(int) ((BytesMessage)
               * mess).getBodyLength()]; ((BytesMessage)
               * mess).readBytes(body);
               * 
               * String enc = Utils.getProperty(Utils.FP_MIGRATION,
               * "mqrec.encoding");
               * 
               * text = new String(body, enc);
               */
              logger.info("MQMessageListener.onMessage BytesMessage");
  
          } else {
              logger.info("MQMessageListener.onMessage other");
          }
      } catch (Exception e) {
          logger.error(
                  "MQMessageListener.onMessage Exception: " + e.getMessage(),
                  e);
          throw JmsUtils.convertJmsAccessException(new JMSException(null));
      }
  }
  </code></pre>