PubSub+ Messaging Handling Features: Message Expiry
Tags: fordevelopers
Published: 2021-06-15 15:25:40

---
title: PubSub+ Messaging Handling Features: Message Expiry
published: true
date: 2021-05-11 13:15:07 UTC
tags: ForDevelopers
canonical_url: https://solace.com/blog/pubsub-messaging-handling-features-message-expiry/
---

 ![](https://solace.com/wp-content/uploads/2021/04/solace-blog-featured-image_hourglass-green.jpg) 

Message handling features can help administrators and developers control how messages behave on the event broker and how they are received by consumers. This is the first in a series of blog posts in which I’ll introduce the various message handling features supported by Solace [PubSub+ Event Brokers](https://solace.com/products/event-broker/), starting with message expiry. Before reading this you should be familiar with both [Solace endpoints](https://solace.com/blog/queues-vs-topic-endpoints/) and [Solace persistent messaging](https://solace.com/blog/delivery-modes-direct-messaging-vs-persistent-messaging/).

## **What is Message Expiry?**

Message expiry is a timer that dictates the lifespan of the message. The message will persist on an endpoint until that timer expires. Without this timer, a message will persist on a Solace endpoint indefinitely, or until it is consumed by an application or deleted by an administrator.

Message expiry is also commonly referred to as ‘message time-to-live’ or ‘message-TTL’.

## **How do I use message expiry with Solace PubSub+ Event Broker?**

When considering message expiry, you need to consider a couple of required configurations. First, your endpoint must ‘Respect-TTL’ – this setting informs the endpoint to actively check messages for a TTL value. Next, you must set the TTL for the message.

There are two options to set the TTL:

1. Set ‘Maximum TTL’ on the endpoint. This will apply to all messages that are stored in the endpoint and is measured in seconds.
2. The publisher optionally sets the ‘Message-TTL’ on the message before sending it. This method allows the publisher to decide how long each message should live and if each message requires a TTL. This value is measured in milliseconds.

![](https://solace.com/wp-content/uploads/2021/04/message-expiry-01-1024x396.png)

It is possible to set both the Message-TTL and the queue Max-TTL. The lower of the two is used for expiry.

Once a message has expired, the default behavior is that the message is deleted from the endpoint. It is also possible to have the message move to a Dead-Message-Queue, for special error or behaviour handling. When a message is expired from the endpoint, the discard statistics will reflect this.

![](https://solace.com/wp-content/uploads/2021/04/message-expiry-02-1024x482.png)

## **What are some use cases for message expiry?**

Message expiry, especially when set on the queue itself, is particularly useful in development environments where messages are sent to queues and are not consumed. To prevent the queue from filling up, you can use TTL to remove messages from a development queue as needed.

A use case example of message expiry could be an order management system that must process orders in a timely manner. For orders that are not processed in the desired amount of time, they could be expired to a Dead-Message-Queue for special, expedited processing or for error handling.

Another example could be an application that receives flight statuses. If a flight status is not consumed within a couple of hours, possibly due to the consuming application being unavailable, the flight status may no longer be relevant and is no longer required. The message could then be expired and removed from the endpoint.

If you found this post useful, visit the [message properties section of our docs](https://docs.solace.com/Solace-JMS-API/Setting-Message-Properties.htm), and our [PubSub+ for Developers](https://www.solace.dev/) page for more information. If you have any questions about queues and topic endpoints, post them to the [Solace Developer Community](https://solace.community/).

The post [PubSub+ Messaging Handling Features: Message Expiry](https://solace.com/blog/pubsub-messaging-handling-features-message-expiry/) appeared first on [Solace](https://solace.com).