Kafka - How to enable the REST API
Find out how to enable the REST API of your Kafka service and produce and consume messages over HTTPS
Objective
Apache Kafka is an open-source, distributed event streaming platform designed for real-time, large-scale data processing with high scalability, durability, and low latency.
The Kafka REST API lets applications produce and consume messages over HTTPS, without a Kafka client library.
This guide explains how to enable the REST API of your Kafka service with the OVHcloud API, then how to produce and consume a first message with curl.
Requirements
- A Public Cloud project in your OVHcloud account
- A Kafka service accepting incoming connections from your IP address
- A topic, and a user with the
readwritepermission on it (see the ACL guide) - Access to the OVHcloud API
Instructions
Enabling the REST API
Update your service with restApi set to true (or false to disable the REST API):
Retrieving the REST API endpoint
Once the REST API is enabled, a kafkaRestApi endpoint is added to your service. You can find it in the endpoints list of the service details:
The REST API uses HTTPS with the CA certificate of your service, and the username and password of a Kafka user. Download the CA certificate as ca.pem (see Connect to a Kafka cluster with CLI).
A user you have just created can be rejected with 401 Unauthorized for about a minute, until it is available on the REST API.
Listing topics
Producing a message
Send a JSON message with the key order-1 to the orders topic:
The REST API returns the partition and offset of the message:
Consuming messages
Consuming takes three steps: create a consumer instance in a consumer group, subscribe it to the topic, then read the records.
The REST API returns the messages of the topic:
When you are done, delete the consumer instance:
Go further
Kafka - How to use Access Control Lists (ACLs)
Kafka - How to enable the Schema Registry
We want your feedback!
We would love to help answer questions and appreciate any feedback you may have.
For training or technical assistance implementing our solutions, contact your sales representative or visit our Professional Services page to request a quote and have your project analysed by our experts.
Are you on Discord? Connect to our channel at https://discord.gg/ovhcloud and interact directly with the team that builds our Analytics service!
Join our community of users.