A simple example for an Event Driven Flow by the help of SPRING CLOUD STREAM KAFKA
- java.version:
11
- spring-cloud.version:
Hoxton.SR12
(To get Advantage of Binders@Input
,@Output
) - spring-boot.version:
2.4.13
Please visit Spring Cloud Stream Kafka (Part 1) for Project documentation
The Docker-compose file contains: single kafka and zookeeper. just simply run the following command
docker-compose up -d
or
- Control Center UI
Runs a Confluent Control Center that exposes a UI at
http://localhost:9021/
.
docker-compose -f ./kafka-cluster.yml -f ./control-center-ui.yml up
To stop the brokers and the Control Center UI run the following command:
docker-compose -f ./kafka-cluster.yml -f ./control-center-ui.yml down
Note: docker-compose file is at the root of this project "/scs-kafka-intro"
Run the First Test:
mvn clean package
Then run the generated jar file in target
folder, (so make sure you are in the same directory when you run the jar
file or give the full path)
java -jar target/scs-099-0.0.1-SNAPSHOT.jar
The application starts to listen on port 8080. make sure that port is not occupied by any other app already, if is try
to pass the following parameter before -jar
by adding --server.port=8081
Basically in this test, Producer adding 10 messages into kafka topic every 5 sec.
mvn spring-boot:run -Dspring.profiles.active=test2
or
java --spring.profiles.active=test2 -jar target/scs-099-0.0.1-SNAPSHOT.jar
mvn spring-boot:run -Dspring.profiles.active=test3
or
java --spring.profiles.active=test3 -jar target/scs-099-0.0.1-SNAPSHOT.jar
Run the following codes in 3 different terminal
on Terminal-1: (this app has one Producer and one consumer)
mvn spring-boot:run -Dspring.profiles.active=test2
or
java --spring.profiles.active=test2 -jar target/scs-099-0.0.1-SNAPSHOT.jar
on Terminal-2: (this app has only one consumer)
mvn spring-boot:run -Dspring.profiles.active=test2 -Dserver.port=8081
or
java --spring.profiles.active=test2 --server.port=8081 -jar target/scs-099-0.0.1-SNAPSHOT.jar
on Terminal-3: (this app has only one consumer)
mvn spring-boot:run -Dspring.profiles.active=test2 -Dserver.port=8082
or
java --spring.profiles.active=test2 --server.port=8082 -jar target/scs-099-0.0.1-SNAPSHOT.jar
Please visit Spring Cloud Stream Kafka (Part 1) for Project documentation
Spring Cloud Stream Polled Consumer with Embedded Kafka Broker Sample