CN114900467A - API flow control method and device - Google Patents

API flow control method and device Download PDF

Info

Publication number
CN114900467A
CN114900467A CN202210509522.9A CN202210509522A CN114900467A CN 114900467 A CN114900467 A CN 114900467A CN 202210509522 A CN202210509522 A CN 202210509522A CN 114900467 A CN114900467 A CN 114900467A
Authority
CN
China
Prior art keywords
current limiting
user request
current
limit
rule
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210509522.9A
Other languages
Chinese (zh)
Inventor
葛玉琦
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ronghui Jinke Financial Service Outsourcing Beijing Co ltd
Original Assignee
Ronghui Jinke Financial Service Outsourcing Beijing Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ronghui Jinke Financial Service Outsourcing Beijing Co ltd filed Critical Ronghui Jinke Financial Service Outsourcing Beijing Co ltd
Priority to CN202210509522.9A priority Critical patent/CN114900467A/en
Publication of CN114900467A publication Critical patent/CN114900467A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/10Flow control; Congestion control
    • H04L47/12Avoiding congestion; Recovering from congestion

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The invention relates to a method and a device for controlling API flow, wherein the method comprises the steps of receiving a user request of a client through a WEB server; the user request comprises a client ID and a product ID; determining a current limiting key according to the user request, performing increment operation on the current limiting key, and returning an incremented numerical value; and inquiring a current limiting rule corresponding to the user request in a mysql database, comparing the increased numerical value with a current limiting threshold value in the current limiting rule, and determining whether to limit current according to a comparison result. The mysql database and the redis database are combined, the dynamic current limiting rule is added, and multi-granularity current limiting control can be realized.

Description

