Message retention allows you to keep messages in Pulsar around even after they have been acknowledged. By default, messages are only kept as long as they are in at least one backlog. To store messages that are not in any backlog, or have already been acknowledged by all active subscriptions, you can use retention policies. Retention policies can be set based on time and size. Before you run the commands below, make sure you have started Pulsar.
To set a message retention policy for all topics in a Pulsar namespace, we need to provide the mandatory parameters:
./bin/pulsar-admin namespaces set-retention my-tenant/my-namespace --size 500MB --time 12h
To set a message retention policy for a Pulsar topic, we need to provide the mandatory parameters:
./bin/pulsar-admin topicPolicies set-retention persistent://my-tenant/my-namespace/my-topic --size 500MB --time 12h
To get the message retention policy for all topics in a Pulsar namespace, we need to provide the mandatory parameters:
./bin/pulsar-admin namespaces get-retention my-tenant/my-namespace
To get the message retention policy for a Pulsar topic, we need to provide the mandatory parameters:
./bin/pulsar-admin topicPolicies get-retention persistent://my-tenant/my-namespace/my-topic --applied
By default, message retention is already disabled. If you changed your configuration, you can reset it by setting both the time and size limit to zero:
# For namespace-level retention
./bin/pulsar-admin namespaces set-retention my-tenant/my-namespace --size 0 --time 0
# For topic-level retention
./bin/pulsar-admin topicPolicies set-retention persistent://my-tenant/my-namespace/my-topic --size 0 --time 0