有没有办法在 kafka-console-producer.sh 中添加 headers
Is there a way to add headers in kafka-console-producer.sh
我想使用 kafka-console-producer.sh 通过 Kafka headers.
发送一些 JSON 消息
这可能吗?
docker exec -it kafka_1 /opt/kafka_2.12-2.3.0/bin/kafka-console-producer.sh --broker-list localhost:9093 --topic my-topic --producer.config /opt/kafka_2.12-2.3.0/config/my-custom.properties
不,但是您可以使用 kafkacat
的 -H
参数:
生产:
echo '{"col_foo":1}'|kafkacat -b localhost:9092 -t test -P -H foo=bar
消费:
kafkacat -b localhost:9092 -t test -C -f '-----\nTopic %t[%p]\nOffset: %o\nHeaders: %h\nKey: %k\nPayload (%S bytes): %s\n'
-----
Topic test[0]
Offset: 0
Headers: foo=bar
Key:
Payload (9 bytes): col_foo:1
% Reached end of topic test [0] at offset 1
我想使用 kafka-console-producer.sh 通过 Kafka headers.
发送一些 JSON 消息这可能吗?
docker exec -it kafka_1 /opt/kafka_2.12-2.3.0/bin/kafka-console-producer.sh --broker-list localhost:9093 --topic my-topic --producer.config /opt/kafka_2.12-2.3.0/config/my-custom.properties
不,但是您可以使用 kafkacat
的 -H
参数:
生产:
echo '{"col_foo":1}'|kafkacat -b localhost:9092 -t test -P -H foo=bar
消费:
kafkacat -b localhost:9092 -t test -C -f '-----\nTopic %t[%p]\nOffset: %o\nHeaders: %h\nKey: %k\nPayload (%S bytes): %s\n'
-----
Topic test[0]
Offset: 0
Headers: foo=bar
Key:
Payload (9 bytes): col_foo:1
% Reached end of topic test [0] at offset 1