【问题标题】:Is there a way to add headers in kafka-console-producer.sh有没有办法在 kafka-console-producer.sh 中添加标题
【发布时间】:2021-02-25 04:39:59
【问题描述】:

我想使用 kafka-console-producer.sh 来触发一些带有 Kafka 标头的 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

【问题讨论】:

标签: apache-kafka kafka-producer-api


【解决方案1】:

不,但您可以使用 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

【讨论】:

  • 现在叫kcat,只是为了记录:)
猜你喜欢
  • 1970-01-01
  • 2016-08-27
  • 1970-01-01
  • 2020-05-09
  • 1970-01-01
  • 2019-09-12
  • 2020-11-20
  • 2020-04-05
  • 2020-03-20
相关资源
最近更新 更多