apache-kafka

Kafka Producer command line headers issue


I am trying to put a message to a kafka topic. The message contains both headers and a JSON payload.

My command is like this:

echo 'headerKey1=value1;headerKey2=value2\t{\"myJson\":\"payload\"}' | ./bin/kafka-console-producer.sh \ --topic my-topic \ --bootstrapserver: myserver \ --property "parse.headers=true"

I get the following error:

No headers delimiter found on line number 1

Solution

  • I've had much better experience using | as a delimiter in between header and the payload. You can try using the command below, this works with the payload and header you had shared:

    echo 'headerKey1=value1,headerKey2=value2|myKey@{"myJson":"payload"}' | ./bin/kafka-console-producer.sh --topic my-topic --bootstrap-server myserver --property "parse.headers=true" --property "headers.key.separator==" --property "headers.delimiter=|" --property parse.key=true --property key.separator="@"
    

    It's good that you already have the parse.headers property. I've also added headers.delimiter=| to enable using | as the delimiter, and headers.key.separator== since your header uses = to separate key and value instead of :

    To produce a record with key, use the properties parse.key=true and key.separator="@"