If you do not have a Kafka cluster and/or topic already, follow these
steps to create one.
UPSTASH_KAFKA_REST_URL, UPSTASH_KAFKA_REST_USERNAME and
UPSTASH_KAFKA_REST_PASSWORD using the copy icons next to them.
We will use a Node.js sample code to show how to consume messages using the
REST API. Our sample will use a topic named cities and consume previously
produced city names from this topic using Kafka consumer groups and automatic
offset committing.
Replace following parameters in the code snippets below with your actual values.
mygroup consumer group id and
myconsumer consumer id from the topic starting from the latest offset and
print the consumed messages and their offsets to the console:
Kafka-Auto-Offset-Reset: earliest request header:
Kafka-Enable-Auto-Commit: false header. This allows us to commit the offsets
only when all messages processed successfully.