JBoss Community

Re: JB 6 CR1: @MessageDriven deployment cleanup issue

created by Christian Tre in EJB3 - View the full discussion

sample code:

 

import java.util.concurrent.atomic.AtomicInteger;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;

 

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; @MessageDriven(mappedName = "WrapperJMS",
        activationConfig = {
            @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
            // deploy and redeploy with following line
            //,@ActivationConfigProperty(propertyName="destination", propertyValue="queue/WrapperJMS")
        })
public class MessageReceiver implements MessageListener {
   
    private static final Log LOG = LogFactory.getLog(MessageReceiver.class);
    private static AtomicInteger messagecount = new AtomicInteger();

 

    /**
     * Default constructor.
     */
    public MessageReceiver() {
        if (LOG.isDebugEnabled()) {
            LOG.debug("init MessageReceiver");
        }
    }
   
    /**
     * @see MessageListener#onMessage(Message)
     */
    @Override
    public void onMessage(Message message) {
       
        if (message == null) {
            if (LOG.isErrorEnabled()) {
                LOG.error("kann Nachricht nicht verarbeiten, da sie NULL ist!");
            }
            return;
        }
       
        try {
            final String ID = message.getJMSMessageID();
            final int PRIORITY = message.getJMSPriority();
            final String REFID = message.getJMSCorrelationID();
           
            if (LOG.isDebugEnabled()) {
                LOG.debug("Message #" + messagecount.incrementAndGet() + ": ID=" + ID + ", Priority=" + PRIORITY + ", RefID=" + REFID);
            }
            try {Thread.sleep(5000);} catch (InterruptedException e) {e.printStackTrace();}
           
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}

Reply to this message by going to Community

Start a new discussion in EJB3 at Community