# spring-boot-microservices-project A small e-commerce system on **Spring Boot 4.1.1** and **Spring Cloud 2025.1.3**, written for the article [Spring Boot Microservices Project: Gateway, Discovery, Config and 3 Services](https://ankurm.com/spring-boot-microservices-project/). ``` client ──> gateway :8080 ──> product-service :8081 ├─> order-service :8082 ──> product-service (read the price) │ └──> inventory-service (reserve stock, circuit breaker) └─> inventory-service :8083 config-server :8888 serves every service's configuration (and the gateway's routes) discovery-server :8761 (Eureka) every service registers here and finds the others here ``` | Module | What it is | |---|---| | `config-server` | Spring Cloud Config Server, native profile; files in `src/main/resources/config/` | | `discovery-server` | Eureka server | | `gateway` | Spring Cloud Gateway Server WebMVC; routes come from the config server (`gateway.yml`) | | `product-service` | `GET /products`, `GET /products/{id}` | | `inventory-service` | stock levels, `POST /inventory/{id}/reserve`, a switch to simulate an outage | | `order-service` | `POST /orders`; calls product-service and inventory-service through the load balancer and a Resilience4j circuit breaker | ## Run it (no Docker needed) Needs JDK 21+, Maven 3.9+, curl and python3. ```bash ./scripts/run-all.sh # build, start the six services, run the scenarios, stop everything ./scripts/start.sh # or: start the services and leave them running ./scripts/demo.sh # re-run the scenarios (rewrites output/) ./scripts/stop.sh ``` Start order matters: **config server first** (everything else reads its configuration from it), then Eureka, then the rest. ## Docker `Dockerfile` and `docker-compose.yml` are provided but were **not run**: the sandbox this was written in had no Docker. Treat them as a starting point, not a tested artifact. ## Captured output Every file in `output/` is written by `scripts/demo.sh` from real requests. Nothing is typed by hand. | File | What it shows | |---|---| | `01-config-server.txt` | What the config server serves and the value the order service ended up with | | `02-eureka-registry.txt` | The instances registered in Eureka | | `03-gateway-requests.txt` | Requests through the gateway: products, stock, orders, and the error cases | | `04-trace-propagation.txt` | One request, one trace id, in the logs of four services | | `05-circuit-breaker.txt` | The circuit breaker going CLOSED, OPEN, and back to CLOSED | ## Versions Spring Boot 4.1.1, Spring Framework 7, Spring Cloud 2025.1.3 (its BOM is built against Boot 4.0.8; it ran here on 4.1.1), Tomcat 11, Java 21 (OpenJDK 21.0.12). JDK 25 was not available when this was written.