Here I'm trying to delete a message from the queue. But the message returns always null. Even though there is a message exist for the provided jmsId. What I'm I doing wrong here.
Note: queue initialization is proper, using the same for fetching the information from queue
public void markAsViewed(String jmsId) throws JMSException, NamingException {
try {
InitialContext initialContext = new InitialContext();
connectionFactory = (ConnectionFactory) initialContext.lookup("java:comp/env/qTt");
mQueue = (Queue) initialContext.lookup("java:comp/env/qTtQueueRef");
jmsConnection = connectionFactory.createConnection();
jmsSession = jmsConnection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
messageConsumer = jmsSession.createConsumer(mQueue, "JMSMessageID='" + jmsId + "'");
Message inMessage = messageConsumer.receive(1000);// inMessage value is null always
}
sample JmsId value is
jmsId ="ID:789aba4c22aebc7c99974c06110a134f0000000000000001 ";
At the very least you aren't calling start()
on your Connection
which means messages will never flow to your consumer. Add this line after you invoke createConnection()
:
jmsConnection.start();
You may also have a problem with your jmsId
as it contains a space at the end which seems unlikely to be valid.