1. Project Idea
1. We have taken an example of a Messaging Service for this Kafka Project.
2. In this project, we have used Kafka producer & consumer messaging service for transfer messages.
3. We will use two web systems, the first system will generate messages and the second system will receive those messages.
4. Source Messaging System works with Kafka producer and pushes all messages on different topics.
5. Destination Messaging System works with Kafka consumer and pulls all messages from topics.
2. Kafka Messaging Project Workflow
a. Open Producer WebClient System & Consumer WebClients System. | |
b. Select subject & type message for the selected subject in Producer WebClient System. | |
c. Submit message from Producer WebClient System to Kafka topics for Consumer WebClient System. | |
d. After successfully message submission, Consumer WebClient System will receive a message from the topic and show it on the page for a valid selected subject. |
3. Building Of Project
To run this project you can install VM (Virtual Machine) on your local system and configured Zookeeper & Kafka on that. After this configuration, your VM system will work as a Kafka service provider system. Now run two web project systems that are communicating with each other with the help of Kafka service.
Let us see this project in detail.
a. Producer Web System | ||
---|---|---|
It is an example of the Spring Boot JAVA Framework. When we will build this project then it will create a "producer.jar" executable file. | ||
It has java code files (ProducerController.java, SpringKafkaProducer.java), build file (pom.xml), and static web files (index.html, cloud.png). | ||
SpringKafkaProducer.java is the main project file, which is responsible for building code and running it on an embedded server. | ||
ProducerController.java provides an endpoint (@PostMapping("/publish")) through which receives messages string from web pages and sends to KafkaTemplate. | ||
index.html is a web view page that provides the Producer process and through which we send messages. | ||
pom.xml is a project build tool file. This file has java dependencies and builds configuration details. | ||
For creating the “producer.jar” file, use the command "mvn clean package". | ||
Click Here To Download the "Producer" project zip file. |
b. Consumer Web System | ||
---|---|---|
It is an example of the Spring Boot JAVA Framework. When we will build this project then it will create a "consumer.jar" executable file. | ||
It has java code files (ConsumerController.java, ConsumerService.java, SpringKafkaConsumer.java), build file (pom.xml), and static web files (index.html, cloud.png). | ||
SpringKafkaConsumer.java is the main project file, which is responsible for building code and running it on an embedded server. | ||
ConsumerController.java provides an endpoint (@GetMapping("/message")) through which receive messages string from KafkaListener and send to the web page to show messages. | ||
ConsumerService.java provides messages service through which collect all messages from KafkaListener and store in List buffer based on topics & groupId. | ||
index.html is a web view page that provides the Consumer process and shows all collected messages. | ||
pom.xml is a project build tool file. This file has java dependencies and builds configuration details. | ||
For creating the “consumer.jar” file, use the command "mvn clean package". | ||
Click Here To Download "Consumer" project zip file. |
4. Run The Project
a. Producer Web System | b. Consumer Web System | |
---|---|---|
1. |
Start Zookeeper and Kafka server. (My VM IP: 192.168.0.106 and Port: 9092 ) |
|
2. |
Download producer.jar in the local system. Click Here To Download the "producer.jar" executable jar file. |
Download consumer.jar in the local system. Click Here To Download the "consumer.jar" executable jar file. |
3. |
Run producer.jar in the local system. At execution time pass server port (8081 )
and Kafka server IP:port (192.168.0.106:9092 ).Here we can use a different port if the port already uses in the local system.
|
Run consumer.jar in the local system. At execution time pass server port (8082 )
and Kafka server IP:port (192.168.0.106:9092 ).Here we can use a different port if the port already uses in the local system.
|
4. |
Open producer web project in the local browser.
|
Open consumer web project in the local browser.
|
5. |
On the Producer page select a subject, type a message and submit. | |
6. |
After submitting a message from the Producer page, the Consumer page automatically receives that submitted message. | |
:) ...enjoy the Kafka messaging project.