apache-kafkakafka-topic

Removing one message from a topic in Kafka


Can I delete only ONE message from a topic if I know the topic, the offset and the partition?

And if not is there any alternative?


Solution

  • It is not possible to remove a single message from a Kafka topic, even though you know its partition and offset.

    Keep in mind, that Kafka is not a key/value store but a topic is rather an append-only(!) log that represents a stream of data.

    If you are looking for alternatives to remove a single message you may

    1. Have your consumer clients ignore that message

    2. Enable log compaction and send a tombstone message

    3. Write a simple job (KafkaStreams) to consume the data, filter out that one message and produce all messages to a new topic.