This project showcases a microservices architecture built with Spring Boot and Spring Cloud. It comprises five distinct services designed to work together seamlessly. Each service is independently deployable and interacts with others through RESTful APIs, with service discovery, load balancing, and security features provided by Spring Cloud components.
-
Function: A central registry for service discovery.
-
Technology: Eureka Server.
-
Responsibilities: Registers all services and enables dynamic discovery of services, allowing for load balancing and failover.
-
Function: Acts as a single entry point for all external requests.
-
Technology: Spring Cloud Gateway.
-
Responsibilities: Routes requests to appropriate services, providing security and load balancing.
- Function: Manages product information.
- Technology: Spring Boot, MongoDB.
- Responsibilities: Provides CRUD operations for product data.
- Function: Handles order creation, processing, and persistence.
- Technology: Spring Boot, PostgreSQL.
- Responsibilities: Manages orders and interacts with the Store Service to check product availability.
- Function: Tracks product stock levels.
- Technology: Spring Boot, PostgreSQL.
- Responsibilities: Manages stock levels for products, ensuring orders can be fulfilled.
The project is organized into multiple modules, each representing a specific service:
- discovery-server: Eureka Server configuration and security setup.
- api-gateway: API Gateway configuration including routing rules and security settings.
- product-services: Product Service implementation including controllers, models, repository, and service logic.
- order-services: Order Service implementation including controllers, models, repository, and service logic. Includes a WebClientConfig class for communication with the Store Service.
- store-services: Store Service implementation including controllers, models, repository, and service logic.
- Java: 21
- Maven: 3.x
- MongoDB: 4.x
- PostgreSQL: 15.x
git clone https://github.com/your-username/microservices.git
Navigate to each module directory and run:
mvn spring-boot:run
- Discovery Server (
discovery-server
module) - API Gateway (
api-gateway
module) - Product Service (
product-services
module) - Store Service (
store-services
module) - Order Service (
order-services
module)
- Service Discovery: Utilizes Eureka Server for service registration and discovery.
- Security: Discovery Server secured with basic authentication.
- Load Balancing: Provided by the API Gateway for routing requests to backend services.
- Database Integration: Services use MongoDB or PostgreSQL for data storage.
- RESTful APIs: Expose RESTful endpoints for interaction.
Interact with the API Gateway through the defined endpoints once all services are running.
-
Create Product:
curl -X POST -H "Content-Type: application/json" -d '{ "name": "iPhone 14 Pro", "description": "Apple's latest flagship phone", "price": 1199.99 }' http://localhost:8080/api/product
-
Get All Products:
curl -X GET http://localhost:8080/api/product
- Check Stock:
curl -X GET http://localhost:8080/api/store?skuCode=iphone_13&skuCode=iphone_13_red
- Place Order:
curl -X POST -H "Content-Type: application/json" -d '{ "orderLineItemsList": [{ "skuCode": "iphone_13", "price": 1000.00, "quantity": 1 }] }' http://localhost:8080/api/order
- Authentication and Authorization: Implement robust security measures like OAuth2.
- Circuit Breaker: Introduce resilience patterns like Hystrix to handle service failures.
- Messaging: Utilize message queues for asynchronous communication between services.
- Monitoring and Logging: Implement centralized logging and monitoring systems for improved observability.
- Testing: Enhance test coverage with integration and end-to-end tests.
This microservices project demonstrates a foundational setup for building distributed applications with Spring Boot and Spring Cloud. It provides essential features for service discovery, load balancing, database integration, and API Gateway configuration. The architecture is modular and extensible, allowing for the addition of more advanced features and adaptation to specific application requirements.
Feel free to explore the project and extend its capabilities to suit your needs.