CloudCurrentLimit implements current limit control under high concurrency based on Lua script of redis, which can greatly reduce the access cost of the system, and limit the current of high concurrency system to protect the system.

out of the box

Introduce maven, configuration files, and a dozen annotations, and integrate current limiting in 1 minute. It really works out of the box.

scenes to be used:

There is no need to start the third-party service independently, and start it together with the project in the form of a jar package. There is no risk of the third-party service hanging up, and the flow of the entire cluster is limited.

If our system has a high-concurrency current-limiting scenario, there may be bugs in temporary writing. To introduce current limiting tools on the market, either the service needs to be started separately, or the configuration is cumbersome. Is there a low-cost and efficient access current-limiting component? ?

It is obvious that CloudCurrentLimit is a good choice for this requirement, and it only needs a simple configuration to achieve the current limiting effect.

The springboot integration version supports 2.2.2.RELEASE<=Version<3.x

The current limit in the cluster state is realized, and the current limit takes effect on the entire cluster

1. Introduce maven dependency


2. Enable current limiting configuration in application.yml

    host: localhost
    database: 0
        max-active: 10
        max-idle: 10
        max-wait: -1ms
      shutdown-timeout: 100ms
    port: 6379
    scan-package: com/example/demoplus/controller  #项目中的controller包
    type: TOKEN #目前算法只支持令牌桶算法,写死TOKEN就行

3. Annotate the Controller class

limitCount = 2, #每秒限流请求次数,默认50
limitMsg = "你被限流了" #支持配置自定义限流提示语句,可不配置,不配置默认提示限流【触发限流了】

give a chestnut

Enter a picture description

4. In this step, the general project has its own global capture exception. You only need to capture RuntimeException. Of course, you can also capture the current-limiting exception class CloudLimitException

public class GlobalExceptionHandler {

    @ExceptionHandler(value = CloudLimitException.class)
    public R handler(CloudLimitException e){
        return R.error(e.getMessage());

If the project starts the limited flow related log output, it means that the current limit takes effect, as shown in the figure below

Enter a picture description

#CloudCurrentLimit #Homepage #Documentation #Download #Current #Limit #Control #Tool #News Fast Delivery

Leave a Comment

Your email address will not be published. Required fields are marked *