KafkaIQ

10.9.3 – Producing Messages via REST

Module: Section 10 – Kafka Ecosystem & Tools
Section: 10.9 – Kafka REST Proxy
Goal: Produce messages to Kafka via REST API


Basic Producer Request

curl -X POST http://localhost:8082/topics/orders \
  -H "Content-Type: application/vnd.kafka.json.v2+json" \
  -d '{
    "records": [
      {
        "key": "order-1",
        "value": {"orderId": "12345", "amount": 99.99}
      }
    ]
  }'

Response

{
  "offsets": [
    {
      "partition": 0,
      "offset": 12345,
      "error_code": null,
      "error": null
    }
  ]
}

Batch Producing

curl -X POST http://localhost:8082/topics/orders \
  -H "Content-Type: application/vnd.kafka.json.v2+json" \
  -d '{
    "records": [
      {"key": "order-1", "value": {"orderId": "1", "amount": 10.0}},
      {"key": "order-2", "value": {"orderId": "2", "amount": 20.0}},
      {"key": "order-3", "value": {"orderId": "3", "amount": 30.0}}
    ]
  }'

Content Types

  • JSON: application/vnd.kafka.json.v2+json
  • Avro: application/vnd.kafka.avro.v2+json
  • Binary: application/vnd.kafka.binary.v2+json

Key Takeaways

  1. POST /topics/{topic}: Produce messages
  2. Batch: Multiple records in one request
  3. Content-Type: JSON, Avro, or binary
  4. Response: Offsets for each record

What's Next?

Next Module: 10.9.4 – Consuming Messages via REST