I have developed a simple REST API to send the incoming message to Apache Kafka.
So before going through this post be familiarize yourself with Docker and Docker Compose
Docker Maven Plugin[Docker Maven Plugin] provides us a nice way to specify multiple images in POM.xml and link it as necessary. We can also use Docker compose for doing this. But I have used this plugin here.
- Clone the project (https://github.com/dkbalachandar/kafka-message-sender)
- Then go into kafka-message-sender folder
- Then enter ‘mvn clean install’
- Then enter ‘mvn docker:start’. Then enter ‘docker ps’ and make sure that there are two containers are running. The name of those containers are kafka, kafka-rest
- Then access http://localhost:8080/api/kafka/send/test (POST) and confirm that you see message has been sent on the browser
- Then enter the below command and make sure that whatever message which you sent is available at Kafka[Kafka Command Line Consumer] or you can also consume via a Flume agent[Kafka Flume Agent Consumer]
docker exec -it kafka /opt/kafka_2.11-0.8.2.1/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning