Pulsar Academy

Pulsar Message TTL Tutorial

Learn how message time to live (TTL) works in Apache Pulsar.

Introduction

Message TTL allows you to discard messages in Pulsar after a certain point even if they have not been acknowledged yet. By default, messages are stored forever if they are unacknowledged. Depending on your use case you might want to remove messages at some point without having a client acknowledge them, this is where message TTL comes into play. Before you run the commands below, make sure you have started Pulsar.

How to set namespace message TTL using the Pulsar CLI?

To set a message TTL for all topics in a Pulsar namespace, we need to provide the mandatory parameters:

  • Tenant name & Namespace name
  • Time to live
./bin/pulsar-admin namespaces set-message-ttl my-tenant/my-namespace --messageTTL 12h

How to set topic message TTL using the Pulsar CLI?

To set a message TTL for a Pulsar topic, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic name
  • Time to live
./bin/pulsar-admin topicPolicies set-message-ttl persistent://my-tenant/my-namespace/my-topic --ttl 12h

How to get namespace message TTL using the Pulsar CLI?

To retrieve the message TTL for all topics in a Pulsar namespace, we need to provide the mandatory parameters:

  • Tenant name & Namespace name
./bin/pulsar-admin namespaces get-message-ttl my-tenant/my-namespace

How to get topic message TTL using the Pulsar CLI?

To get the message TTL for a Pulsar topic, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic name
./bin/pulsar-admin topicPolicies get-message-ttl persistent://my-tenant/my-namespace/my-topic --applied

How to remove namespace message TTL using the Pulsar CLI?

To remove the message TTL for a namespace in Pulsar, we need to provide the mandatory parameters:

  • Tenant name & Namespace name
./bin/pulsar-admin namespaces remove-message-ttl my-tenant/my-namespace

How to remove topic message TTL using the Pulsar CLI?

To remove the message TTL for a topic in Pulsar, we need to provide the mandatory parameters:

  • Persistence & Tenant name & Namespace name & Topic name
 ./bin/pulsar-admin topicPolicies remove-message-ttl persistent://my-tenant/my-namespace/my-topic

Table of Contents

Let's stay in touch

Get notified of new developments or blogposts.
Checkmark icon
You've joined the mailing list!
Oops! Something went wrong while submitting the form.