Skip to content

TestContainerLearn1/testcontainers-with-spring-boot-postgres-kafka

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Retail Order System

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.

Features

  • 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 OrderPlacedEvent events, 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.

Technologies Used

  • 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)

Getting Started

Prerequisites

  • 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)

Installation

  1. Clone the repository:
git clone https://github.com/j2eeexpert2015/testcontainers-with-spring-boot-postgres-kafka.git
cd testcontainers-with-spring-boot-postgres-kafka
  1. Build the application:
mvn clean install

Running the Application

With Docker Compose (Recommended)

  1. Start the Docker Compose environment:
docker-compose up -d

This will start PostgreSQL, Zookeeper, Kafka, and Kafka UI.

  1. Build and run the Spring Boot application (if not already built):
mvn spring-boot:run

Note: 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.

  1. (Optional) Access Kafka UI:

    • Kafka UI is available at http://localhost:8081 to monitor Kafka topics and messages.

Running with Spring Boot (Without Docker Compose)

  1. 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.properties are correct for your local setup.
  2. Run the Spring Boot application:

mvn spring-boot:run

Access Swagger UI

http://localhost:8080/swagger-ui/index.html

Access UI for Apache Kafka

http://localhost:8081

Running Tests

The project includes integration tests that use Testcontainers to run PostgreSQL and Kafka within Docker.

Running All Tests (with Testcontainers)

This command will run all tests, including those that use Testcontainers:

mvn test

👤 About the Instructor

Ayan Dutta - Instructor

Hi, 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.


🌐 Connect With Me


📺 Subscribe on YouTube

YouTube


📚 Explore My Udemy Courses

🧩 Java Debugging Courses with Eclipse, IntelliJ IDEA, and VS Code


Eclipse Debugging Techniques

Java Debugging With IntelliJ

Java Debugging with VS Code

💡 Java Productivity & Patterns


IntelliJ IDEA Tips & Tricks

Creational Design Patterns

🐍 Python Debugging Courses


Python Debugging With PyCharm

Python Debugging with VS Code

Python Debugging (Free)

🛠 Git & GitHub Courses


GitHub Desktop Guide

Git & GitHub with Eclipse

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 99.0%
  • Dockerfile 1.0%