Using Kafka
To run Apache Kafka locally we will use three containers (Kafka, Zookeeper, Kafdrop) organized inside a file called “docker Compose”.
After starting the containers, wait a few minutes and use any Apache Kafka-compatible tool to connect using tcp port 29092. To make it easier to test in the development environment, this docker Compose file comes with the Kafdrop tool.
Follow the steps below to get started with kafka:
- Clone the repository
git clone https://github.com/devprime/kafka
- To start
docker-compose up -d
- List the three active containers
docker ps
- To finish
docker-compose down
Starting to set up topics in Kafka
Devprime-based microservices automatically connect to Stream services like Kafka, and in the examples we use some standard topics like orderevents and paymentevents.
- Open Kafdrop in the browser in http://localhost:9000
- Go to the “Topic” and New option by adding “orderevents” and then “paymentevents”
- Check the Topics Created
Viewing messages in Kafka
When using the microservice, we will send events through Kafka and view them through the Kafdrop tool by clicking on the topic and then on “View Messages”.