Apache Kafka Messaging Project

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. Open Producer Consumer
b.   Select subject & type message for the selected subject in Producer WebClient System. Producer Type Message
c.   Submit message from Producer WebClient System to Kafka topics for Consumer WebClient System. Producer Submit Message
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. Consumer Receive Message

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. Producer Project Folder
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. Consumer Project Folder
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)
Start Zookeeper and Kafka Server

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.
Download Producer Jar Download Consumer Jar

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.

java -jar producer.jar --server.port=8081 --spring.kafka.producer.bootstrap-servers=192.168.0.106:9092

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.

java -jar consumer.jar --server.port=8082 --spring.kafka.consumer.bootstrap-servers=192.168.0.106:9092

Start Producer Jar Start Consumer Jar

4.

Open producer web project in the local browser.

http://localhost:8081

Open consumer web project in the local browser.

http://localhost:8082

Start Web Producer Project Start Web Consumer Project

5.

On the Producer page select a subject, type a message and submit.
Select Type Submit Message Start Web Consumer Page

6.

After submitting a message from the Producer page, the Consumer page automatically receives that submitted message.
Producer Submit Message Consumer Receive Message

:) ...enjoy the Kafka messaging project.