Micro Marketplace is a robust e-commerce application built on a microservices architecture using Spring technologies and other open-source tools.
- This platform leverages the power of Spring Boot, Netflix Eureka, Spring Cloud Gateway, and KeyCloak for service development, discovery, gateway management, and security, respectively.
- It incorporates Resilience4j for resilient synchronous communication, and Apache Kafka for seamless event-driven asynchronous communication between services.
- It offers extensive observability into the application using Micrometer and Zipkin for distributed tracing, and Prometheus and Grafana for monitoring and visualization.
With a focus on scalability, resilience, and real-time interaction, Micro Marketplace provides a robust foundation for creating feature-rich online marketplaces.
- Product Service: Responsible for managing product information, including creation, retrieval, and updates. It uses a MongoDB database.
- Order Service: Handles order management, including creating and retrieving orders. It uses a MySQL database.
- Inventory Service: Manages products inventory. It also uses a MySQL database.
- Notification Service: A stateless service responsible for sending notifications to users regarding their orders or other relevant updates.
- Discovery Server: Netflix Eureka is employed for service registration and discovery, allowing microservices to locate and interact with each other dynamically.
- API Gateway: Spring Cloud Gateway is deployed to serve as the entry point for all external requests, effectively routing traffic to the appropriate microservices.
- Auth Server: For robust authentication and authorization mechanisms, KeyCloak is used to secure the microservices and protect sensitive data.
- Circuit Breaker: Resilience4j is used to maintain system reliability by preventing cascading failures in microservices through circuit-breaking mechanisms.
- Message Broker: Apache Kafka forms the backbone of Micro Marketplace's event-driven architecture, facilitating asynchronous notification for orders.
- Observability Stack: Distributed tracing is implemented to monitor and troubleshoot requests as they traverse different microservices, using Micrometer for metrics and Zipkin for tracing. Moreover, Prometheus is used for collecting metrics, and Grafana for providing a rich dashboard for visualizing and analyzing application performance data.
Languages & Frameworks |
|
Databases & Message Queue |
|
API Gateway |
|
Service Discovery |
|
Circuit Breaker |
|
Security |
|
Observability |
|
Build & Containerization |
|
- Docker and Docker Compose should be installed.
- Docker should be running.
-
Navigate to the project directory:
cd ecommerce-microservices
-
Start the containers:
docker compose up -d
-
Confirm that the containers are up and running:
docker ps
-
Getting Credentials from KeyCloak
- Access the KeyCloak Admin UI at http://localhost:8080/
- Go to the Realm
spring-boot-microservices-realm
- Go to the Client
spring-cloud-client
- Go the the 'Credentials' section, and get the 'Client Secret'
-
Setup Postman Authentication [Required in the next steps]
-
On the Request page, set Authorization:
- Type:
OAuth 2.0
- Configure New Token with:
- Token Name:
token
- Grant Type:
Client Credentials
- Access Token URL:
http://keycloak:8080/realms/spring-boot-microservices-realm/protocol/openid-connect/token
- Client ID:
spring-cloud-client
- Client Secret:
<client-secret>
(which you copied in the last step from KeyCloak)
- Token Name:
- Click on "Get New Access Token" and then click "Use Token"
NOTE: For getting the access token from the keycloak container with the local machine, it is required to add a row with
127.0.0.1 keycloak
in the file:C:\Windows\System32\drivers\etc\hosts
or/etc/hosts
- Type:
-
-
Accessing API Endpoints
-
POST /api/product
- Method: POST
- Endpoint: http://localhost:8181/api/product
- Authorization: Use the OAuth 2.0 token fetched, following the previous step.
- Body:
{ "name": "Iphone 15", "description": "Apple Iphone 15", "price": 1500 }
- Output:
-
GET /api/product
- Method: GET
- Endpoint: http://localhost:8181/api/product
- Authorization: Use the OAuth 2.0 token fetched, following the previous step.
- Output:
-
POST /api/order
- Method: POST
- Endpoint: http://localhost:8181/api/order
- Authorization: Use the OAuth 2.0 token fetched, following the previous step.
- Body:
{ "orderLineItemsDtoList": [ { "skuCode": "iphone_15_pro", "price": 2000, "quantity": 1 } ] }
- Output:
-
-
KeyCloak Admin UI
- Keycloak UI can be accessed on http://localhost:8080/
- Realm:
spring-boot-microservices-realm
- Client:
spring-cloud-client
-
Eureka Dashboard
- Services (Clients) discovered can be viewed on http://localhost:8761/
- Services (Clients) discovered can be viewed on http://localhost:8761/
-
Zipkin UI
- Traces for the API calls can be accessed on http://localhost:9411/zipkin/
- Traces for the API calls can be accessed on http://localhost:9411/zipkin/
-
Prometheus UI
- Prometheus UI can be accessed on http://localhost:9090/
- Prometheus Graph Query
- Prometheus Targets Health
- Prometheus Service Discovery Status
-
Grafana Dashboard
- Grafana Dashboard can be accessed on http://localhost:3000/
- To visualize the application, create a 'Data Source' and import the dashboard using
grafana-dashboard.json
file. - Data Source
- Dashboard [Collapsed]
- Dashboard
- To completely stop and remove the containers and other resources (network, volume, etc.), run the following command:
docker compose down -v