This project is a Spring Boot application that provides a RESTful API for managing retail orders. It demonstrates a microservices architecture pattern by integrating PostgreSQL for persistent data storage and Kafka for asynchronous event-driven communication. The system supports basic order management operations and publishes order events to Kafka for other services to consume.
- Create, retrieve, update, and delete orders.
- Uses PostgreSQL for data persistence.
- Asynchronously publishes "Order Placed" events to a Kafka topic (
order_placed_topic) upon order creation. - Includes a Kafka consumer to process
OrderPlacedEventevents, simulating order processing. - Comprehensive test suite including unit and integration tests, with Testcontainers for PostgreSQL and Kafka.
- Docker support for easy setup and deployment, including Kafka and Kafka UI.
- OpenAPI 3 (Swagger) documentation for API endpoints.
- Java 17
- Spring Boot 3.1.0
- Spring Data JPA
- PostgreSQL 16-alpine (using Testcontainers)
- Kafka (using Confluent Platform cp-kafka:latest with Testcontainers)
- Maven
- JUnit Jupiter
- Testcontainers (for PostgreSQL and Kafka)
- Docker
- Springdoc-openapi (Swagger UI)
- Java 17 or higher
- Maven 3.6.0 or higher
- Docker (if you want to use the Docker setup)
- PostgreSQL (if you want to run the application outside Docker)
- Clone the repository:
git clone https://github.com/j2eeexpert2015/testcontainers-with-spring-boot-postgres-kafka.git
cd testcontainers-with-spring-boot-postgres-kafka- Build the application:
mvn clean install- Start the Docker Compose environment:
docker-compose up -dThis will start PostgreSQL, Zookeeper, Kafka, and Kafka UI.
- Build and run the Spring Boot application (if not already built):
mvn spring-boot:runNote: You can also build the application directly into the Docker image. For an optimized workflow, consider building a Docker image for the Spring Boot application and including it in your docker-compose.yml file.
-
(Optional) Access Kafka UI:
- Kafka UI is available at
http://localhost:8081to monitor Kafka topics and messages.
- Kafka UI is available at
-
Ensure PostgreSQL and Kafka are running and accessible.
- You need to have PostgreSQL and Kafka set up and running separately. Make sure the connection details in
src/main/resources/application.propertiesare correct for your local setup.
- You need to have PostgreSQL and Kafka set up and running separately. Make sure the connection details in
-
Run the Spring Boot application:
mvn spring-boot:runhttp://localhost:8080/swagger-ui/index.htmlhttp://localhost:8081The project includes integration tests that use Testcontainers to run PostgreSQL and Kafka within Docker.
This command will run all tests, including those that use Testcontainers:
mvn testHi, I’m Ayan Dutta, a Software Architect, Instructor, and Content Creator.
I create practical, hands-on courses on Java, Spring Boot, Debugging, Git, Python, and more.
- 💬 Slack Group: Join Here
- 📢 After joining, go to the
#java-debugging-with-intellij-idea-udemychannel - 📧 Email: j2eeexpert2015@gmail.com
- 🔗 YouTube: LearningFromExperience
- 📝 Medium Blog: @mrayandutta
- 💼 LinkedIn: Ayan Dutta
![]() Eclipse Debugging Techniques |
![]() Java Debugging With IntelliJ |
![]() Java Debugging with VS Code |
![]() IntelliJ IDEA Tips & Tricks |
![]() Creational Design Patterns |
![]() Python Debugging With PyCharm |
![]() Python Debugging with VS Code |
![]() Python Debugging (Free) |
![]() GitHub Desktop Guide |
![]() Git & GitHub with Eclipse |










