Friday, July 2, 2004 06:34 AM
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.
// 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
// The message may have been consumed elsewhere so no point in hanging around...
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!
Arjuna Technologies Limited