2

I am using Kafka rest proxy, but not whole Confluent Platform just Kafka rest with my Kafka brokers. But I am not able to create topics from command line by the following command.

bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test.

I want to know is there any other way out.

Michael Heil
  • 16,250
  • 3
  • 42
  • 77
  • What is the problem? – Giorgos Myrianthous Mar 25 '20 at 10:03
  • 1
    I have installed only schema-registry and Kafka rest not whole confluent platform, now when I try to execute commands to create topic It doesn't give any response. I want to know how san I craete topics – Wajahat Lateef Mar 28 '20 at 10:24
  • You can easily do the same through this command: curl --location --request POST 'http://localhost:8082/topics/mytopic' \ --header 'Accept: application/vnd.kafka.v2+json' \ --header 'Content-Type: application/vnd.kafka.avro.v2+json' \ --header 'Content-Type: text/plain' \ --data-raw '{ "key_schema": "{\"type\":\"string\"}", "value_schema": "{\"type\":\"string\"}", "records": [ { "key": "somekey", "value": "somevalue" } ] }' – codebased Apr 08 '20 at 13:03

1 Answers1

1

The command you have tried out is not meant to interact with the REST Proxy Server of Kafka, but rather interacting with the Kafka cluster directly.

According to the Confluent REST Proxy API Reference the creation of a topic is only possible with the REST Proxy API v3 that is currently available as a preview feature.

"The API v3 can be used for evaluation and non-production testing purposes or to provide feedback to Confluent."

An example of a topic creation request is presented below and documented here:

POST /v3/clusters/cluster-1/topics HTTP/1.1
Host: kafkaproxy.example.com
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "attributes": {
      "topic_name": "topic-1",
      "partitions_count": 2,
      "replication_factor": 3,
      "configs": [
        {
          "name": "cleanup.policy",
          "value": "compact"
        }
      ]
    }
  }
}

Using curl:

curl -X POST -H "Content-Type: application/vnd.api+json" -H "Accept: application/vnd.api+json" \
          --data '{"data":{"attributes": {"topic_name": "topic-1", "partitions_count": 2, "replication_factor": 1, "configs": [{"name": "cleanup.policy","value": "compact"}]}}}' \
          "http://localhost:8082/v3/clusters/<cluster-id>/topics"

where the cluster-id can be identified using

curl -X GET -H "Accept: application/vnd.api+json" localhost:8082/v3/clusters
Michael Heil
  • 16,250
  • 3
  • 42
  • 77