Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to handle messages in MessageDrivenBeans onMessage when setRollbackOnly()

User_7N3NYDec 9 2015 — edited Jan 26 2016

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

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2016
Added on Dec 9 2015
1 comment
1,219 views