【问题标题】:weblogic JMS queue message not rolled back on exceptionweblogic JMS 队列消息未在异常时回滚
【发布时间】:2012-10-02 21:57:48
【问题描述】:

我们在weblogic10.3.4和JMS队列上设置,下面是消息监听代码,它使用Spring JMS,MessageProducer设置为ClientAcknowledgeMode。当发生异常时,消息仍然被移出队列并回滚,下面的代码有什么问题吗?

public class EmailListener implements MessageListener,ExceptionListener{



    private EmailSend emailSend;



    @SuppressWarnings("unchecked")
    public void onMessage(Message message){
        ObjectMessage om ;
        try {
            if(message instanceof ObjectMessage) {
                om = (ObjectMessage)message;
                emailSend.sendEmail((Map<String, String>)om.getObject());
                //throw new JMSException("Test");
                 om.acknowledge();

            }
        }
        catch(MailException me) {
            logger.error("Mail server exception in sending email",me);
            throw new RuntimeException(me);
        }catch(JMSException jmse) {
            logger.error("Error in sending email",jmse);
            throw new RuntimeException(jmse);

        }

    }

    public void setEmailSend(EmailSend emailSend){
        this.emailSend = emailSend;
    }

    public void onException(JMSException jmse){
        logger.error("Exception in sending email",jmse);

    }
    public void acknowledge(
    ) throws JMSException{

    }
}

下面是 Spring 配置

<!--Spring JMS Message Listener Container -->
    <bean id="jmsContainer"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer"
        p:autoStartup="true" p:destination-ref="queue"
        p:destinationResolver-ref="jmsDestinationResolver"
        p:connectionFactory-ref="authenticationConnectionFactory"
        p:exceptionListener-ref="emailListener"
        p:messageListener-ref="emailListener" />

【问题讨论】:

    标签: jms weblogic-10.x spring-jms


    【解决方案1】:

    你需要澄清一下。标题表明您的消息没有按照应有的方式回滚到 Queue,而帖子中的文字则表示消息已回滚。

    无论如何,一些让你的回滚行为正确的指针:

    不要依赖确认。实际上,它们并不打算作为应用程序逻辑级别的重新交付。您可以阅读有关它的一些详细信息here。因此,acks 不会让您在异常情况下重新交付,但交易会。

    您可以在 DMLC 上设置 p:sessionTransacted="true"。这可能就是您想要的 - 如果您遇到异常,消息将回滚到队列中。

    如果您开始在其中包含数据库连接,您或许应该从 WebLogic JNDI 存储库中获取 Jta 事务管理器并将其作为 p:transactionManager 属性注入 DMLC,因为会话事务仅支持一个资源事务。

    【讨论】:

      猜你喜欢
      • 2015-02-25
      • 2013-04-11
      • 2017-08-22
      • 2018-12-20
      • 2013-05-22
      • 1970-01-01
      • 2015-09-27
      • 2012-01-19
      • 2014-03-29
      相关资源
      最近更新 更多