This project is a comprehensive microservice-based e-commerce application built using Spring Cloud, providing a scalable and resilient architecture for online retail operations.
The application consists of several microservices that work together to handle various aspects of an e-commerce platform. These services include a store service, supplier service, delivery service, authentication server, configuration server, service discovery, and an API gateway.
auth-server/
: OAuth2 authentication serverconfig-server/
: Spring Cloud Config server for centralized configuration managementeureka-server/
: Service discovery server using Netflix Eurekagateway-zuul/
: API Gateway using Netflix Zuulloja/
: Store microservice handling purchase operationsfornecedor/
: Supplier microservice managing product inventory and orderstransportador/
: Delivery microservice for handling shippingmicroservice-config/
: Configuration files for different microservices and environmentspostman/
: Postman collection for API testing
Key Files:
pom.xml
: Parent Maven configuration filenew_release.sh
: Script for creating new releasesset-pom-version.js
: Script for updating version numbers in POM files
Prerequisites:
- Java 11
- Maven 3.6+
- MariaDB 10.5+
Steps:
- Clone the repository:
git clone <repository-url>
- Navigate to the project root:
cd microservice-project
- Build the project:
mvn clean install
- Start the Config Server:
java -jar config-server/target/config-server-<version>.jar
- Start the Eureka Server:
java -jar eureka-server/target/eureka-server-<version>.jar
- Start the Auth Server:
java -jar auth-server/target/auth-server-<version>.jar
- Start other microservices (loja, fornecedor, transportador) in any order.
- Start the Gateway:
java -jar gateway-zuul/target/gateway-zuul-<version>.jar
Each microservice can be configured using the application.yml
file in its src/main/resources
directory. Global configurations are managed in the microservice-config/
directory.
-
Creating a new purchase:
POST http://localhost:8080/api/v1/compras { "endereco": { "rua": "Example Street", "numero": 123, "estado": "EX" }, "itens": [ { "id": 1, "quantidade": 5 } ] }
-
Retrieving purchase information:
GET http://localhost:8080/api/v1/compras/{id}
-
Retrieving supplier information:
GET http://localhost:8081/api/v1/info/{estado}
Run tests for all modules:
mvn test
-
Issue: Microservice fails to start
- Check if the Config Server is running and accessible
- Verify database connection details in the configuration
- Enable debug logging by setting
debug: true
in the application.yml
-
Issue: Authentication fails
- Ensure the Auth Server is running
- Verify client credentials in the Auth Server configuration
- Check if the token is being properly passed in the request header
-
Issue: Service discovery problems
- Confirm that the Eureka Server is running
- Check if the microservice has properly registered with Eureka
- Verify Eureka client configuration in the microservice's application.yml
For debugging, enable verbose logging by setting logging.level.root=DEBUG
in the application.yml of the affected service.
- Client sends a request to the Gateway (Zuul)
- Gateway authenticates the request using the Auth Server
- Gateway routes the request to the appropriate microservice
- Microservice processes the request, potentially communicating with other services
- Response is sent back through the Gateway to the client
Client -> Gateway -> Auth Server
-> Microservice A <-> Microservice B
-> Microservice C -> Database
Prerequisites:
- Docker
- Kubernetes cluster
Steps:
- Build Docker images for each microservice
- Push images to a container registry
- Apply Kubernetes manifests to deploy services
- Configure ingress for external access
The project uses the following key infrastructure components:
- Spring Boot (version 2.3.0.RELEASE)
- Spring Cloud (version Hoxton.SR5)
- Netflix Eureka for service discovery
- Netflix Zuul for API gateway
- Spring Cloud Config for centralized configuration
- Spring Cloud OAuth2 for authentication
- MariaDB for data persistence
- Undertow as the web server
Each microservice is configured with its own database connection, Eureka client settings, and security configurations.