2
votes

is there any case where the message could be null in the Method onMessage(message), if my MessageConsumer is implementing the MessageListener (JBoss JMS 1.1 API)?

import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;


@MessageDriven( ... )
public class MyMessageConsumer implements MessageListener {

    @Override
    public void onMessage(final Message message) {

      // is there any case, where message could be null here?
    }

}
1

1 Answers

3
votes

The interface alone does not prevent that. All examples assume that the message is not null. According to http://docs.oracle.com/javaee/6/tutorial/doc/bnbpo.html:

The onMessage method is called by the bean’s container when a message 
has arrived for the bean to service. 

In my opinion that means, that message may not be null. Even an empty message must have a message ID and a date of sending.