简体   繁体   English

JMS setRollbackOnly - 不一致的行为

[英]JMS setRollbackOnly - inconsistent behaviour

Please have a look at the following Message Driver Bean.请查看以下消息驱动程序 Bean。 The message comes in, we call clearProperties() on it to unlock and be able set some other properties on it.消息进来后,我们对其调用clearProperties()以解锁并能够在其上设置一些其他属性。 At the end we call setRollbackOnly() on the MessageDrivenContext so that the message will be re-delivered.最后,我们在MessageDrivenContext上调用setRollbackOnly()以便重新传递消息。

We use ActiveMQ as a message broker with JBoss and the corresponding activemq-rar.rar resource adapter.我们使用 ActiveMQ 作为消息代理,带有 JBoss 和相应的activemq-rar.rar资源适配器。 There is a difference although between recent and new releases on how this resource adapter behaves regarding the code segment below.尽管最近和新版本之间关于此资源适配器关于下面代码段的行为方式存在差异。 Until version "5.11.0.redhat-630446" of the resource adapter, the property("newprop") we set in the onMessage method appeared in the message that has been re-delivered.直到版本“5.11.0.redhat-630446”的资源适配器,我们在onMessage方法中设置的property("newprop")出现在重新投递的消息中。 Since version "5.11.0.redhat-630475" the clearProperties() and setObjectProperty() method has no effect on the re-delivered message, so it falls in the onMessage method with the same properties as the original 1st message.从版本“5.11.0.redhat-630475”开始, clearProperties()setObjectProperty()方法对重新发送的消息没有影响,因此它属于onMessage方法,具有与原始第一条消息相同的属性。

I wonder which is the right behaviour?我想知道哪种行为是正确的?

@MessageDriven(activationConfig = {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/QUEUE1"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})

public class MDBean implements MessageListener {

    @Resource
    private MessageDrivenContext contextMD;

    public void onMessage(Message message) {
        try {
            message.clearProperties();
            message.setObjectProperty("newprop", "newprop");
        } catch (JMSException e) {
            e.printStackTrace();
        }
        contextMD.setRollbackOnly();
    }

}

The behavior you're seeing with the newer version is the correct one.您在新版本中看到的行为是正确的。 The relevant change was made via AMQ-7464 .相关更改是通过AMQ-7464进行的。 In short, changes made to the message during consumption should not be reflected in the message during redelivery.简而言之,在消费期间对消息所做的更改不应反映在重新传递期间的消息中。

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

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