Flow control mechanism controls the transmission speed to avoid microservices being overloaded. This guide shows how to use flow control with ServiceComb in the BMI application.
Before you start
Walk through Develop microservice application in minutes and have BMI application running.
Add flow control dependency in
pom.xmlof BMI calculator service:
<dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>handler-flowcontrol-qps</artifactId> </dependency>
Add handler chain and configurations of flow control in
microservice.yamlof BMI calculator service:
servicecomb: handler: chain: Provider: default: qps-flowcontrol-provider flowcontrol: Provider: qps: limit: gateway: 1
The above configurations have already set up in the code. All you need to do is to stop all BMI calculator services and then start a new one with the following command:
mvn spring-boot:run -Drun.jvmArguments="-Dcse.handler.chain.Provider.default=qps-flowcontrol-provider -Dcse.flowcontrol.Provider.qps.limit.gateway=1"
Visit http://localhost:8889. Input a positive height and weight and then click Submit button twice or more in less than one second. You will see the web page change from the left one to the right one.