dcsimg
Delete Messages in a queue
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, May 20, 2004 08:19 PM

I need to delete a message which has been already sent to a JMS queue.
I have come across that you need to receive the messageID and send it to the queue with MessageID + Remove for specific application server vendors implemetations.
Is this the right scenario. If yes please explain this in detail by an example.

Re: Delete Messages in a queue

Posted By:   Tom_Jenkinson  
Posted On:   Friday, July 2, 2004 06:34 AM


Sanjeewa,

If you know the message ID of the message that you want to delete then you can create a MessageConsumer specifically for the purpose of receiving (and therefore removing/deleting) that particular message.

E.G:

// Cache the message ID somehow
String messageIDToRemove = sentMessage.getJMSMessgageID();

Queue queue = (Queue)jndi.lookup("same as send queue");
// Use the messageIDToRemove as the message selector
MessageConsumer mc = session.createMessageConsumer(queue, "JMSMessageID = '" + messageIDToRemove + "'");
// If connection is not already started
connection.start();
// The message may have been consumed elsewhere so no point in hanging around...
mc.receiveNoWait();

If you don't know the message ID but would be able to identify it given the list of messages in a queue, use a QueueBrowser to see all the messages in the queue and find the message ID that way.

Hope this helps!
Tom Jenkinson
Arjuna Technologies Limited
About | Sitemap | Contact