Application current limiting access manual

Chapter 1              General Introduction

1 Overview

2. Function description

3. Apply current limiting policy

Chapter 2              Business Current Limiting Configuration

1. Description

2. Context management

3. Token pool management

4. Priority queue management

Chapter 3              Application Access

1. Introduce dependencies

2. Spring configuration

3. Business current limiting API

4. Exception handling

 

 

 

 

 

 

 

 

 

 

 

Chapter 1     General Introduction

1 Overview

1.1. Explanation of terms:

name

illustrate

Remark

Server

An independently deployed current-limiting application server provides functions such as priority policy configuration and alarm snapshot reception.

 

client

Provided in the form of jar package to business applications to use the access current limiting function

 

Business Applications

Correspond to specific quick money product applications

 

 

 

 

 

2. Function description

2.1. Current limiting client

  1. 1. Token allocation : The issuance, release, and timeout release of tokens are managed according to the established token capacity and timeout period.                                                                                                                      
  2. 2. Synchronous token priority strategy : The client loads the policy configuration information changes from the server and applies the policy to the corresponding token pool in real time.
  3. Token queuing queue maintenance : Maintain the queuing queue according to the priority policy, including queue insertion according to business priority and kicking out after timeout.
  4. Current limiting parameter service : Provides current limiting parameters through http.
  5. 1. Configuration and maintenance of current limiting parameters.

2.2. Current limiting server

2.3. Website operation and maintenance

 

 

3. Apply current limiting policy

l When allocating tokens, check whether there are idle tokens in the corresponding token pool queue according to the priority of the request. If so, return it; otherwise, return empty.

l After the business processing is completed, the token is released and returned to the token pool of the priority level to which the token belongs.

 

 

 

 

Chapter 2     Business Current Limiting Configuration

1. Description

Select current limiting configuration management in the operation and maintenance monitoring system

 

2. Context management

New, deleted, and modified contexts can be maintained on the current limiting configuration management interface.

 

The context name is any string

When the snapshot sending time is 0, the snapshot is not sent.

The pause button can disable the current limit of the context. At this time, all business requests can pass

Click the context name to enter the token pool interface under the context.

3. Token pool management

Multiple token pools can be configured under one Context

 

The token pool name can be any string

The pause button can disable the current limit of the token pool. At this time, business requests can pass through

Click Modify to modify parameters such as the number of token pools and timeout time.

 

 

Click the token pool name to enter the priority configuration interface under the token pool.

 

4. Priority queue management

 

 

 

 

 

Matching value: It can be an ordinary string or a regular expression, where the regular expression must be enclosed by /, such as /.*/. Other forms are treated as ordinary strings, and multiple matching values ​​are separated by spaces. Except for /.*/, regular expressions should be avoided as much as possible to avoid affecting performance.

Maximum number of concurrent requests: The request token is implemented asynchronously. This parameter specifies the maximum number of tasks in the asynchronous request queue.

 

 

 

 

Chapter 3     Application Access

1. Introduce dependencies

<dependency org="com.99bill" name="if-flowcontrol" rev="1" conf="zip->default"/>

<dependency org="com.sun" name="javaee-api" rev="5" conf="compile->default"/>

<dependency org="com.ibm" name="wsdl4j" rev="1.6.1" conf="compile->default"/>

<dependency org="javax.xml" name="jaxrpc-api" rev="1.1" conf="compile->default"/>

<dependency org="org.slf4j" name="slf4j-api" rev="1.5.8" conf="compile->default"/>

<dependency org="org.spring" name="spring" rev="2.5.5" conf="zip->default"/>      

 

2. Spring configuration

<bean id="tokenPoolManager"

 class="com.bill99.fc.service.token.TokenPoolManagerFactoryBean">

        <property name="contextName" value="myContext" />

        <property name="serverUrl" value="${inf.fc.server.url}" />

 

        <!-- The following parameters are optional-->

        <!-- Maximum timeout for obtaining token, default is 10000 -->

        <property name="tokenGettingTaskTimeOut" value="3000" />

        <!-- Delay time for loading configuration after startup, default is 60000 -->

        <property name="configReloadDelay" value="10000" />

        <!-- The interval for refreshing the configuration, the default is 30000 -->

        <property name="configReloadInterval" value="60000" />

    </bean>      

where myContext is the context name you configured yourself

${inf.fc.server.url} is the server address. If you connect to ACMS, you can directly introduce this placeholder.

3. Business current limiting API

软件包 com.bill99.fc.service.token

类摘要

Token

令牌对象

TokenPoolManager

限流控制主入口

TokenPoolManagerFactoryBean

 

 

com.bill99.fc.service.token 
类 TokenPoolManager

java.lang.Object
 
 
com.bill99.fc.service.token.TokenPoolManager

public class TokenPoolManager
extends java.lang.Object

限流控制主入口

方法摘要

 void

active() 
          激活限流功能

 void

deactive() 
          暂停令牌功能

 Token

getToken(java.lang.String poolName, java.lang.String in) 
          从令牌池中获取令牌

参数:

poolName - 令牌池名称,与服务端配置的令牌池名称对应

in - 业务参数,用于确定优先级

返回:

成功时为Token实例,无可用令牌时返回null

static TokenPoolManager

getTokenPoolManager() 
          获取 TokenPoolManager唯一入口

 boolean

isActive() 
           判断是否激活

 

com.bill99.fc.service.token 
类 Token

java.lang.Object
  
 
com.bill99.fc.service.token.Token

public class Token
extends java.lang.Object

令牌对象

方法摘要

 long

getHeldDuration() 
          获得保持时长

 java.lang.String

getId() 
          获得令牌标识 

 long

getIssueTime() 
           获得颁发时间

 java.lang.String

getPoolName() 
           获得所属令牌池名称

 java.lang.Integer

getPriority() 
           获得优先级

 boolean

isExpired() 
           是否过期

 void

release() 
          释放令牌

 

使用示例:

//…..
//获得令牌
Token t = TokenPoolManager.getTokenPoolManager.getToken(“/internal/txn”,
999451145110001 &PUR”);
//业务处理
//….
//业务处理完毕,归还令牌
t.releaseToken();

 


4.  异常处理

异常情况

处理方式

客户端请求服务端同步策略配置失败

此种场景为客户端首次启动时发生,此时由于客户端无优先策略配置,对于所有请求都按同一优先级进行限流控制。当达到配置的轮询间隔时期后,客户端再次尝试向服务端请求策略配置信息。

 

 

Guess you like

Origin blog.csdn.net/wo240/article/details/47266803