Kafkacat Produce message from a file with headers
Asked Answered
P

1

7

I need to produce batch messages to Kafka so I have a file that I feed kafkacat:

kafkacat -b localhost:9092 -t <my_topic> -T -P -l /tmp/msgs

The content of /tmp/msgs is as follows

-H "id=1"
{"key" : "value0"}
-H "id=2"
{"key" : "value1"}

When I run the kafkacat command above, it inserts four messages to kafka - one message per line in /tmp/msgs.

I need to instruct kafkacat to parse the file correctly - that is -H "id=1" is the header for the message {"key" = "value0"}.

How do I achieve this?

Thanks

Paternalism answered 28/5, 2020 at 18:9 Comment(0)
I
1

You need to pass the headers as follows.

kcat -b localhost:9092 -t topic-name -P -H key1=value1 -H key2=value2 /temp/payload.json
Interrupt answered 10/11, 2022 at 0:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.