API flow control method and device
Technical Field
The invention belongs to the technical field of computers, and particularly relates to an API flow control method and device.
Background
The current most of the current-limiting scenes in the market use the Filter current limiting based on springclosed-gateway, with the continuous individuation of service requirements, more requirements are born continuously, and the conventional current-limiting rule can not meet the requirements and more multi-dimensional requirements; therefore, the technical implementation of fine-grained current-limiting specifications becomes an important index in software development.
In the related art, the current limiting method cannot refine the request distinguishing strength.
Disclosure of Invention
In view of the above, the present invention provides an API flow control method and apparatus to overcome the deficiencies in the prior art, so as to solve the problem that the current limiting manner in the prior art cannot finely distinguish the request strength.
In order to achieve the purpose, the invention adopts the following technical scheme: an API flow control method comprises the following steps:
receiving a user request of a client through a WEB server; the user request comprises a client ID and a product ID;
determining a current limiting key according to the user request, performing incremental operation on the current limiting key through a redis database, and returning an incremented numerical value;
and inquiring a current limiting rule corresponding to the user request in a mysql database, comparing the increased numerical value with a current limiting threshold value in the current limiting rule, and determining whether to limit current according to a comparison result.
Further, when a user requests a plurality of current limiting rules; the inquiring about the current limiting rule corresponding to the user request in the mysql database, and comparing the incremented value with the current limiting threshold value in the current limiting rule include:
and comparing the increased numerical values with the current limiting threshold values in a plurality of current limiting rules one by one until the last one.
Further, the determining whether to limit the current according to the comparison result includes:
if the increased numerical value is smaller than the current limiting threshold value, continuing to access;
and if the incremented data is greater than or equal to the current limit threshold, the access is refused, namely, the current limit is triggered.
Further, the method also comprises the following steps:
configuring a current limiting rule through a background server and storing the current limiting rule into a mysql database; wherein the flow limit rules include flow limit granularity including second flow limit and/or minute flow limit and/or hour flow limit and/or day flow limit and/or month flow limit.
Further, the current limiting rule is a map type of java.
Further, the current limiting key adopts a key-value data format of redis.
Further, the method also comprises the following steps:
and checking and updating the current limiting rule in the mysql database in real time.
An embodiment of the present application provides an API flow control device, including:
the receiving module is used for receiving a user request of a client through a WEB server; the user request comprises a client ID and a product ID;
the increasing module is used for determining a current limiting key according to the user request, performing increasing operation on the current limiting key and returning an increased numerical value;
and the comparison module is used for inquiring the current limiting rule corresponding to the user request in the mysql database, comparing the increased numerical value with the current limiting threshold value in the current limiting rule, and determining whether to limit the current according to the comparison result.
By adopting the technical scheme, the invention can achieve the following beneficial effects:
the invention provides a method and a device for controlling API flow, which comprises the steps of receiving a user request of a client through a WEB server; the user request comprises a client ID and a product ID; determining a current limiting key according to the user request, performing incremental operation on the current limiting key, and returning an incrementally increased numerical value; and inquiring a current limiting rule corresponding to the user request in a mysql database, comparing the increased numerical value with a current limiting threshold value in the current limiting rule, and determining whether to limit current according to a comparison result. According to the technical scheme, the mysql database and the redis database are combined, the dynamic current limiting rule is added, and multi-granularity current limiting control can be achieved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a schematic diagram illustrating the steps of an API flow control method according to the present invention;
FIG. 2 is a schematic diagram of the structure of an API flow control device of the present invention;
fig. 3 is a schematic diagram of a hardware environment implemented by the API flow control method of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the technical solutions of the present invention will be described in detail below. It should be apparent that the described embodiments are only some embodiments of the present invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the examples given herein without any inventive step, are within the scope of the present invention.
A specific API flow control method and apparatus provided in the embodiments of the present application are described below with reference to the accompanying drawings.
Current limiting is a request for a certain time, if an expected threshold is exceeded, the current limiting system limits its access to the service system, for example: the A organization requests the B product not to exceed 10 times in 1 minute, and the A organization does not allow the continued access when the A organization exceeds 10 times.
As shown in fig. 1, an API flow control method provided in this embodiment includes:
s101, receiving a user request of a client through a WEB server; the user request comprises a client ID and a product ID;
it can be understood that the technical scheme provided by the application can be applied to a current limiting system, a client sends a user request to a WEB server, the client can be an organization, the user request can include an organization ID and a product ID, and the WEB server sends the user request to the current limiting system.
S102, determining a current limit key according to the user request, performing incremental operation on the current limit key through a redis database, and returning an incremented numerical value;
after the current limiting system receives the user request through the WEB server, the current limiting key may be determined according to the user request, and it should be noted that, for the current limiting requests of different time dimensions, there may be different current limiting keys, for example, one key per second if the current limiting is at the level of seconds, or one key per minute if the current limiting is at the level of minutes. And if the current limiting key value cached in the current limiting system is 1, the redis database performs incr operation on the current limiting key and returns a numerical value.
S103, inquiring a current limiting rule corresponding to the user request in the mysql database, comparing the increased numerical value with a current limiting threshold value in the current limiting rule, and determining whether to limit current according to a comparison result.
And inquiring corresponding current limiting rules according to the client ID and the product ID, wherein the current limiting rules comprise a current limiting threshold value, comparing a numerical value returned after incr operation is carried out on the current limiting key by the redis database with the current limiting threshold value, and judging whether current limiting is carried out or not according to a comparison result.
In some embodiments, when the user requests a plurality of current limiting rules; the inquiring about the current limiting rule corresponding to the user request in the mysql database, and comparing the incremented value with the current limiting threshold value in the current limiting rule include:
and comparing the increased numerical values with the current limiting threshold values in a plurality of current limiting rules one by one until the last one.
It is understood that if the current limiting rule includes a plurality of current limiting rules, the current limiting threshold value in each current limiting rule is different, for example, the current limiting rule may have a second level and a minute level, and the incremented value needs to be compared with each current limiting threshold value, and the comparison result is integrated to obtain the result of whether to limit the current.
In some embodiments, the determining whether to limit the current according to the comparison result includes:
if the increased numerical value is smaller than the current limiting threshold value, continuing to access;
and if the incremented data is larger than or equal to the current limiting threshold value, the access is refused, namely, the current limiting is triggered.
As a specific embodiment, after the request, the value returned according to the incr operation of the redis is judged, if the value after incr is larger than the threshold value, the current limiting is triggered, the access is refused, for example, the mechanism a requests the product B, the maximum limit per minute is 9 times, the mechanism a requests the product B for 10 times within one minute, the first redis database returns the value 1, 1 to the incr operation of the current limiting key, less than 9, the access is released continuously, the tenth redisKey returns the value 10, if the value is larger than 9, the access is refused, that is, the current limiting is carried out, and if a plurality of current limiting rules exist, the judgment is carried out for a plurality of times (when the current limiting rules exist at both the second level and the minute level).
In some embodiments, further comprising:
configuring a current limiting rule through a background server and storing the current limiting rule into a mysql database; wherein the flow limit rules include flow limit granularity including second flow limit and/or minute flow limit and/or hour flow limit and/or day flow limit and/or month flow limit.
This application reaches through mysql + redis's combination, mysql database is saved and is preserved the configuration operation, the configuration can be saved, and in time take effect, reids database can high efficiency read the use configuration, make the scalability of current-limiting higher, reach the control of fine grit through standardizing specific income to participate in and code control, reach can self-defining current-limiting unit through encapsulating the code, the technical scheme that this application provided supports the current-limiting of grit such as second, minute, hour, day, month, it is visual and the editable of configuration to assist the backstage management interface to reach, make the operator who does not understand the code also can be smooth adjust according to the demand.
Preferably, the current limiting rule is a map type of java.
As a preferred embodiment, the method further comprises:
and checking and updating the current limiting rule in the mysql database in real time.
In particular the addition or modification of current limiting rules.
The operation operator adds a current limiting rule to the background server and stores the current limiting rule to the mysql database, the current limiting system caches data in the mysql to the memory, and then the current limiting rule is judged according to information in the memory, and the type of the current limiting rule and the threshold are determined.
In the application, the single mechanism flow limiting rule key is mechanism id, and the value of the mechanism id is a flow limiting value containing second, minute, hour and day dimensions
The current limiting rule key of a single mechanism and a product is the mechanism ID-product ID, and the value of the current limiting rule key is the same as the value map of the current limiting rule key of the single mechanism, as shown in Table 1
Figure BDA0003638750580000051
Figure BDA0003638750580000061
TABLE 1 particle size limitation
Preferably, the current limit key uses a key-value data format of redis,
the method specifically comprises the following steps: the single mechanism current limit key is limit, instruction, mechanism id, current limit time string;
the current limiting key of the single mechanism + product is finite, i.e. limit, inst-prod, mechanism id, product id, current limiting time string;
the system current limit key is fintel limit, sys: $ { current limit time string }.
The current limit time string rule is shown in table 2;
Figure BDA0003638750580000062
TABLE 2 Current limiting time series rule
As shown in fig. 2, an API flow control device according to an embodiment of the present application is characterized in that a redis database is applied, and includes:
a receiving module 201, configured to receive a user request of a client through a WEB server; the user request comprises a client ID and a product ID;
the increment module 202 is used for determining a current limit key according to the user request, carrying out increment operation on the current limit key and returning an incremented numerical value;
and the comparison module 203 is configured to query a current limiting rule corresponding to the user request in the mysql database, compare the incremented value with a current limiting threshold in the current limiting rule, and determine whether to limit current according to a comparison result.
The API flow control apparatus provided in the present application operates on the principle that the receiving module 201 receives a user request from a client through a WEB server; the user request comprises a client ID and a product ID; the increasing module 202 determines a current limiting key according to the user request, performs increasing operation on the current limiting key, and returns a value after increasing; the comparison module 203 queries the current limiting rule corresponding to the user request in the mysql database, compares the incremented value with the current limiting threshold value in the current limiting rule, and determines whether to limit current according to the comparison result.
The present application provides a computer device comprising: memory, which may include volatile memory on a computer-readable medium, Random Access Memory (RAM), and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM), and a network interface. The computer device stores an operating system, and the memory is an example of a computer-readable medium. The computer program, when executed by the processor, causes the processor to perform an API flow control method, the structure shown in fig. 3 being a block diagram of only a portion of the structure associated with the present application and not constituting a limitation on the computer apparatus to which the present application applies, a particular computer apparatus may include more or less components than shown in the figure, or combine certain components, or have a different arrangement of components.
In one embodiment, the API flow control method provided by the present application may be implemented in a form of a computer program, and the computer program may be run on a computer device as shown in fig. 3.
In some embodiments, the computer program, when executed by the processor, causes the processor to perform the steps of: receiving a user request of a client through a WEB server; the user request comprises a client ID and a product ID; determining a current limiting key according to the user request, performing incremental operation on the current limiting key through a redis database, and returning an incremented numerical value; and inquiring a current limiting rule corresponding to the user request in a mysql database, comparing the increased numerical value with a current limiting threshold value in the current limiting rule, and determining whether to limit current according to a comparison result.
The present application also provides a computer storage medium, examples of which include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassette storage or other magnetic storage devices, or any other non-transmission medium, that can be used to store information that can be accessed by a computing device.
In some embodiments, the present invention further provides a computer-readable storage medium storing a computer program, which when executed by a processor, receives a user request from a client through a WEB server; the user request comprises a client ID and a product ID; determining a current limiting key according to the user request, performing incremental operation on the current limiting key through a redis database, and returning an incremented numerical value; and inquiring a current limiting rule corresponding to the user request in a mysql database, comparing the increased numerical value with a current limiting threshold value in the current limiting rule, and determining whether to limit current according to a comparison result.
In summary, the present invention provides a method and an apparatus for API traffic control, including receiving a user request of a client through a WEB server; the user request comprises a client ID and a product ID; determining a current limiting key according to the user request, performing increment operation on the current limiting key, and returning an incremented numerical value; and inquiring a current limiting rule corresponding to the user request in a mysql database, comparing the increased numerical value with a current limiting threshold value in the current limiting rule, and determining whether to limit current according to a comparison result. According to the technical scheme, the mysql database and the redis database are combined, the dynamic current limiting rule is added, and multi-granularity current limiting control can be achieved.
It is to be understood that the embodiments of the method provided above correspond to the embodiments of the apparatus described above, and the corresponding specific contents may be referred to each other, which is not described herein again.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.

