Incredibly basic Spring Boot Kafka demo. Uses Kafka autoconfiguration.
Assumes Kafka is running on localhost on the standard port (9092). You can get this going by following their quickstart guide, although you might want to download the latest version rather than the slightly-dated version they specify.
The app will create a topic, called demo
. An HTTP POST message to /kafka/send will send a string message to this topic:
curl -X POST localhost:8080/kafka/send
You should see something like the following:
SendResult [producerRecord=ProducerRecord(topic=demo, partition=null, headers=RecordHeaders(headers = [], isReadOnly = true), key=null, value=hello there., timestamp=null), recordMetadata=demo-0@6]
Use the kafka-console-consumer.sh
script that comes with kafka:
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic demo
You should see hello there.
each time you post to the endpoint.