在kafka res api响应中获取垃圾值

时间:2020-11-05 09:12:38

标签: apache-kafka confluent-cloud

我正在使用rest api从融合云上的kafka实例获取主题

我正在使用以下curl命令

var XMINode = dom.getElementsByTagName('xmi:XMI')[0]

但是我在curl "http://(myhost):9092/topics/(topicname)" --output op.txt 中得到了垃圾值

op.txt

对此有什么解决办法吗?

1 个答案:

答案 0 :(得分:1)

您还不能使用REST从Confluent Cloud消费(尚未)。使用Confluent Cloud中的数据,您可以使用ccloudkafkacat之类的工具从命令行访问数据。

Confluent Cloud CLI(ccloud

$ ccloud kafka topic consume --from-beginning rmoff_test_topic_01
Starting Kafka Consumer. ^C or ^D to exit
Hello world!
This is a message on a topic in Confluent Cloud

kafkacat

您可以在本地运行kafkacat,也可以从Docker使用它。

docker run --rm --interactive edenhill/kafkacat:1.6.0 \
            -X security.protocol=SASL_SSL -X sasl.mechanisms=PLAIN \
            -X ssl.ca.location=./etc/ssl/cert.pem -X api.version.request=true \
            -b $CCLOUD_BROKER_HOST \
            -X sasl.username="$CCLOUD_API_KEY" \
            -X sasl.password="$CCLOUD_API_SECRET" \
            -t rmoff_test_topic_01 -C -u -e
Hello world!
This is a message on a topic in Confluent Cloud

您还可以使用JSON输出消息,这可能很有用:

docker run --rm --interactive edenhill/kafkacat:1.6.0 \
            -X security.protocol=SASL_SSL -X sasl.mechanisms=PLAIN \
            -X ssl.ca.location=./etc/ssl/cert.pem -X api.version.request=true \
            -b $CCLOUD_BROKER_HOST \
            -X sasl.username="$CCLOUD_API_KEY" \
            -X sasl.password="$CCLOUD_API_SECRET" \
            -t rmoff_test_topic_01 -C -u -J -e
{
  "topic": "rmoff_test_topic_01",
  "partition": 0,
  "offset": 0,
  "tstype": "create",
  "ts": 1604571163960,
  "broker": 7,
  "key": null,
  "payload": "Hello world!"
}
{
  "topic": "rmoff_test_topic_01",
  "partition": 3,
  "offset": 0,
  "tstype": "create",
  "ts": 1604571168723,
  "broker": 1,
  "key": null,
  "payload": "This is a message on a topic in Confluent Cloud"
}