Get Started
If you do not have a Kafka cluster and/or topic already, follow these steps to create one. In the cluster details section of the Upstash Console, scroll down theREST API
section. You will see two basic REST API snippets there; the first one is to
produce a message to a topic and the second one is to consume messages from a
topic using Kafka consumer group mechanism.
- Producer
- Consumer
UPSTASH_KAFKA_REST_USERNAME
and UPSTASH_KAFKA_REST_PASSWORD
from the
console and replace then in the code snippets shown above.
Produce
To produce a message just replace the$TOPIC
variable with a topic name which
you’ve created before and replace the $MESSAGE
with the message you want to
send to the Kafka topic.
mytopic
Kafka topic and return the metadata
related to the message as a JSON, like:
For more info and options about producer API please see REST Producer
API section.
Consume
To consume messages from the topic, replace the$TOPIC
variable with a topic
name which you’ve created before, replace the $GROUP_NAME
with a meaningful
name to be used as the
Kafka consumer group id,
and $GROUP_INSTANCE_NAME
with a name for
Kafka consumer instance id.
mytopic
using Kafka consumer group
mechanism and return the messages as a JSON array, like:
For more info and options about consumer API please see REST Consumer
APIs section.
Responses
Each API returns a JSON response and they have their own specific structures. When the API call fails for a reason (illegal argument, unauthorized access, invalid API etc), a common error JSON message returned. Its structure is as following:error
field contains the error message which explains the cause and status
field shows the HTTP status code for the error.