Deleting Kafka Messages
This section describes how to delete messages stored in a topic on the console.
Note
Deleting messages takes effect permanently.
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.
Procedure
- Log in to the console.
- Click in the upper left corner to select a region.
Select the region where your Kafka instance is located.
- Click and choose Application > Distributed Message Service (for Kafka) to open the console of DMS for Kafka.
- Click the desired Kafka instance to go to the instance details page.
- In the navigation pane, choose Topics.
- 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.
- 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 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.
- Click OK. The Deletion Result dialog box is displayed. Click OK to delete the messages.
Figure 2 Deletion result
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.