Claims (8)

1. An API flow control method, comprising:
receiving a user request of a client through a WEB server; the user request comprises a client ID and a product ID;
determining a current limiting key according to the user request, performing incremental operation on the current limiting key through a redis database, and returning an incremented numerical value;
and inquiring a current limiting rule corresponding to the user request in a mysql database, comparing the increased numerical value with a current limiting threshold value in the current limiting rule, and determining whether to limit current according to a comparison result.
2. The method of claim 1, wherein when a plurality of current limiting rules are requested by a user; the querying of the current limiting rule corresponding to the user request in the mysql database and the comparison of the incremented value with the current limiting threshold value in the current limiting rule comprise:
and comparing the increased numerical values with the current limiting threshold values in a plurality of current limiting rules one by one until the last one.
3. The method of claim 1, wherein determining whether to limit current based on the comparison comprises:
if the increased numerical value is smaller than the current limiting threshold value, continuing to access;
and if the incremented data is larger than or equal to the current limiting threshold value, the access is refused, namely, the current limiting is triggered.
4. The method of claim 1, further comprising:
configuring a current limiting rule through a background server and storing the current limiting rule into a mysql database; wherein the flow limit rules include flow limit granularity including second flow limit and/or minute flow limit and/or hour flow limit and/or day flow limit and/or month flow limit.
5. The method of claim 1,
the current limiting rule is a map type of java.
6. The method of claim 1,
the current limiting key adopts a key-value data format of redis.
7. The method of claim 6, further comprising:
and checking and updating the current limiting rule in the mysql database in real time.
8. An API flow control device, wherein a redis database is applied, comprising:
the receiving module is used for receiving a user request of a client through a WEB server; the user request comprises a client ID and a product ID;
the increment module is used for determining a current limit key according to the user request, carrying out increment operation on the current limit key and returning an incremented numerical value;
and the comparison module is used for inquiring the current limiting rule corresponding to the user request in the mysql database, comparing the increased numerical value with the current limiting threshold value in the current limiting rule, and determining whether to limit the current according to the comparison result.
CN202210509522.9A 2022-05-11 2022-05-11 API flow control method and device Pending CN114900467A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210509522.9A CN114900467A (en) 2022-05-11 2022-05-11 API flow control method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210509522.9A CN114900467A (en) 2022-05-11 2022-05-11 API flow control method and device

