简体   繁体   English

Websphere MQ消息重新交付

[英]Websphere MQ message redelivery

I have a Websphere MQ and a java app receiveng messages from it. 我有一个Websphere MQ和一个Java应用程序,从中接收消息。 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. 我正在使用Spring事务管理器,但问题是如果消息在我的应用程序中导致异常,则该应用程序正在尝试重新发送同一条消息。 Can i put a broken message in the end of the queue if there were some (2,3 etc) unsuccessful attempts of redelivery? 如果有一些(2,3等)重新交付尝试失败,我可以在队列末尾添加一条残破的消息吗?

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: 这是onMessage方法的代码:

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

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. 两种选择都将要求消费者与生产者合作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM