Service management is mainly used to solve or ease avalanche effect of microservices. Abnormal microservices will be isolated and stop cascading failure to reduce unnecessary resource. This guide shows how to use service management with ServiceComb in the BMI application.
Before you start
Walk through Develop microservice application in minutes and have BMI application running.
Add service management dependency in
pom.xmlof BMI calculator service:
<dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>handler-bizkeeper</artifactId> </dependency>
Configure handler chain of service management and fallback strategy:
servicecomb: handler: chain: Provider: default: bizkeeper-provider circuitBreaker: Provider: calculator: requestVolumeThreshold: 3 fallbackpolicy: Provider: policy: returnnull
The above configurations have already set up in the code. All you need to do is to restart the BMI calculator services with the following command:
mvn spring-boot:run -Drun.jvmArguments="-Dcse.handler.chain.Provider.default=bizkeeper-provider -Dcse.circuitBreaker.Provider.calculator.requestVolumeThreshold=3 -Dcse.fallbackpolicy.Provider.policy=returnnull"
Circuit-break microservices. Visit http://localhost:8889, enter a negative height or weight and click the Submit button three times or more continuously. Then the web page should look like the left one in fig-1.
Verify serivces are in circuit-break status. Enter a positive height and weight, then click Submit button. The web page still looks like the left one in fig-1. In the meanwhile, no exceptions show in the log of BMI calculator service. Instead it shows lines contain “fallback called”.
Verify the service back online again. Wait for about 15 seconds, enter a positive height and weight, then click Submit button. You will see the service works fine again like the right one in fig-1.