Forum Stats

  • 3,760,198 Users
  • 2,251,663 Discussions
  • 7,871,021 Comments

Discussions

purging destinations vs setting message expirations

886634
886634 Member Posts: 14
edited Sep 27, 2011 5:49AM in Java Message Service (JMS)
Hi,

Is there a way to automate the process of purging a destination on the broker? For example, I might want to purge the destination before sending it another message so that there is only one message at a time in the destination. Or perhaps the better way to do this is to set the JMSExpiration for each message? Just making sure, but the value the function setJMSExpiration takes is in milliseconds correct?

Thanks!

Answers

  • 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.

    Nigel
This discussion has been closed.