Confluent REST API - Tuong-Nguyen/Angular-D3-Cometd GitHub Wiki

Architecture

Confluent Kafka REST proxy Architecture

Send and Read message

Embedded format

Embedded format is used for formatting data in Kafka. There are 3 formats:

  • Avro
  • Json
  • Binary (default).

Message must be sent and read using the same embedded format. Otherwise, the result is incorrect.

Example: using Json as Embedded format when sending and reading message from a topic

  • Send a message to a topic:

Content-Type header is used for specifying the embedded format. (application/vnd.kafka.json.v2+json ) Value of each message must be in JSON format

Content-Type: application/vnd.kafka.json.v2+json
Body:
{
  "records": [
    {
      "key": "somekey",
      "value": {"foo": "bar"}
    },
    {
      "value": [ "foo", "bar" ],
      "partition": 1
    },
    {
      "value": 53.5
    }
  ]
}
  • Create an consumer instance for reading

The embedded format must be set for consumer to de-serialize messages in the topic.

{
  "name": "my_consumer",
  "format": "json",
  "auto.offset.reset": "latest",
  "auto.commit.enable": "true"
}
  • Read messages

Accept header is used in reading message

Accept: application/vnd.kafka.json.v2+json

Reference

Confluent Kafka REST Proxy

CORS

Configure CORS - Confluent Kafka REST Proxy