Skip to Main Content
Java Message Service
book

Java Message Service

by David A Chappell, Richard Monson-Haefel
December 2000
Intermediate to advanced content levelIntermediate to advanced
240 pages
6h 9m
English
O'Reilly Media, Inc.
Content preview from Java Message Service

Name

JMSExpiration — Purpose: Routing

Synopsis

A Message object can have an expiration date, the same as on a carton of milk. The expiration date is useful for messages that are only relevant for a fixed amount of time. For example, the B2B example developed in Chapter 4, and Chapter 5, might use expiration dates on messages representing “Hot Deals” that a wholesaler extends to retailers. The “Hot Deal” is only valid for a short time, so the Message that represents a deal expires after that deadline.

The expiration time for messages is set in milliseconds by the producer using the setTimeToLive( ) method on either the QueueSender or TopicPublisher as shown below:

// Publish-and-subscribe
TopicPublisher topicPublisher = topicSession.createPublisher(topic);
// Set time to live as 1 hour (1000 millis x 60 sec x 60 min)
topicPublisher.setTimeToLive(3600000);

// Point-to-point
QueueSender queueSender = queueSession.createSender(topic);
// Set time to live as 2 days (1000 millis x 60 sec x 60 min x 48 hours)
queueSender.setTimeToLive(172800000);

By default the timeToLive is zero, which indicates that the message doesn’t expire. Calling setTimeToLive( ) with a zero value as the argument ensures that message is created without an expiration date.

The JMSExpiration date itself is calculated as:

JMSExpiration = currenttime + timeToLive.

The value of the currenttime is the amount of time, measured in milliseconds, that has elapsed since the Java epoch (midnight, January 1, 1970, UTC).

The JMS ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Spring Boot 2.0

Mastering Spring Boot 2.0

Dinesh Rajput
Cloud Native Java

Cloud Native Java

Josh Long, Kenny Bastani

Publisher Resources

ISBN: 0596000685Supplemental ContentErrata Page