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 12hTo 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 12hTo 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-namespaceTo 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 --appliedTo 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-namespaceTo 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