Spring Kafka example with JUnit 5 using EmbeddedKafka/spring-kafka-test
and also using Testcontainers.
For the tutorials check the links below,
- Test Spring Kafka consumer and producer with EmbeddedKafka
- Write Kafka integration test with Testcontainers
- Database migration with Spring Boot and Flyway
- Spring Boot MySQL integration tests with Testcontainers
- Spring Boot Swagger documentation using OpenAPI
- Disable Springdoc OpenAPI Swagger in production
First start the docker-compose which contains ZooKeeper, Kafka, Kafdrop, and MySQL.
$ docker-compose -f docker-compose.yml up -d
Once all the containers are healthy start the application,
$ ./mvnw spring-boot:run
Open the browser localhost:8080/apidocs
.
You can interact with the random
API to create a random user which then will be sent to Kafka and consumed by the consumer (see consumer/UserKafkaListener.java
file) and finally saves into the database.
To see whether the message has been sent to Kafka, open your browser http://localhost:8085/topic/com.madadipouya.kafka.use
(Kafdrop environment),
you should be able to see all messages that sent to kafka.user
topic.
To run Flyway migration scripts only run,
$ ./mvnw flyway:migrate