Updated on 2024-05-30 GMT+08:00

Deleting Kafka Messages

Scenario

This section describes how to delete messages on the console.

Deleted messages cannot be recovered.

Prerequisites

Before deleting a message, set the auto.offset.reset parameter in the code of consumption. auto.offset.reset specifies the consumption policy of a consumer when there is no initial offset in Kafka or the current offset does not exist (for example, the current offset has been deleted). Options:

  • latest: The offset is automatically reset to the latest offset.
  • earliest: The offset is automatically reset to the earliest offset.
  • none: The system throws an exception to the consumer.

If this parameter is set to latest, the producer may start to send messages to new partitions (if any) before the consumer resets to the initial offset. As a result, some messages will be lost.

Deleting Kafka Messages

  1. Log in to the console.
  2. Click in the upper left corner to select a region.

    Select the region where your Kafka instance is located.

  3. Click and choose Application > Distributed Message Service for Kafka to open the console of DMS for Kafka.
  4. Click the desired Kafka instance to view its details.
  5. In the navigation pane, choose Topics.
  6. Perform either of the following steps to display the Delete Message dialog box:

    • If SASL has not been enabled for the instance, click Delete Messages in the row that contains the topic whose messages you want to delete.
    • If SASL has been enabled for the instance, choose More > Delete Messages in the row that contains the topic whose messages you want to delete.

  7. Set the parameters for deleting messages, as shown in Table 1.

    Figure 1 Deleting messages
    Table 1 Parameters for deleting a message

    Parameter

    Description

    Partition

    Select the ID of the partition where the message is located.

    Offset

    Enter the offset. Data before this offset will be deleted.

    NOTE:
    • If Offset is set to -1, all messages in the partition will be deleted.
    • If the offset you entered is not between the earliest offset and the latest offset of the specified partition, no messages will be deleted.

    To delete messages from multiple partitions, click Add Partition and specify the partition and offset for the messages to be deleted. 10 partitions can be deleted at most at a time.

  8. Click OK. The Deletion Result dialog box is displayed. Click OK to delete the messages.

    Figure 2 Deletion result