API request processing methods, devices, systems, electronic devices, and media
By introducing a distributed memory grid and custom processors into the distributed service cluster, the deployment complexity and data consistency issues of the existing API registration method are resolved, simplifying deployment and scaling, and improving the system's reliability and scalability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN QIANHAI HUANRONG LIANYI INFORMATION TECHNOLOGY SERVICES CO LTD
- Filing Date
- 2023-06-30
- Publication Date
- 2026-05-26
AI Technical Summary
Existing API registration methods suffer from problems such as complex system deployment, reliance on external dependencies and cumbersome configuration, data inconsistency in distributed environments, and the need for downtime when scaling up nodes.
Add a distributed memory grid to the distributed service cluster, implement the mapping relationship of API requests through custom processors, and use reflection mechanism to establish the mapping between API requests and processing scripts, avoiding the dynamic registration process, simplifying deployment and solving data consistency problems.
It enables simple deployment and expansion of distributed service clusters, avoids distributed consistency issues, and improves the reliability and scalability of the system.
Smart Images

Figure CN117014517B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically to a method, apparatus, electronic device, and readable storage medium for processing API requests. Background Technology
[0002] In the Spring framework, requests are typically mapped to corresponding handler functions using the @RequestMapping annotation. The principle is to store the mapping between methods and paths within RequestMappingHandlerMapping, and retrieve the corresponding handler method through this mapping path each time a request is made.
[0003] The existing API registration scheme simply removes the process of statically writing the @RequestMapping annotation. What remains unchanged is that for each registered API, a new mapping is dynamically registered with RequestMappingHandlerMapping.
[0004] Existing API registration methods have many shortcomings, such as complex system deployment, the need to introduce other external dependencies, and cumbersome configuration; currently, API registration relies on mapping, which is stored in a local cache, and can easily cause data inconsistency issues in a distributed environment; node expansion requires downtime, causing business interruption, etc. Summary of the Invention
[0005] To address the aforementioned issues, embodiments of this application provide a method, apparatus, system, electronic device, and medium for processing API requests, thereby overcoming, at least partially, the shortcomings of the prior art.
[0006] In a first aspect, embodiments of this application provide an API request processing method, which is applied to a distributed service cluster, the distributed service cluster including multiple service nodes and a database, and a distributed memory grid is added to the distributed service cluster, each of the service nodes being connected to the database and the distributed memory grid, and the database being connected to the distributed memory grid;
[0007] The method is applied to any of the service nodes, and the method includes:
[0008] Multiple custom processors pre-built in the database are loaded into the distributed memory grid, wherein each custom processor has a first mapping relationship with the API request, and a second mapping relationship between the API request and the corresponding processing method is established in the custom processor based on the reflection mechanism;
[0009] Receive an API request and route the API request to the corresponding target custom processor according to the first mapping relationship, so that the target custom processor determines the target processing script corresponding to the API request according to the second mapping relationship;
[0010] The target processing script is invoked to process the API request.
[0011] Secondly, embodiments of this application also provide an API request processing method apparatus, the apparatus comprising:
[0012] A loading unit is used to load multiple custom processors pre-built in the database into the distributed memory grid, wherein each custom processor has a first mapping relationship with the API request, and a second mapping relationship between the API request and the corresponding processing method is established in the custom processor based on a reflection mechanism;
[0013] A routing unit is used to receive API requests and route the API requests to the corresponding target custom processors according to the first mapping relationship, so that the target custom processors determine the target processing scripts corresponding to the API requests according to the second mapping relationship.
[0014] The processing unit is used to call the target processing script to process the API request.
[0015] Thirdly, this application also provides a request processing system, which includes: a front-end application based on HTTP protocol communication and a distributed service cluster. The distributed service cluster includes multiple service nodes and a database, and a distributed memory grid is added to the distributed service cluster. Each service node is connected to the database and the distributed memory grid, and the database is connected to the distributed memory grid. Each service node is equipped with the above-mentioned API request processing method apparatus. When the distributed service cluster starts, any few of the multiple service nodes form a distributed server, which includes a master node and at least one slave node.
[0016] The front-end application sends API requests to the distributed service cluster and receives the processing results returned by the distributed service cluster;
[0017] The database is used to store multiple pre-built custom processors, wherein each custom processor has a first mapping relationship with the API request, and a second mapping relationship between the API request and the processing script is established in the custom processor based on the reflection mechanism;
[0018] The distributed memory grid is used to cache multiple custom processors loaded from the database.
[0019] Fourthly, embodiments of this application also provide an electronic device, including: a processor; and a memory arranged to store computer-executable instructions, which, when executed, cause the processor to perform the above-described API request processing method.
[0020] Fifthly, embodiments of this application also provide a computer-readable storage medium that stores one or more programs, which, when executed by an electronic device including multiple applications, cause the electronic device to perform the API request processing method described above.
[0021] The above-described technical solutions adopted in the embodiments of this application can achieve the following beneficial effects:
[0022] This application designs a distributed service cluster. Compared with existing distributed service clusters, in addition to multiple service nodes and a database, a distributed memory grid is added. Each service node is connected to both the database and the distributed memory grid. The distributed memory grid provides caching services for the distributed service cluster. Users can register API interfaces through custom processors. During definition, a first mapping relationship is established between different API requests and different custom processors. Then, within the custom processor, a second mapping relationship is established between the API request and a pre-written processing script based on reflection. The custom processors are stored in the database. Custom processors can be considered as custom routing rules. When processing API requests, the custom processors stored in the database are loaded into the distributed memory grid. When an API request arrives in the distributed service cluster, it is routed to any service node. The service node, based on the first mapping relationship, first routes the API request to the corresponding target custom processor. Then, the target custom processor, based on the second mapping relationship, queries the target processing script corresponding to the API request through addressing. Finally, it calls the target processing script to process the API request and return the result. This application improves the API registration method by defining a custom processor, avoiding the process of dynamically registering new mappings with RequestMappingHandlerMapping. Furthermore, the distributed service cluster deployed in this application is simple to deploy, easy to expand, and avoids the problem of distributed consistency from the root. Attached Figure Description
[0023] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0024] Figure 1 A schematic diagram of the structure of a request processing system according to an embodiment of this application is shown;
[0025] Figure 2 A flowchart illustrating an API request processing method according to an embodiment of this application is shown;
[0026] Figure 3 A schematic diagram of the structure of a custom processor according to an embodiment of this application is shown;
[0027] Figure 4 A schematic diagram of the structure of an API request processing apparatus according to an embodiment of this application is shown;
[0028] Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Detailed Implementation
[0029] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0030] The technical solutions provided by the various embodiments of this application are described in detail below with reference to the accompanying drawings.
[0031] Existing API registration methods have several shortcomings: First, deployment issues: existing cluster systems are complex to deploy, requiring the introduction of external dependencies, such as Redis, and different distributed service nodes require different configurations, making deployment cumbersome and complex. Second, distribution issues: existing API registration relies on RequestMappingHandlerMapping, but this mapping is stored in a local cache, which can easily cause data inconsistency in a distributed environment. For example, an API request that can be processed normally on node A may find that there is no corresponding processing method for the API request when it is routed to node B. Third, scaling issues: current cluster systems require downtime for node scaling, making dynamic horizontal scaling impossible.
[0032] In response, this application provides a method for processing API requests, which can be implemented through a request processing system. Figure 1 A schematic diagram of the structure of a request processing system according to an embodiment of this application is shown. Figure 1 As can be seen, the request processing system 100 includes a front-end application 110 and a distributed service cluster 120 that communicate based on the HTTP protocol. The front-end application 110 can be any client, such as an APP application, a web client, etc., and it communicates with the distributed service cluster 120 based on the HTTP protocol. In this application, the user can initiate access to the API interface from the front-end application 110 (such as an HTTP address) to the distributed service cluster 120. In this application, the request to access the API interface sent by the front-end application 110 to the distributed service cluster 120 based on the HTTP protocol is called an API request.
[0033] The distributed service cluster 120 includes multiple service nodes 121 and a database 122, with each service node 121 connected to the database 122. In addition, this application adds a distributed memory grid 123 to the distributed service cluster 120, with each service node 121 connected to the distributed memory grid 123, and the database 122 connected to the distributed memory grid 123. The main function of the distributed memory grid 123 is to provide caching services for the distributed service cluster 120.
[0034] Each service node 121 is equipped with an API request processing method apparatus 400 that can implement the API request processing method of this application. Figure 4 When the distributed service cluster 120 starts, any few of the multiple service nodes will elect a master to form a distributed server. The distributed server usually includes a master node and at least one slave node.
[0035] The distributed service cluster of this application can be built based on any distributed architecture in the prior art. In some embodiments of this application, the distributed service cluster is built based on the Spring framework. Spring is an open-source lightweight framework that provides a comprehensive programming and configuration model and is often used to build modern Java-based enterprise applications.
[0036] Figure 2 This illustration shows a flowchart of an API request processing method according to an embodiment of this application. Figure 2 It can be seen that this application includes at least steps S210 to S230:
[0037] Step S210: Load multiple pre-built custom processors from the database into the distributed memory grid, wherein each custom processor has a first mapping relationship with the API request, and a second mapping relationship between the API request and the corresponding processing method is established in the custom processor based on the reflection mechanism.
[0038] The API request processing method of this application can be applied to any of the service nodes. When the distributed service cluster 120 starts, any few of the multiple service nodes will elect a master to form a distributed server. Each time the API request processing method of this application is executed, it is usually executed by the master node generated through the master election.
[0039] The database stores user-built custom processors, whose main function is to define routing rules. Specifically, in some embodiments of this application, the custom processor is constructed using the following method: In the lookupHandlerMethod function, a second mapping relationship is established between the API request and the corresponding processing method based on the API request method and path; the lookupHandlerMethod function is encapsulated using the HandlerMethod function to obtain the custom processor, and a first mapping relationship is established between the API request and the corresponding custom processor based on the API request method and path.
[0040] The custom handler in this application implements routing rules by inheriting from RequestMappingHandlerMapping. The idea is to override the lookupHandlerMethod method of the class, firstly by creating a lookupHandlerMethod method, and then defining a second mapping relationship between API requests and pre-written processing methods within the newly created lookupHandlerMethod method. That is, the lookupHandlerMethod method defines how to find the processing method of the API request through reflection. Then, the lookupHandlerMethod method is wrapped into a HandlerMethod method, and the wrapped HandlerMethod method is defined as a custom handler. Finally, a first mapping relationship is established between API requests and the corresponding custom handlers. That is, when an API request arrives, the request can be handed over to the custom handler for processing.
[0041] like Figure 3 As shown, Figure 3 A schematic diagram of the structure of a custom processor according to an embodiment of this application is shown. Figure 3As can be seen, the outermost function of a custom processor is HandlerMethod, and a custom processor has a first mapping relationship with an API request (or a class of API requests). The inner function of a custom processor is lookupHandlerMethod, which defines a second mapping relationship between the API request and the corresponding processing method.
[0042] Both the first and second mapping relationships can be established according to the API request method (such as POST, GET) and the path of the processing method (such as / a / b / c). Users can define these themselves when writing custom processors, or they can refer to existing technologies. The processing method can be an existing and publicly available method of the distributed service cluster 120, or it can be written by the user. For example, the user writes an SQL statement, which is concatenated and compiled into an executable script. The SQL statement and the executable script are stored accordingly, thus forming the API request processing method.
[0043] Custom processors are stored in a database. When the distributed service cluster 120 starts, or when the master node among multiple service nodes starts, or when an API request arrives at the distributed service cluster 120, the custom processors stored in the database are loaded into the distributed memory grid 123 of the distributed service cluster 120. The distributed memory grid 123 provides caching services for the distributed service cluster 120 and supports each service node to read and write data in the distributed memory grid 123.
[0044] In some embodiments of this application, the distributed memory grid includes multiple cache nodes; prior to the step of loading multiple custom processors pre-built in the database into the distributed memory grid, the method further includes: when the distributed service cluster starts, the multiple cache nodes of the distributed memory grid form a cache cluster through broadcast or fixed IP address.
[0045] In some embodiments of this application, the distributed memory grid is built on a hazelcast cluster, which includes multiple cache nodes. When the distributed service cluster starts, the multiple cache nodes of the distributed memory grid form a cache cluster through broadcast or fixed IP address.
[0046] A Hazelcast cluster is a distributed system consisting of multiple Hazelcast nodes. Each node can store and process data and work in conjunction with other nodes. Hazelcast clusters provide high availability, high performance, and scalability, enabling applications to handle a large number of concurrent requests.
[0047] A cache cluster can be formed via broadcast or fixed IP. In the case of fixed IP, the first node to start is the master node, and subsequent nodes are automatically found and added to the cluster based on their IP configuration information and managed by the master node.
[0048] To create a Hazelcast cluster using fixed IP addresses, you need to configure the same cluster name and a fixed IP address on each node. Specifically, install and configure Hazelcast on each node, specifying a unique node name and a fixed IP address; start Hazelcast on each node and ensure they are all joined to the same cluster; test the cluster to ensure it functions correctly, including data read / write operations and node failure recovery. Using fixed IP addresses for a Hazelcast cluster provides a more stable and reliable cluster because it is not affected by other devices on the network, but it requires ensuring that each node has a fixed IP address and that these addresses are correctly specified in the configuration file.
[0049] In addition, users who want to register new API interfaces can edit them in the development interface and then store the resulting custom processors in database 122. Database 122 is connected to the distributed memory grid 123. When the custom processors in database 122 are modified or updated, the service node 121 will be aware of it. In response to the user's update operation on the custom processors in database 122, the service node 121 will update the custom processors loaded in the cache cluster.
[0050] Step S220: Receive an API request and route the API request to the corresponding target custom processor according to the first mapping relationship, so that the target custom processor determines the target processing script corresponding to the API request according to the second mapping relationship.
[0051] After the distributed service cluster 120 receives the API request sent by the front-end application, the API request is usually routed to the master node among multiple service nodes 122. The master node reads the custom processor from the distributed memory grid 123, and then queries the corresponding custom processor from multiple custom processors according to the first mapping relationship. The API request is then routed to the custom processor obtained through the query, which is denoted as the target custom processor, and then processed inside the target custom processor.
[0052] Specifically, when an API request is routed to the target custom processor, the target custom processor can find the processing method corresponding to the API request by looking up the second mapping relationship in the lookupHandlerMethod function in its own cache.
[0053] Step S230: Invoke the target processing script to process the API request.
[0054] Finally, the target processing script is invoked to process the API request and return the processing result. Specifically, in some embodiments, the processing method includes an SQL statement and a corresponding executable script; invoking the target processing script to process the API request includes: using the Bindings class to bind pre-set JDBC generic functions to the script's execution environment; in the execution environment, invoking the target processing method, using the SQL statement of the target processing method as a parameter, executing the executable script of the target processing method to process the API request, and returning a List object as the processing result.
[0055] A pre-defined JDBC generic function for database operations is provided. This function takes an SQL statement as a parameter and returns a List collection. Internally, the collection is a HashMap structure where the key is the column name and the value is the value. If no results are found, the collection is empty. Alternatively, this JDBC generic function is used to call an SQL processing script and retrieve the execution result. Specifically, when Java calls a scripting language, Java's Bindings class is used to bind this JDBC generic function to the execution environment of the script. The execution script is the user-written SQL statement. When the SQL statement is written, it is automatically compiled into an executable script. The script content calls the pre-defined function, takes the user-written SQL statement as a parameter, executes the SQL script, and returns the result.
[0056] After receiving the processing result, the distributed service cluster 120 returns the result to the front-end application 110 to complete the processing of the API request.
[0057] Depend on Figure 2As shown in the method, this application designs a distributed service cluster. Compared with existing distributed service clusters, in addition to multiple service nodes and a database, a distributed memory grid is added. Each service node is connected to the database and the distributed memory grid, which provides caching services for the distributed service cluster. Users can register API interfaces through custom processors. During definition, a first mapping relationship is established between different API requests and different custom processors. Then, in the custom processor, a second mapping relationship is established between the API request and a pre-written processing script based on reflection. The custom processors are stored in the database. Custom processors can be regarded as custom routing rules. When processing API requests, the custom processors stored in the database are loaded into the distributed memory grid. When an API request arrives in the distributed service cluster, it is routed to any service node. The service node routes the API request to the corresponding target custom processor according to the first mapping relationship. Then, the target custom processor queries the target processing script corresponding to the API request through addressing according to the second mapping relationship. Finally, the target processing script is called to process the API request and return the result. This application improves the API registration method by defining a custom processor, avoiding the process of dynamically registering new mappings with RequestMappingHandlerMapping. Furthermore, the distributed service cluster deployed in this application is simple to deploy, easy to expand, and avoids the problem of distributed consistency from the root.
[0058] Figure 4 A schematic diagram of the structure of an API request processing apparatus according to an embodiment of this application is shown. Figure 4 As can be seen, the API request processing device 400 includes:
[0059] The loading unit 410 is used to load multiple custom processors pre-built in the database into the distributed memory grid, wherein each custom processor has a first mapping relationship with the API request, and a second mapping relationship between the API request and the corresponding processing method is established in the custom processor based on the reflection mechanism;
[0060] The routing unit 420 is used to receive API requests and route the API requests to the corresponding target custom processors according to the first mapping relationship, so that the target custom processors determine the target processing scripts corresponding to the API requests according to the second mapping relationship.
[0061] The processing unit 430 is used to call the target processing script to process the API request.
[0062] In some embodiments of this application, in the above-described apparatus, the custom processor is constructed by the following method: in the lookupHandlerMethod function, a second mapping relationship between the API request and the corresponding processing method is established according to the API request method and path; the lookupHandlerMethod function is encapsulated using the HandlerMethod function to obtain the custom processor, and a first mapping relationship between the API request and the corresponding custom processor is established according to the API request method and path.
[0063] In some embodiments of this application, in the above-described apparatus, the distributed memory grid includes multiple cache nodes; when the distributed service cluster is started, the multiple cache nodes of the distributed memory grid form a cache cluster through broadcasting or fixed IP addressing.
[0064] In some embodiments of this application, in the above-described apparatus, the loading unit 410 is further configured to update the custom processor loaded in the cache cluster in response to an update operation on the custom processor in the database.
[0065] In some embodiments of this application, in the above-described apparatus, the processing method includes an SQL statement and a corresponding executable script; the processing unit 430 is used to bind a pre-set JDBC generic function to the execution environment of the script using the Bindings class; in the execution environment, the target processing method is called, and the executable script of the target processing method is executed with the SQL statement of the target processing method as a parameter to process the API request and return a List object as the processing result.
[0066] In some embodiments of this application, in the above-described apparatus, the distributed service cluster is built based on the Spring framework, and the distributed memory grid is built based on the Hazelcast cluster.
[0067] It should be noted that the API request processing device described above can implement the aforementioned API request processing methods one by one, which will not be elaborated here.
[0068] Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Please refer to it. Figure 5At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and memory. The memory may include main memory, such as high-speed random-access memory (RAM), or non-volatile memory, such as at least one disk drive. Of course, the electronic device may also include other hardware required for other business operations.
[0069] The processor, network interface, and memory can be interconnected via an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. This bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0070] Memory is used to store programs. Specifically, programs may include program code, which includes computer operation instructions. Memory may include main memory and non-volatile memory, and provides instructions and data to the processor.
[0071] The processor reads the corresponding computer program from non-volatile memory into main memory and then executes it, forming an API request processing device at the logical level. The processor executes the program stored in memory and specifically performs the methods described above.
[0072] The above is as stated in this application. Figure 4The method executed by the API request processing apparatus disclosed in the illustrated embodiments can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module can reside in a mature storage medium in the field, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method.
[0073] The electronic device can also perform Figure 4 The method executed by the API request processing device, and the implementation of the API request processing device in Figure 4 The functions of the embodiments shown are not described in detail here.
[0074] This application also proposes a computer-readable storage medium that stores one or more programs, the programs including instructions that, when executed by an electronic device including multiple applications, enable the electronic device to perform... Figure 4 The method executed by the API request processing device in the illustrated embodiment is specifically used to execute the aforementioned method.
[0075] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0076] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can 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, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0077] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0078] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0079] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0080] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0081] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media 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 technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0082] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0083] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0084] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for processing API requests, characterized in that, The method is applied to a distributed service cluster, which includes multiple service nodes and a database, and a distributed memory grid is added to the distributed service cluster. Each service node is connected to the database and the distributed memory grid, and the database is connected to the distributed memory grid. The method is applied to any of the service nodes, and the method includes: Multiple custom processors pre-built in the database are loaded into the distributed memory grid, wherein each custom processor has a first mapping relationship with the API request, and a second mapping relationship between the API request and the corresponding processing method is established in the custom processor based on the reflection mechanism; Receive an API request and route the API request to the corresponding target custom processor according to the first mapping relationship, so that the target custom processor determines the target processing method corresponding to the API request according to the second mapping relationship; The target processing method is invoked to process the API request.
2. The method according to claim 1, characterized in that, The custom processor was constructed using the following method: In the lookupHandlerMethod function, a second mapping relationship is established between the API request and the corresponding processing method based on the API request method and path; The lookupHandlerMethod function is encapsulated using the HandlerMethod function to obtain a custom processor, and a first mapping relationship between the API request and the corresponding custom processor is established according to the API request method and path.
3. The method according to claim 1, characterized in that, The distributed memory grid includes multiple cache nodes; Prior to the step of loading multiple pre-built custom processors from the database into the distributed memory grid, the method further includes: When the distributed service cluster starts, multiple cache nodes of the distributed memory grid form a cache cluster through broadcasting or fixed IP address.
4. The method according to claim 3, characterized in that, The method further includes: In response to an update operation on a custom processor in the database, the custom processor loaded in the cache cluster is updated.
5. The method according to any one of claims 1 to 4, characterized in that, The processing method includes SQL statements and corresponding executable scripts; The invocation of the target processing method to process the API request includes: The Bindings class is used to bind pre-defined JDBC generic functions to the script's execution environment; In the execution environment, the target processing method is invoked, and the executable script of the target processing method is executed with the SQL statement of the target processing method as a parameter to process the API request and return a List object as the processing result.
6. The method according to any one of claims 1 to 4, characterized in that, The distributed service cluster is built on the Spring framework, and the distributed memory grid is built on the Hazelcast cluster.
7. An API request processing apparatus, characterized in that, The device is applied to a distributed service cluster, which includes multiple service nodes and a database, and a distributed memory grid is added to the distributed service cluster. Each service node is connected to the database and the distributed memory grid, and the database is connected to the distributed memory grid. The device is applied to any of the service nodes, and the device includes: A loading unit is used to load multiple custom processors pre-built in the database into the distributed memory grid, wherein each custom processor has a first mapping relationship with the API request, and a second mapping relationship between the API request and the corresponding processing method is established in the custom processor based on a reflection mechanism; A routing unit is used to receive API requests and route the API requests to the corresponding target custom processors according to the first mapping relationship, so that the target custom processors determine the target processing method corresponding to the API requests according to the second mapping relationship; The processing unit is used to call the target processing method to process the API request.
8. A request processing system, characterized in that, The request processing system includes: a front-end application based on HTTP protocol communication and a distributed service cluster. The distributed service cluster includes multiple service nodes and a database, and a distributed memory grid is added to the distributed service cluster. Each service node is connected to the database and the distributed memory grid, and the database is connected to the distributed memory grid. Each service node is equipped with the API request processing device as described in claim 7. When the distributed service cluster starts, any few of the multiple service nodes form a distributed server, which includes a master node and at least one slave node. The front-end application sends API requests to the distributed service cluster and receives the processing results returned by the distributed service cluster; The database is used to store multiple pre-built custom processors, wherein each custom processor has a first mapping relationship with the API request, and a second mapping relationship between the API request and the processing method is established in the custom processor based on the reflection mechanism; The distributed memory grid is used to cache multiple custom processors loaded from the database.
9. An electronic device, comprising: processor; as well as A memory configured to store computer-executable instructions, which, when executed, cause the processor to perform the processing method for the API request as described in any one of claims 1 to 6.
10. A computer-readable storage medium storing one or more programs, which, when executed by an electronic device including a plurality of applications, cause the electronic device to perform the API request processing method of any one of claims 1 to 6.