Websphere MQ消息重新交付 [英] Websphere MQ message redelivery

查看:59
本文介绍了Websphere MQ消息重新交付的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Websphere MQ和一个Java应用程序,从中接收消息.如果我的应用程序中抛出任何异常,我想制作重新交付系统.我正在使用Spring事务管理器,但问题是如果消息在我的应用程序中导致异常,则该应用程序正在尝试重新发送同一条消息.如果有一些(2,3等)尝试重新交付失败,我可以在队列末尾添加一条损坏的消息吗?

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?

这是我的弹簧配置:

<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>

这是onMessage方法的代码:

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

推荐答案

队列基于先进先出的FIFO操作.

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

所以有两个选择

  • 在应用程序内将消息路由到其他位置.
  • 将消息的优先级指定为较低,然后确保使用方按优先级顺序拉出消息.

这两种选择都需要消费者与生产者合作.

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

这篇关于Websphere MQ消息重新交付的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