Research the Spring Cloud Netflix
Consumer ● Producer ● Registration
The microservice registration and discovery are done with the Eureka Service Discovery server.
The Eureka server uses a Resilience4J circuit breaker.
The sections of this project:
Java source code. Packages in modules 'common', 'producer', 'consumer', and 'registration':
module 'common' application sources:
kp.common
module 'producer' application sources:
kp.producer
module 'consumer' application sources:
kp.consumer
module 'registration' application sources:
kp.registration
Action:
1. With batch file
'01 MVN clean install.bat'
build servers.
2. With batch file
'02 run registration server.bat'
start the Eureka registration server.
3. With batch file
'03 run producer server.bat'
start the producer-service server.
It registers the 1st instance of producer-service.
4. With batch file
'04 run producer server (9091).bat'
start the alternative producer-service server on port 9091.
It registers the 2nd instance of producer-service.
5. With batch file
'05 run consumer server.bat'
start the consumer-service server.
producer-service on port 8081 | http://localhost:8081/content |
producer-service on port 9091 | http://localhost:9091/content |
consumer-service | http://localhost:8082/content |
Eureka Dashboard | http://localhost:8761/ |
producer server | application.yml |
consumer server | application.yml |
registration server | application.yml |
1.1. In the ConsumerApplication the web client 'RestTemplate' is configured to use a 'LoadBalancerClient'.
1.2. The screenshots from the Eureka Dashboard.
Screenshot fragment from the Eureka Dashboard home
Screenshot fragment from the Eureka Dashboard 'registered leases' tab
1.3. The registration server console log screenshot.
1.4. The Eureka server endpoint with the list of registered applications: http://localhost:8761/eureka/apps/.
Action:
1. In the web browser call consumer-service two times.
Link http://localhost:8082/content.
The consumer-service controller GET method: kp.consumer.controller.ConsumerController::getContent.
The kp.consumer.service.ConsumerService with web client RestTemplate and CircuitBreaker for fallbacks.
The consumer-service service method: kp.consumer.service.ConsumerService::getContent.
The producer-service controller GET method: kp.producer.controller.ProducerController::getContent.
2.2. Calling the consumer-service two times returns the same result in the web browser.
The result from the consumer-service
The consumer-service was called two times.
console log from the consumer-service server.
On the 1st call, the consumer-service responded with the content from the producer-service on port 9091.
console log from the producer-service server on port 9091.
On the 2nd call, the consumer-service responded with the content from the producer-service on port 8081.
console log from the producer-service server on port 8081.
It is the round-robin load-balancing algorithm.
Action:
1. Execute the batch file
06 CURL read.bat.
3.1. The screenshot of the console log from the run of the batch file "06 CURL read.bat".
Action:
1. Start the Eureka registration server.
2. Start producer-service server on default port 8081.
3. Start consumer-service server.
4. Execute "06 CURL read.bat".
5. Kill the producer-service on default port 8081.
6. Start producer-service' server on alternative port 9091.
7. Execute "06 CURL read.bat".
4.1. The consumer-service server switches to the next available producer-service server.
4.2. For the absent producer-service there is a response "fallback" from the Resilience4J fallback method.
Console log from the consumer-service with the responses: normal and fallback.