How to remove a message?

Is there any api to remove a message from a queue when browsing the queue? I've tried to set JMSExpiration to 1 as follows, but it doesn't seem to work.

Enumeration<Message> en=queueBrowser.getEnumeration();

while(en.hasMoreElements()){

Message message=en.nextElement();

if(message.getJMSMessageID().equals(id)){

message.setJMSExpiration(1);

return;

}

}

Anyone knows how to remove a message from a queue?

[677 byte] By [dan2005a] at [2007-11-26 15:10:48]
# 1

You cannot remove the message via a QueueBrowser and any messages returned from the browser are read-only. I'm surprised you calling setJMSExpiration() didn't throw a MessageNotWriteableException or similar. What JMS provider is it?

Using either the same session or a different session, create a MessageConsumer with a selector JMSMessageID = 'XXXX' where XXXX is the message ID of the message you want to delete. Next call receive() with a timeout (as maybe someone else has removed the message) to try to destructively read the message.

Depending on whether the session is client-ack or transacted you'll need to acknowledge() the message or commit() on the session.

Regards,

Colin.

http://hermesjms.com

colincrista at 2007-7-8 9:01:40 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Great! It works now. I'm using jboss messaging.Thanks a lot
dan2005a at 2007-7-8 9:01:40 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...