A complete ecommerce demo Implement based on Microservice Architecture Pattern using Spring Boot, Spring Cloud, Spring WebFlux, Postgresdb and Docker.
In this project I didn't built independent microservices But i implemented microservices share the same database Why?
Because I want to use database tools like ACID transactions, joins, bulk files imports, ...
instead of network overhead for interprocess communication between microservices.
I worked in a large project implemented based on microservices architecture we have a set of independent services and
I used Spring Cloud Open Feign
for inter-process communication (Which uses client side load balancer ribbon)
I'm planning to implement another version from project with independent microservices and communicate via feign.
I have split services into two types system and logical services.
Secured, Authorized and Paginated endpoints.
Authorization Server for all other services which grants OAuth2 tokens for the backend resource services. All other secured services must set jwk uri for endpoint implemented on this service.
security:
oauth2:
resourceserver:
jwt:
jwk-set-uri: ${JWKS_URL}
Endpoints
Method | Path | Description | User authenticated |
---|---|---|---|
GET | /.well-known/jwks | System endpoint to get JSON Web Key Set (JWKS) is a set of keys containing the public keys that should be used to verify JWT token | |
POST | /user/merchant | Register new merchant account (with merchant role) | |
POST | /user/client | Register new client account (with client role) | |
GET | /user | Get current login user information | × |
Manage products information and inventory Endpoints
Method | Path | Description | User authenticated | Role |
---|---|---|---|---|
GET | /list?page={page}&pageSize={pageSize} | Get all products | x | any |
GET | /list/merchant?page={page}&pageSize={pageSize} | Get products created by merchant | x | merchant,admin |
POST | /save | Create new product | x | merchant |
PUT | /save | Update existing product | x | merchant |
GET | /list/available?page={page}&pageSize={pageSize} | Get available products with inventory > 0 | × | any |
GET | /list/not-available?page={page}&pageSize={pageSize} | Get available products with inventory = 0 | × | any |
Manage products information and inventory Endpoints
Method | Path | Description | User authenticated | Role |
---|---|---|---|---|
GET | /list/user?page={page}&pageSize={pageSize} | Get login user orders | x | any |
GET | /{orderId} | Get order by id | x | any |
POST | /save | Create new order | x | client |
PUT | /save | Update existing order | x | client |
Core service to implement Netflix OSS design architecture and Services token security
Provides configuration for all other services (centralize configuration for all services).
Details: Spring Cloud Config
It allows automatic detection of network locations for service instances, which could have dynamically assigned addresses because of auto-scaling,
failures and upgrades (Every service register in this service after running).
Details: Spring Cloud Netflix
Eureka server url: http://localhost:2222/
Provide a proxy (routing) and client side load balancing via ribbon You can deploy multiple services for the same service and gateway will load balancing between them ( Simple scalability ) Details: Spring Cloud Gateway
Migrations service handle changes on database tables using flyway
To apply change on database please create file in this folder ecommerce-microservices/storage/migration/src/main/resources/flyway/migrations
in this structure *__*.sql
then apply this command
cd ecommerce-microservices/storage/migration # change it to your path
mvn clean package
docker-compose build
docker-compose up migration
Not completed require implement turbine service and any broker service (rabbitmq) But you can access start page from http://localhost:8000/hystrix
mvn clean install
docker-compse build
docker-compse up
# on the first run or after update sql migration on migration service
docker-compose up migration
Probably you got issues because docker caching refresh docker images by:
docker rm $(docker ps -a -q) -f
docker volume prune
greatly appreciate your help. Feel free to suggest and implement improvements.