apache-kafkaconfluent-platformkafka-rest

How to create topic with partitions in confluent kafka using curl


I have a curl command given like this i'm trying to do a curl to create a topic on confluent kafka i have an issue understanding this curl statement, on official documentation curl command is given as below

$ 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 Do i have to consider {"name":"test","num_partitions":3} as data or is it a part of curl command..?


Solution

  • You're using v2.0 of the docs, I'd recommend the latest (currently 5.5)

    To create a topic you can use the new API that was added in 5.5:

    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
        }
      }
    }'
    

    You need to get your cluster ID (rgfnzs2RS3O65A7VSpNatg in the example above), which you can do with

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

    Ref: v3 API docs


    To delete a topic use the corresponding API:

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