This content has been marked as final. Show 1 reply
The JMS specification doesn't offer a way to explicitly purge a destination (delete all its messages), though your chosen JMS provider might off a non-standard way of doing this.
You could of course simply consume all the messages in a loop.
If you want to use message expiration, don't try using setJMSExpiration on the Message. That method is not for the purpose you might think (see the javadocs). Instead use one of the following methods on MessageProducer:
void setTimeToLive(long timeToLive)
Sets the default length of time in milliseconds from its dispatch time that a produced message should be retained by the message system.
void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive)
Sends a message to a destination for an unidentified message producer, specifying delivery mode, priority and time to live.
timeToLive is in milliseconds.