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.
To set a message TTL for all topics in a Pulsar namespace, we need to provide the mandatory parameters:
./bin/pulsar-admin namespaces set-message-ttl my-tenant/my-namespace --messageTTL 12h
To set a message TTL for a Pulsar topic, we need to provide the mandatory parameters:
./bin/pulsar-admin topicPolicies set-message-ttl persistent://my-tenant/my-namespace/my-topic --ttl 12h
To retrieve the message TTL for all topics in a Pulsar namespace, we need to provide the mandatory parameters:
./bin/pulsar-admin namespaces get-message-ttl my-tenant/my-namespace
To get the message TTL for a Pulsar topic, we need to provide the mandatory parameters:
./bin/pulsar-admin topicPolicies get-message-ttl persistent://my-tenant/my-namespace/my-topic --applied
To remove the message TTL for a namespace in Pulsar, we need to provide the mandatory parameters:
./bin/pulsar-admin namespaces remove-message-ttl my-tenant/my-namespace
To remove the message TTL for a topic in Pulsar, we need to provide the mandatory parameters:
./bin/pulsar-admin topicPolicies remove-message-ttl persistent://my-tenant/my-namespace/my-topic