Publications (1)

Publication Number Publication Date
CN114900467A true CN114900467A (en) 2022-08-12

Family

ID=82722389

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210509522.9A Pending CN114900467A (en) 2022-05-11 2022-05-11 API flow control method and device

Country Status (1)

Country Link
CN (1) CN114900467A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017041666A1 (en) * 2015-09-11 2017-03-16 阿里巴巴集团控股有限公司 Processing method and device directed at access request
CN110276182A (en) * 2019-06-10 2019-09-24 必成汇(成都)科技有限公司 The implementation method of API distribution current limliting
CN110417671A (en) * 2019-07-31 2019-11-05 中国工商银行股份有限公司 The current-limiting method and server of data transmission
CN114257550A (en) * 2021-12-31 2022-03-29 广州零世纪信息科技有限公司 Automatic control method and device for interface access flow, storage medium and server

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017041666A1 (en) * 2015-09-11 2017-03-16 阿里巴巴集团控股有限公司 Processing method and device directed at access request
CN110276182A (en) * 2019-06-10 2019-09-24 必成汇(成都)科技有限公司 The implementation method of API distribution current limliting
CN110417671A (en) * 2019-07-31 2019-11-05 中国工商银行股份有限公司 The current-limiting method and server of data transmission
CN114257550A (en) * 2021-12-31 2022-03-29 广州零世纪信息科技有限公司 Automatic control method and device for interface access flow, storage medium and server

