users@glassfish.java.net

Re: how can i setup glassfish to deal with "poison message"

From: <glassfish_at_javadesktop.org>
Date: Fri, 06 Feb 2009 07:02:54 PST

I am having the same problem. I set the endpointExceptionRedeliveryAttempts using annotations, but the messages keep getting redelivered

Here's the code

package jms;

import javax.annotation.Resource;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenContext;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import javax.ejb.ActivationConfigProperty;


/**
 * Message-Driven Bean implementation class for: MessagingMDB
 *
 */
@MessageDriven(
                mappedName = "jms/DTNQueue", activationConfig =
                {
                                @ActivationConfigProperty(propertyName = "endpointExceptionRedeliveryAttempts", propertyValue = "1")

                                })
public class MessagingMDB implements MessageListener {

        @Resource
          private MessageDrivenContext mdc;
    /**
     * Default constructor.
     */
    public MessagingMDB() {
        // TODO Auto-generated constructor stub
    }
        
        /**
     * @see MessageListener#onMessage(Message)
     */
    public void onMessage(Message message) {
            TextMessage msg = null;
               try {
                       if(message instanceof TextMessage)
                       {
                               msg = (TextMessage) message;
                               System.out.println("Message received : " + msg.getText());
                               if("DTNdie".equalsIgnoreCase(msg.getText())) throw new Exception("CROAK!!!");
                       }
                       else
                       {
                               System.out.println("Non text message recieved " + message.toString());
                       }
                      
               } catch (Exception e) {
                 e.printStackTrace();
                 mdc.
                 //mdc.setRollbackOnly();
               }
        
    }

}
[Message sent by forum member 'jlalwnai' (jlalwnai)]

http://forums.java.net/jive/thread.jspa?messageID=330532