Updated on 2025-09-03 GMT+08:00

Changing Kafka Message Retention Period

Aging time is a period that messages in a topic are retained for. Consumers must consume messages before this period ends. Otherwise, the messages will be deleted and can no longer be consumed.

The topic retention period is 72 hours by default, and can be changed later as required. Changing the aging time does not affect services.

You can change the aging time in either of the following ways:

The log.retention.hours parameter takes effect only when the aging time has not been set for the topic. For example, if the aging time of Topic01 is set to 60 hours and log.retention.hours is set to 72 hours, the actual aging time of Topic01 is 60 hours.

Notes and Constraints

  • The retention period of a maximum of 50 topics can be modified at a time.

Modifying the Message Retention Period of a Topic

  1. Log in to the console.
  2. Click in the upper left corner to select the region where your instance is located.
  3. Click in the upper left corner and choose Application > Distributed Message Service for Kafka to open the Kafka instance list.
  4. Click the desired instance to go to the instance details page.
  5. In the navigation pane, choose Instance > Topics.
  6. Modify the topic aging time using either of the following methods:

    • Select one or more topics and click Edit Topic in the upper left corner.
    • In the row containing the desired topic, click Edit.

  7. In the Edit Topic dialog box, enter the aging time (1–720) and click OK.

    View the aging time on the Topics page.

Modifying the Message Retention Period of Multiple Topics

  1. Log in to the console.
  2. Click in the upper left corner to select the region where your instance is located.
  3. Click in the upper left corner and choose Application > Distributed Message Service for Kafka to open the Kafka instance list.
  4. Click the desired instance to go to the instance details page.
  5. In the navigation pane, choose Instance > Topics.
  6. Select the desired topics and click Batch Edit Topic above the list.
  7. In the Batch Operations area, select Aging Time (h) and enter a value (range: 1 to 720). In the Preview Change area, check the aging time before and after the modification and click OK.

    Figure 1 Batch modifying the aging time

    Check the new aging time on the Topics page.