The application demonstrates service of communication between producer and consumer microservices using Apache Kafka.
- Spring Boot
- Apache Kafka
- Lombok
- Swagger
- Maven
Install Apache Kafka for MacOS X.
brew install kafka
Install Apache Kafka for Ubuntu.
apt install kafka
Start zookeeper and kafka in terminal. Set up path to zookeeper.properties and server.properties.
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties & kafka-server-start /usr/local/etc/kafka/server.properties
Create topic server, set up port(9092) and quantity of replications (1) and partitions (1), write topic's name (example-topic).
bin/kafka-topics.sh --create \
--zookeeper localhost:9092 \
--replication-factor 1 --partitions 1 \
--topic example-topic
Set up kafka-producer service.
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
Change directory to kafka-producer and run application.
cd kafka-producer
mvn spring-boot:run
Set up kafka-consumer service.
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
Change directory to kafka-consumer and run application.
cd kafka-consumer
mvn spring-boot:run
Open the url - localhost:8080/swagger-ui.html, choose kafka-producer-controller
and send any message.
curl -X POST "http://localhost:8080/kafka/publish?message=Good%20evening!" -H "accept: */*"
See in terminal of kafka-consumer - log.info.
2020-05-05 23:46:32.849 INFO 16760 --- [ main] c.e.k.k.KafkaConsumerApplication : Receive message=Good evening!
For any problems, comments, or feedback please create an issue here.