users@glassfish.java.net

JMS/Glassfish - MDB Not Consuming Queue Messages

From: <forums_at_java.net>
Date: Tue, 22 Nov 2011 09:32:35 -0600 (CST)

I am using JMS for the first time and am using Glassfish 3.1.1.  I have set
up a JMS Connection Factory:
<code>
    Pool Name: jms/QueueConnectionFactory
    JNDI Name: jms/QueueConnectionFactory
    Resource Type: javax.jms.QueueConnectionFactory
</code>
and a Destination Resource:
<code>
    JNDI Name: jms/ProcessBatchQueue
    Physical Destination: ProcessBatchQueue
    Resource Type: javax.jms.Queue
</code>   
I have deployed a war with a servlet that accepts a file, parses it and saves
the contents to a database.  If this is all successful it sends a message to
the queue:
<code>
    @Resource(lookup = "jms/ProcessBatchQueue")
    private Queue processBatchQueue;
    private void sendProcessBatchMessage(String batchID) throws
JMSException
    {
        log.info("Attempting to send process batch message for batch
ID: "
                + batchID);
        Connection jmsConnection =
connectionFactory.createConnection();
        Session jmsSession = jmsConnection.createSession(false,
                Session.AUTO_ACKNOWLEDGE);
        TextMessage message = jmsSession.createTextMessage();
        message.setText(batchID);
       
        MessageProducer msgProducer =
jmsSession.createProducer(processBatchQueue);
        msgProducer.send(message);
       
        jmsConnection.close();
    }
</code>
I have a deployed an ear with an MDB that should be listening to the queue
and actioning the message:
<code>
    @MessageDriven(mappedName = "jms/ProcessBatchQueue")
    public class BatchReceiver
    {
        private final Logger log =
LoggerFactory.getLogger(BatchReceiver.class);
        public void onMessage(Message message)
        {
            log.info("Received message from jms/ProcessBatchQueue:
" + message);
            try
            {
                if (message instanceof TextMessage)
                {
                    String batchId = ((TextMessage)
message).getText();
                    // do processing
                }
                else
                {
                    log.error("Received invalid message
type from jms/ProcessBatchQueue");
                }
            }
            catch (Exception ex)
            {
                String error = "Received error '" +
ex.toString()
                        + "' retrieving message from
jms/BatchProcessingTopic.";
                Throwable linkedEx = ex.getCause();
                if (linkedEx != null)
                {
                    log.error(error += "Linked exception:
" + linkedEx.getMessage(),
                        linkedEx);
                }
                else
                {
                    log.error(error + ", " +
ex.getMessage(), ex);
                }
            }
        }
    }
</code>
In my war logs, I get the
<code>
    log.info("Attempting to send process batch message for batch ID: " +
batchID);
</code>
statement, but in the ear logs, I get nothing that would indicate that the
MDB is receiving the message.
My understanding is that I should be able to "just" deploy the ear with the
MDB and it should start receiving the messages.  Is there a config step that
I've missed?
Is there some way to confirm that the message generated in the servlet is
making it to the queue in the first place?  There are no errors in any log
including server.log.


--
[Message sent by forum member 'sdoca']
View Post: http://forums.java.net/node/866704