This is an example of microservice architecture pattern implemented with following stack of Java-technologies:
- JDK 13
- Spring Cloud
- Spring Cloud Gateway
- Spring Cloud Config
- Spring Cloud Sleuth
- Spring Cloud OpenFeign
- Spring Cloud Netflix
- Gradle with Kotlin DSL
- Other: Thymeleaf, Bootstrap, Webjars
Diagram of components
Stores configs of all microservices.
Service discovery server
Performs Service registry function. Spring Cloud Netflix Eureka is used which is Client-side service discovery. Each application sends heartbeats to Eureka server after registration.
This is an example of front-end which uses Thymeleaf for HTML-pages rendering and Bootstrap CSS framework (plugs in with help of Webjars). Application contains a few examples of interacting with back-end (Items service) by using different API:
You can test all of these approaches by request to
You can test Hystrix fallback working by request to
Performs authentication and routing to UI microservices (only Items UI in this project). Routing implemented with Spring
Cloud Gateway which settings as well as other settings are stored in YAML-config.
Also application contains route to Eureka
https://localhost/eureka. All routes you can see by request to
https://localhost/actuator/gateway/routes. Access to
login page implements using WebFlux.
You can perform authentication with one of hardcoded
users. Application passes user's login and roles by adding
it to HTTP request headers. You can request to
https://localhost/items-ui/greeting to see passed credentials. Sure you
can access all other endpoints provided by Items UI. As well as Items UI this application uses Thymeleaf and Bootstrap for UI purposes.
ui-gateway works on port 443 and is available with HTTPS protocol. SSL certificate was created by using following command:
keytool -genkey -alias test_key -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650
and with qwerty password.
This schema is simple, see here for details.
Depending of your OS:
gradlew clean build or
./gradlew clean build.
Used Gradle 5 requires at least JDK 8.
Run all microservices in the same order as they are listed. If you are using Intellij IDEA with enabled Run Dashboard you should get something like: