javajmsmessage-driven-bean

JMS setRollbackOnly - inconsistent behaviour


Please have a look at the following Message Driver Bean. The message comes in, we call clearProperties() on it to unlock and be able set some other properties on it. At the end we call setRollbackOnly() on the MessageDrivenContext so that the message will be re-delivered.

We use ActiveMQ as a message broker with JBoss and the corresponding activemq-rar.rar resource adapter. 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. 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.

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

}

Solution

  • The behavior you're seeing with the newer version is the correct one. The relevant change was made via AMQ-7464. In short, changes made to the message during consumption should not be reflected in the message during redelivery.