This project demonstrates a microservices architecture using Spring Cloud components, including Eureka Server, API Gateway, User Service, and Spring Boot Admin for monitoring.
- Eureka Server: Service discovery for all microservices.
- API Gateway: Load balancer and request router for microservices.
- User Service: A simple service registered with Eureka Server.
- Spring Boot Admin: Monitoring and managing Spring Boot applications.
Before running the project, ensure you have the following installed:
- Java 11 or later
- Maven 3.6+
- Docker (optional, for containerized deployment)
git clone https://github.com/your-repo/microservices-architecture.git
cd microservices-architectureBuild all services using Maven:
mvn clean installNavigate to the eureka-server directory and run:
cd eureka-server
mvn spring-boot:runEureka Server will be available at http://localhost:8761.
Navigate to the spring-admin directory and run:
cd spring-admin
mvn spring-boot:runSpring Boot Admin will be available at http://localhost:9090.
Navigate to the api-gateway directory and run:
cd api-gateway
mvn spring-boot:runAPI Gateway will be available at http://localhost:8080.
Navigate to the user-service directory and run:
cd user-service
mvn spring-boot:runUser Service will be available at http://localhost:8081.
application.yml for Eureka Server:
server:
port: 8761
eureka:
server:
eviction-interval-timer-in-ms: 5000
client:
register-with-eureka: false
fetch-registry: falseapplication.yml for Spring Boot Admin:
server:
port: 9090
spring:
application:
name: spring-admin
boot:
admin:
discovery:
enabled: true
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
register-with-eureka: true
fetch-registry: trueapplication.yml for API Gateway:
server:
port: 8080
spring:
application:
name: api-gateway
cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: user-service
uri: lb://user-service
predicates:
- Path=/users/**
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
register-with-eureka: true
fetch-registry: trueapplication.yml for User Service:
server:
port: 8081
spring:
application:
name: user-service
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
register-with-eureka: true
fetch-registry: true
instance:
prefer-ip-address: true- Eureka Dashboard: http://localhost:8761
- Spring Boot Admin: http://localhost:9090
- API Gateway: http://localhost:8080
- User Service: http://localhost:8081
- Ensure all services are correctly registered in Eureka.
- Verify
management.endpoints.web.exposure.includeincludeshealthandinfo. - Restart services if stale instances are present in the registry.
- Add
prefer-ip-address: truein theapplication.ymlof services. - Replace any hardcoded hostnames with
localhost.
This project is licensed under the MIT License. See the LICENSE file for details.