Forum Stats

  • 3,752,284 Users
  • 2,250,483 Discussions
  • 7,867,783 Comments

Discussions

How to handle messages in MessageDrivenBeans onMessage when setRollbackOnly()

User_7N3NY
User_7N3NY Member Posts: 1 Blue Ribbon
edited Jan 26, 2016 12:53PM in Java Message Service (JMS)

Hi,

I am using Glassfish version 3.1.2 for my testing cenario.

I want to configure an MDB on Glassfish with ActivationConfigProperty (redeliveryInterval = 10000 and redeliveryAttempts = 5).

When I explicitly force rollback with setRollbackOnly() inside onMessage method, the server redelivery my message constantly on loop.

Does this two ActivationConfigProperty exists on glassfish?

What I'm doing wrong?

Because I need that after 5 unsuccessful redeliveries, the topic send the message to de DMQ queue.

Here is my MDB code definition:

@MessageDriven(

        activationConfig = {

                @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),

                @ActivationConfigProperty(propertyName = "destination", propertyValue = "TestTopic"),

                @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),

                @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),

                @ActivationConfigProperty(propertyName = "transaction-type", propertyValue = "Container"),

                @ActivationConfigProperty(propertyName = "trans-attribute", propertyValue = "Required"),

                @ActivationConfigProperty(propertyName = "redeliveryInterval", propertyValue = "10000"),

                @ActivationConfigProperty(propertyName = "redeliveryAttempts", propertyValue = "5"),

               

                @ActivationConfigProperty(propertyName = "clientId", propertyValue = "TestTopicMDB2"),

                @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "TestTopicMDB2")

        }

        , mappedName = "TestTopic")

public class TestTopicMDB2 implements MessageListener {

    @Resource

    private MessageDrivenContext mdctx;

    /**

     * Default constructor.

     */

    public TestTopicMDB2() {

        // TODO Auto-generated constructor stub

    }

    public void setMessageDrivenContext(MessageDrivenContext mdctx)

    {

        this.mdctx = mdctx;

        System.out.println("TextMDB.setMessageDrivenContext, this=" +

                hashCode());

    }

    @Override

    public void onMessage(Message message) {

//        try {

//            message.setStringProperty("JMS_Sun_JMSJCA_RedeliveryHandling", "2:5000");

//        } catch (JMSException e) {

//            // TODO Auto-generated catch block

//            e.printStackTrace();

//        }

       

        TextMessage txtMessage = (TextMessage) message;

        try {

            System.out.println ("\nMesg ID:" + message.getJMSMessageID ());

            System.out.println ("Is Message redelivered:" + message.getJMSRedelivered ());

        } catch (JMSException e1) {

            // TODO Auto-generated catch block

            e1.printStackTrace();

        }

       

       

        //throw new RuntimeException("Exception thrown to simulate a bad message");

       

        mdctx.setRollbackOnly();

       

       

        //

        //        try {

        //            System.out.println("First Listener: " + txtMessage.getText());

        //        } catch (Exception e) {

        //            e.printStackTrace();

        //        }

    }

}

Thanks in advance.

António Oliveira

Tagged:

Answers

  • AbrahamStalin
    AbrahamStalin Member Posts: 6
    edited Jan 26, 2016 12:53PM

    This is because the exception is propagated to prevent it involves the process, and determines whether you catch the exception and must throw a loop, or simply end becomes the message and put in log message what happened, to be treated on the other side.

This discussion has been closed.