A multi-module Spring Cloud project that demonstrates the core building blocks of a microservice architecture: a service registry, an API gateway and two domain services that talk to each other through the registry.
- Service discovery with Netflix Eureka (Spring Cloud Netflix).
- Edge routing with Spring Cloud Gateway.
- Two independently deployable Spring Boot services that register themselves with Eureka.
- Inter-service communication, where
user-servicecallsdepartment-servicevia a Value Object response template. - Standard Spring Boot patterns: JPA persistence (H2 in-memory), REST controllers, layered architecture.
+-------------------------+
client ---------> | cloud-gateway | (Spring Cloud Gateway, port 9191)
+-------------+-----------+
| routes via Eureka
+------------------+------------------+
v v
+---------------------+ +-----------------------+
| user-service | ----- REST --> | department-service |
| port 9002 | inter-svc | port 9001 |
| (DepartmentUser) | | (Department) |
+---------------------+ +-----------------------+
^ ^
| registers with |
+---------------+---------------------+
v
+---------------------------+
| service-registry | (Netflix Eureka, port 8761)
+---------------------------+
| Module | Port | Role |
|---|---|---|
service-registry |
8761 | Netflix Eureka server. All services register here. |
cloud-gateway |
9191 | Spring Cloud Gateway. Single entry point routing to the right service via Eureka. |
department-service |
9001 | Spring Boot REST service exposing Department resources, persisted in H2 with JPA. |
user-service |
9002 | Spring Boot REST service exposing DepartmentUser resources. Calls department-service and returns a combined response via ResponseTemplateVO. |
- Java + Spring Boot 2.7.x
- Spring Cloud 2021.0.4
- Spring Cloud Gateway
- Netflix Eureka (server and clients)
- Spring Data JPA + H2 (in-memory)
- Maven
- Java 17 or newer (
java -version) - No need to install Maven, the project includes the Maven wrapper in each module
Open four terminals, one per module, and start them in this order:
git clone https://github.com/Haseeb-Khalil/MicroService.git
cd MicroService
# Terminal 1: Eureka registry
cd service-registry && ./mvnw spring-boot:run
# Terminal 2: Department service (wait until Eureka is up)
cd department-service && ./mvnw spring-boot:run
# Terminal 3: User service
cd user-service && ./mvnw spring-boot:run
# Terminal 4: Gateway
cd cloud-gateway && ./mvnw spring-boot:runOn Windows replace ./mvnw with mvnw.cmd.
- Eureka dashboard:
http://localhost:8761(you should see USER-SERVICE, DEPARTMENT-SERVICE, API-GATEWAY registered) - Department service direct:
http://localhost:9001/departments/1 - User service direct:
http://localhost:9002/users/1 - Through the gateway:
http://localhost:9191/departments/1andhttp://localhost:9191/users/1
Hands-on practice for the microservice patterns I work with at Capgemini on the HMRC Enterprise Integration Services (EIS) programme: independently deployable Spring Boot services, service discovery and routing, and clean inter-service communication.