Architecture Microservice with Spring Cloud and Best Practices
This repository is Dealer Management Systems based on a microservices architecture.
The architecture supports the following technologies:
Codebase One codebase tracked in VCS, many deploys. One app has a single code base and its tracked by a version control system like Git, Subversion, Mercurial, etc. You can do many deployments (from the same code base) to development, testing, staging and production environments.
Dependencies. Explicity declare and isolate dependencies. Some times your environments don’t have internect connection (if is a private system), so you need to think about packaging your dependencies (jars, gems, shared-libraries, etc) or if you have an internal repository of libraries, you can declared manifest like poms, gemfile, bundles, etc. Never rely that you will have everything in your final environment.
Configuration. Store config in the environment. You should’t hardcode anything that varies. Use the environment variables or a configuration server.
Backing Services Treat backing services as attached resources. Connect to services via URL or configuration.
Build, Release, Run Strictly separate build and run stages. Related to a CI/CD (Continuous Integration, Continuous Delivery)
Processes Execute the app as one or more stateless processes. Processess should not store internal state. Share nothing. Any necessary state should be considered as a Backing Service.
Port binding Export services via port port binding. Your application is self-container, and these apps are exposed via port binding. An application can become another App’ service.
Concurrency Scale out via the process model. Scale by adding more application instances. Individual processes are free to multithread.
Disposability Maximize robustness with fast startup and graceful shutdown. Processes should be disposable (remember they are stateless). Fault tolerant.
Environment parity. Keep development, staging and production environments as similar as possible. This is a result of High Quality, ensures continuous delivery.
Logs Treat logs as event streams. Your apps should write to stdout. Logs are streams of aggregated, time-ordered events.
Admin processes Run admin and managemenr tasks as one-off processes. Run admin processes on the platform: DB migrations, one time scripts, etc.
The following diagram shows the targert platform architecture.:
Since an auto dealership application uses the Microservice architecture pattern for vehicle details data is spread over multiple services. For example,
Consequently, the code that displays the vehicle details needs to fetch information from all of these services.
Each service is:
:small_orange_diamond: Highly maintainable and testable enables rapid and frequent development and deployment.
:small_orange_diamond: Loosely coupled with other services - enables a team to work independently the majority of time on their service(s) without being impacted by changes to other services and without affecting other services.
:small_orange_diamond: Independently deployable - enables a team to deploy their service without having to coordinate with other teams
:small_orange_diamond: Capable of being developed by a small team - essential for high productivity by avoiding the high communication head of large teams.
:small_orange_diamond: Services communicate using either synchronous protocols such as HTTP/REST or asynchronous protocols such as AMQP.
:small_orange_diamond: Services can be developed and deployed independently of one another.
:small_orange_diamond: Each service has its own database in order to be decoupled from other services.
:small_orange_diamond: Data consistency between services is maintained using the Saga pattern.
:small_orange_diamond: Client-side Discovery pattern or Server-side Discovery pattern to route requests to available service instances.
:small_orange_diamond: The API Gateway authenticate the user and pass an Access Token containing information about the user to the services
:small_orange_diamond: API Gateway use a Circuit Breaker to invoke services :small_orange_diamond: API gateway often implements the API Composition pattern.
:small_orange_diamond: Asynchronous Java API + Reactive Programming Model.
:small_orange_diamond: Hystrix Fault Tolerance.
This is a Maven project. However, you need to have installed :
The details of how to build and run the services depend slightly on whether you are using
First, must sign up to get your credentials in order to get free access to the SaaS version.
Next, build the application
$ git clone https://github.com/rcherara/rcherara-spring-cloud-microservice.git
$ cd rcherara-spring-cloud-microservice
$ mvn install
Next, you can launch the services using Docker Compose:
$ docker-compose up -d
Run locally with Maven, Visual Studio Code, STS, Eclipse or IntelliJ:
:point_right: Gateway http://localhost:8080
:point_right: Eureka Discovery Dashboard http://localhost:8761
:point_right: Config Server http://localhost:7761
:point_right: Spring Admin Dashboard http://localhost:9761
:point_right: Vehicle service http://localhost:8081
:point_right: Dealership service http://localhost:8082
:point_right: Transaction service http://localhost:8083
:point_right: RabbitMq (username/password: guest/guest) http://localhost:15000
Run with docker-compose:
:point_right: Gateway http://localhost:5080
:point_right: Eureka Discovery Dashboard http://localhost:5761
:point_right: Config Server http://localhost:5760
:point_right: Spring Admin Dashboard http://localhost:5761
:point_right: Vehicle service http://localhost:5081
:point_right: Dealership service http://localhost:5082
:point_right: Transaction service http://localhost:5083
:point_right: RabbitMq (username/password: guest/guest) http://localhost:15000
Spring Cloud Config Server offers the following benefits:
HTTP resource-based API for external configuration (name-value pairs or equivalent YAML content)
Encrypt and decrypt property values (symmetric or asymmetric)
Embeddable easily in a Spring Boot application using @EnableConfigServer
Spring Cloud Config Client lets you:
Bind to the Config Server and initialize Spring Environment with remote property sources.
Encrypt and decrypt property values (symmetric or asymmetric).
@RefreshScope for Spring @Beans that want to be re-initialized when configuration changes.
Use management endpoints:
Bootstrap application context: It binds to the Config Server and decrypts property values.
The services are Swagger "enabled".
Open the url http://${DOCKER_HOST_IP}:<SERVICE-PORT>/swagger-ui.html
All Swagger Resources(groups) : http://localhost:<SERVICE-PORT>/swagger-resources Swagger UI endpoint: http://localhost:<SERVICE-PORT>/swagger-ui.html Swagger docs endpoint: http://localhost:<SERVICE-PORT>/v2/api-docs
mkdir rcherara
cd rcherara
git clone --recurse-submodules <url>
cd rcherara-spring-cloud-microservice
mvn clean package -DskipTests
To run locally:
$ cd vehicle-service
$ java -jar target/vehicle-service-0.0.1.BUILD-SNAPSHOT.jar
To run locally:
cd dealership-service
java -jar target/dealership-service-0.0.1.BUILD-SNAPSHOT.jar
To run locally:
cd transaction-service
java -jar target/transaction-service-0.0.1.BUILD-SNAPSHOT.jar
To run locally:
cd gateway-service
java -jar target/gateway-service-0.0.1.BUILD-SNAPSHOT.jar
To run locally:
cd discovery-service
java -jar target/discovery-service-0.0.1.BUILD-SNAPSHOT.jar
To run locally:
cd admin-service
java -jar target/admin-service-0.0.1.BUILD-SNAPSHOT.jar
The following guides illustrate how to use some features concretely:
Eco-system for a car dealer based on a microservices architecture is open source and want to give to you the basics knowledge about cloud native application, architecture, DevOps with Docker, Kubernate Cloud, Spring Java, React Typescript and technologies. A star to this project will be appreciate!
CHERARA REDDAH.