Similar Documents

Publication Publication Date Title
US11409900B2 (en) Processing event messages for data objects in a message queue to determine data to redact
CN108427886B (en) Method, system, device and readable medium for setting access authority of application program
US20230306135A1 (en) Masking sensitive information in records of filtered accesses to unstructured data
EP3490193B1 (en) Terminal rule engine device and terminal rule operation method
Zhang et al. CHARM: A cost-efficient multi-cloud data hosting scheme with high availability
US20120136850A1 (en) Memory usage query governor
US20110040792A1 (en) Stored Object Replication
US7636736B1 (en) Method and apparatus for creating and using a policy-based access/change log
US8583608B2 (en) Maximum allowable runtime query governor
US11194815B1 (en) Constrained query execution
US11029891B2 (en) Hybrid distributed storage system to dynamically modify storage overhead and improve access performance
US8935481B2 (en) Apparatus system and method for providing raw data in a level-two cache
US10664508B1 (en) Server-side filtering of unstructured data items at object storage services
CN111737168A (en) Cache system, cache processing method, device, equipment and medium
AU2001236686A1 (en) Selectively auditing accesses to rows within a relational database at a database server
WO2001082118A2 (en) Selectively auditing accesses to rows within a relational database at a database server
US20200134062A1 (en) Determining a storage pool to store changed data objects indicated in a database
US20090228526A1 (en) Apparatus for managing attribute information on system resources
US20200159771A1 (en) Processing event messages for data objects to determine data to redact from a database
US20220150065A1 (en) Determining facet values for sensitive information in a data object to determine an encryption technique to encrypt the data object for backup
CN111770150B (en) Access flow control method and device and electronic equipment
CN114900467A (en) API flow control method and device
CN110659296A (en) Storage method, device, equipment and computer readable medium
US11468417B2 (en) Aggregated storage file service
US9063773B2 (en) Automatic parallelism tuning for apply processes

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination