This project demonstrates a microservices architecture using Kafka with Spring Boot, consisting of two services:
These microservices interact via Kafka topics, where the DeliveryBoy service produces location updates, and the EndUser service consumes those updates. This project is a practical example of implementing event-driven architecture using Kafka and Spring Boot.
- DeliveryBoy (Producer): Sends location updates to a Kafka topic.
- EndUser (Consumer): Listens to the Kafka topic and consumes location updates.
- Event-driven communication between services via Kafka.
- Kafka integration with Spring Boot for seamless message production and consumption.
- Separate producer and consumer services using Kafka topics.
- Configurable properties for Kafka and service setup.
Location Topic: Used for publishing and consuming delivery location updates.
To run this project locally, ensure you have the following installed:
- Java 11 or higher
- Apache Kafka and Zookeeper running locally
- Maven for dependency management
- An IDE like IntelliJ or Eclipse for running the Spring Boot services
- Clone the Repository:
git clone https://github.com/chandrakanthrck/EventDrivenArchitecture.git
cd EventDrivenArchitecture- Set Up Apache Kafka:
- Make sure Kafka and Zookeeper are running locally. Use the following commands in your Kafka installation directory:
./zookeeper-server-start.sh config/zookeeper.properties
./kafka-server-start.sh config/server.properties- Create the Kafka Topic:
- Create the location-topic-name topic in Kafka:
./kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic location-topic-name- Build the Project:
- Navigate to each service directory (deliveryboy and enduser) and build the services:
mvn clean install- Run the Services:
- Run both the DeliveryBoy (producer) and EndUser (consumer) services. For DeliveryBoy:
cd deliveryboy
mvn spring-boot:runFor EndUser:
cd enduser
mvn spring-boot:runThe DeliveryBoy service sends location updates to Kafka. The service is configured via the application.properties file:
spring.application.name=deliveryboy
server.port=8080
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializerThe EndUser service consumes location updates from Kafka. It is configured via the application.properties file:
spring.application.name=enduser
server.port=8081
spring.kafka.consumer.bootstrap-servers=localhost:9092
spring.kafka.consumer.group-id=group-1
spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer- DeliveryBoy (Producer) sends location updates to the location-topic-name topic.
- EndUser (Consumer) listens to the location-topic-name topic and processes the updates. You can test this by producing a location update in the DeliveryBoy service and watching it be consumed by the EndUser service.
If you want to manually view messages in Kafka, you can run the Kafka console consumer:
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic location-topic-name --from-beginningFeel free to open issues and submit pull requests if you want to contribute to this project.
This project is licensed under the ISC License.