2

I'm using the following command:

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test.topic --property parse.key=true --property key.separator=#

This allows me to start typing key#value entries.

However, no matter what I try, I'm not able to create a null entry.

If I try sending [myKey#] and press Enter, on the feed I will see an Empty message for the Key, but not null.

I need to create a Null value.

Stole
  • 4,978
  • 3
  • 20
  • 18
  • Does this answer your question? [Producing a Kafka message with a Null Value (Tombstone) from the Console](https://stackoverflow.com/questions/52057588/producing-a-kafka-message-with-a-null-value-tombstone-from-the-console) – Ryan Jul 06 '20 at 19:44

2 Answers2

10

kafkacat allows you to produce tombstones through the -Z option.

Produce a tombstone (a "delete" for compacted topics) for key "abc" by providing an empty message value which -Z interpretes as NULL:

$ echo "abc:" | kafkacat -b mybroker -t mytopic -Z -K:

Edenhill
  • 2,897
  • 22
  • 35
5

Console producer cannot produce a null record. It parses the input as UTF8 strings

Personally, I would write a simple python or ruby script to do so

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Managed to write a small Java app to achieve this. Thanks for the suggestion. – Stole Jan 30 '20 at 15:03
  • `kafkacat` might also work. Can't remember right now – OneCricketeer Jan 30 '20 at 18:50
  • 1
    @Stole can you give me a hint how you wrote your java app? I cant seem to get mine to work with apache kafka producer.. stringProducer.send( ProducerRecord(statesTopic, key, null) ) – a.hrdie Jun 15 '22 at 15:15
  • 2
    @a.hrdie That should work fine https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/serialization/StringSerializer.java#L46 – OneCricketeer Jun 15 '22 at 15:47