Deleting Kafka Messages

This section describes how to delete messages stored in a topic on the console.

Important

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.

Important

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.

Procedure

  1. Log in to the console.

  2. Click image1 in the upper left corner to select a region.

    Note

    Select the region where your Kafka instance is located.

  3. Click Service List and choose Application > Distributed Message Service. The Kafka instance list is displayed.

  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 ciphertext access has not been enabled for the instance, click Delete Messages in the row that contains the topic whose messages you want to delete.

    • If ciphertext access 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

    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 an offset. The data after the earliest offset and before this offset will be deleted. For example, if the earliest offset is 2 and the entered offset is 5, the messages whose offset ranges from 2 to 4 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

    Figure 2 Deletion result