【问题标题】:How to create topic with partitions in confluent kafka using curl如何使用 curl 在融合 kafka 中创建带有分区的主题
【发布时间】:2020-06-04 22:52:53
【问题描述】:

我有一个这样的 curl 命令我正在尝试做一个 curl 以在 confluent kafka 上创建一个主题我在理解这个 curl 语句时遇到问题,在官方文档中 curl 命令如下所示

$ curl "http://localhost:8082/topics/test"
  {"name":"test","num_partitions":3}

https://docs.confluent.io/2.0.0/kafka-rest/docs/intro.html#inspect-topic-metadata 我是否必须将 {"name":"test","num_partitions":3} 视为数据还是 curl 命令的一部分..?

【问题讨论】:

标签: apache-kafka confluent-platform kafka-rest


【解决方案1】:

您使用的是 v2.0 的文档,我建议您使用 latest (currently 5.5)

要创建主题,您可以使用 5.5 中添加的新 API:

curl -s -X POST 'http://localhost:8082/v3/clusters/rgfnzs2RS3O65A7VSpNatg/topics' \
--header 'Content-Type: application/vnd.api+json' \
--data-raw '{
  "data": {
    "attributes": {
      "topic_name": "rmoff_topic03",
      "partitions_count": 1,
      "replication_factor": 1
    }
  }
}'

您需要获取集群 ID(上例中为 rgfnzs2RS3O65A7VSpNatg),您可以使用

➜ curl -s -X GET 'localhost:8082/v3/clusters'| jq '.data[0].attributes.cluster_id'
"rgfnzs2RS3O65A7VSpNatg"

参考:v3 API docs


要删除主题,请使用corresponding API:

curl -s -X DELETE 'http://localhost:8082/v3/clusters/rgfnzs2RS3O65A7VSpNatg/topics/rmoff_topic03'

【讨论】:

  • 谢谢Robin..如何删除主题..?
  • 使用 Rest 代理 API 是否可以删除创建的新主题...?
猜你喜欢
  • 1970-01-01
  • 2018-08-05
  • 2015-11-29
  • 2018-11-29
  • 2019-02-25
  • 1970-01-01
  • 2017-07-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多