Updated on 2024-05-06 GMT+08:00

Rate Limiting

The rate limiting rule is based on Resilience4j and works on the server. The principles are as follows: A maximum of rate requests can be accepted at the interval specified by limitRefreshPeriod. If the number of requests exceeds the value of rate, the traffic is limited and the response code 429 is returned.

  • Rate limiting of Java chassis is used for microservice providers. The rate limiting module must be integrated into microservice applications and the qps-flowcontrol-provider processing chain must be enabled.

    Configuration example:

    servicecomb:
      handler:
        chain:
          Provider:
            default: qps-flowcontrol-provider

    Add the following dependency to the POM file:

    <dependency>
      <groupId>org.apache.servicecomb</groupId>
      <artifactId>handler-flowcontrol-qps</artifactId>
      <version>${project.version}</version>
    </dependency>

    For details, see ServiceComb Rate Limiting Development Guide.

  • Spring Cloud uses Aspect to intercept RequestMappingHandlerAdater to implement rate limiting. After Spring Cloud Huawei is integrated, the rate limiting module spring-cloud-starter-huawei-governance is integrated by default. You only need to enable a specific rate limiting policy.

    Configuration example:

    servicecomb:
      matchGroup:
        AllOperation: |
          matches:
            - apiPath:
                prefix: "/"
      rateLimiting:     
        AllOperation: |      
          rate: 10 # A maximum of 10 requests are allowed in a period of time.