Websphere MQ message redelivery

北城余情 提交于 2021-02-11 15:09:20

问题


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?

here's my spring configuration:

<bean id="mqMessageListener" class="ru.mos.notification.controller.MQNotificationListener">
    <property name="mqwsUrl" value="${mqws.url}" />
    <property name="mqwsSoapAction" value="${mqws.soapAction}" />
    <property name="mqwsSoapStart" value="${mqws.soapStart}" />
    <property name="mqwsSoapEnd" value="${mqws.soapEnd}" />
</bean>

<bean id="mqQueueConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
    <property name="hostName" value="${mq.hostName}" />
    <property name="port" value="${mq.port}" />
    <property name="queueManager" value="${mq.queueManager}" />
    <property name="transportType" value="1" />
    <property name="channel" value="${mq.channel}" />
</bean>

<bean id="jmsConnectionFactory"
    class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
    <property name="targetConnectionFactory" ref="mqQueueConnectionFactory" />
    <property name="username" value="${mq.username}" />
    <property name="password" value="${mq.password}" />
</bean>

<bean
    class="org.springframework.jms.listener.DefaultMessageListenerContainer">       
    <property name="destinationName" value="${mq.destinationName}" />
    <property name="destinationResolver">
        <bean
            class="org.springframework.jms.support.destination.DynamicDestinationResolver" />
    </property>
    <property name="sessionAcknowledgeModeName" value="AUTO_ACKNOWLEDGE" />
    <property name="sessionTransacted" value="true" />
    <property name="messageListener" ref="mqMessageListener" />
    <property name="transactionManager" ref="transactionManager"/>
    <property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>

here's the code of onMessage method:

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));
    }
}

回答1:


Queues operate on a FIFO basis, first in first out.

So two options are

  • to within the application route the message else where.
  • to specify the priority of the message lower and then ensure the consuming pulls message off in priority order.

Both options would require the consumer to collaborate with the producer.



来源:https://stackoverflow.com/questions/27122872/websphere-mq-message-redelivery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!