Microservices - also known as the microservice architecture - is an architectural style that structures an application as a collection of services that are
- Highly maintainable and testable
- Loosely coupled
- Independently deployable
- Organized around business capabilities
- Owned by a small team
The microservice architecture enables the rapid, frequent and reliable delivery of large, complex applications. It also enables an organization to evolve its technology stack.
- Eureka server - It is used to provides as a discovery server for applications. This server maintains and distributes a dynamic list of available application instances that are then used by the microservices to do HTTP requests routing and load balancing.
- Swagger - It allows you to describe the structure of your APIs so that machines can read them. The ability of APIs to describe their own structure is the root of all awesomeness in Swagger.
- Spring Cloud Config server - It is used to provide runtime configuration properties to all applications.
- Spring Cloud Openfeign - It is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it. Spring Cloud integrates Eureka, as well as Spring Cloud LoadBalancer to provide a load-balanced http client when using Feign. It provides client side load balencer in round robbin fassion.
-
git clone
-
Start/deploy all applications in below sequence.
- config-server ->
java -jar <path to jar file>
- eureka-discovery-server ->
java -jar <path to jar file>
- user-service ->
java -jar <path to jar file> --spring.profiles.active=dev
- arithmatic-operations-service ->
java -jar <path to jar file> --spring.profiles.active=dev
- config-server ->
-
Swagger -> http://localhost:8080/swagger-ui.html
-
Eureka server -> http://localhost:8761/
-
Config server -> http://localhost:8888/user-service/dev or http://localhost:8888/arithmatic-operations-service/dev
-
To test Feign service Open 2 command prompts and run below command on each
cd arithmatic-operations-service mvn package java -jar target\arithmatic-operations-service-0.0.1-SNAPSHOT.jar --server.port=8083 Note - use unique port number for each cmd/instance
Then hit the url from postman using below details
POST: http://localhost:8080/hello BODY: { "name" : "prashant" }
You will see the logs getting printed on both console in round robin fassion.
https://microservices.io/ https://cloud.spring.io/spring-cloud-openfeign/reference/html/ https://cloud.spring.io/spring-cloud-config/spring-cloud-config.html https://cloud.spring.io/spring-cloud-netflix/multi/multi_pr01.html https://cloud.spring.io/spring-cloud-netflix/reference/html/