Asynchronous request processing method and apparatus, computer device, and storage medium

By using preset configuration templates and readiness status checks, the target method for handling asynchronous requests can be quickly determined, solving the problem of low processing efficiency in traditional servers and achieving more efficient asynchronous request processing.

CN117009104BActive Publication Date: 2025-11-07CHINA TELECOM CORP LTD TECHNOLOGY INNOVATION CENTER +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310904143.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-21
Publication Date
2025-11-07
Estimated Expiration
2043-07-21

AI Technical Summary

Technical Problem

Traditional servers have low processing efficiency when handling asynchronous requests due to multiple layers of judgment.

Method used

By using a preset configuration template and the ready state of the asynchronous request to be processed, the target method can be quickly determined, the asynchronous request can be processed based on the target method, and the processing result can be sent using the target callback function.

Benefits of technology

It improves the processing efficiency of asynchronous requests, shortens the time for determining the target method, and increases the speed of sending processing results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117009104B_ABST
    Figure CN117009104B_ABST
Patent Text Reader

Abstract

The application relates to an asynchronous request processing method and device, computer equipment, a storage medium and a computer program product. The method comprises the following steps: obtaining a target object corresponding to a to-be-processed asynchronous request and a target callback function; in the case that the to-be-processed asynchronous request is in a ready state, determining a target method corresponding to the to-be-processed asynchronous request based on a preset configuration template and the to-be-processed asynchronous request; processing the to-be-processed asynchronous request based on the target method to obtain a processing result corresponding to the to-be-processed asynchronous request; and sending the processing result to the target object based on the target callback function. The method can improve the processing efficiency of asynchronous requests.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, in particular to an asynchronous request processing method and device, computer equipment, storage medium and computer program product. BACKGROUND

[0002] When the server receives the request sent by the sending end, the request is processed by calling the method corresponding to the request, the processing result corresponding to the request is obtained, and the processing result is sent to the sending end, so as to realize the response of the server to the request.

[0003] In the traditional technology, the server determines the method for processing the request through multi-layer judgment, and the judgment process needs to take a long time, which leads to low processing efficiency of the request. SUMMARY

[0004] Therefore, it is necessary to provide an asynchronous request processing method and device, computer equipment, computer readable storage medium and computer program product, which can improve the asynchronous request processing efficiency.

[0005] In a first aspect, the present application provides an asynchronous request processing method. The method comprises:

[0006] obtaining a target object corresponding to a to-be-processed asynchronous request and a target callback function;

[0007] In the case that the to-be-processed asynchronous request is in a ready state, a target method corresponding to the to-be-processed asynchronous request is determined based on a preset configuration template and the to-be-processed asynchronous request;

[0008] The to-be-processed asynchronous request is processed based on the target method, and a processing result corresponding to the to-be-processed asynchronous request is obtained;

[0009] The processing result is sent to the target object based on the target callback function.

[0010] In one embodiment, the preset configuration template includes a corresponding relationship between a path and a method; and the target method corresponding to the to-be-processed asynchronous request is determined based on the preset configuration template and the to-be-processed asynchronous request, comprising:

[0011] obtaining a target path from a request address of the to-be-processed asynchronous request;

[0012] The method corresponding to the target path in the preset configuration template is determined as the target method corresponding to the to-be-processed asynchronous request.

[0013] In an embodiment, the processing the to-be-processed asynchronous request based on the target method to obtain a processing result corresponding to the to-be-processed asynchronous request comprises:

[0014] obtaining a request parameter set corresponding to the to-be-processed asynchronous request;

[0015] calling the target method to process the request parameter set to obtain the processing result corresponding to the to-be-processed asynchronous request.

[0016] In an embodiment, before the determining the target method corresponding to the to-be-processed asynchronous request based on the preset configuration template and the to-be-processed asynchronous request, the method further comprises:

[0017] establishing and registering a target network connection channel corresponding to the to-be-processed asynchronous request;

[0018] obtaining an event state corresponding to the to-be-processed asynchronous request through the target network connection channel;

[0019] when the event state corresponding to the to-be-processed asynchronous request is a preset event state, determining that the to-be-processed asynchronous request is in a ready state.

[0020] In an embodiment, the establishing and registering the target network connection channel corresponding to the to-be-processed asynchronous request comprises:

[0021] storing the to-be-processed asynchronous request in a waiting queue;

[0022] when the to-be-processed asynchronous request is a head of the waiting queue, generating the target network connection channel corresponding to the to-be-processed asynchronous request;

[0023] registering the target network connection channel on a target listener; the target listener is configured to obtain the event state corresponding to the to-be-processed asynchronous request through the target network connection channel.

[0024] In an embodiment, before the determining the target method corresponding to the to-be-processed asynchronous request based on the preset configuration template and the to-be-processed asynchronous request, the method further comprises:

[0025] determining a target thread corresponding to the to-be-processed asynchronous request;

[0026] storing the to-be-processed asynchronous request in a target queue corresponding to the target thread.

[0027] In an embodiment, the processing the to-be-processed asynchronous request based on the target method to obtain a processing result corresponding to the to-be-processed asynchronous request comprises:

[0028] The target method is called by the target thread, and a request parameter set of the to-be-processed asynchronous request is processed to obtain a processing result corresponding to the to-be-processed asynchronous request.

[0029] In a second aspect, the present application further provides an asynchronous request processing apparatus. The apparatus comprises:

[0030] An obtaining module is configured to obtain a to-be-processed asynchronous request corresponding to a target object and a target callback function;

[0031] A determining module is configured to, in a case where the to-be-processed asynchronous request is in a ready state, determine a target method corresponding to the to-be-processed asynchronous request based on a preset configuration template and the to-be-processed asynchronous request;

[0032] A processing module is configured to process the to-be-processed asynchronous request based on the target method to obtain a processing result corresponding to the to-be-processed asynchronous request;

[0033] A callback module is configured to send the processing result to the target object based on the target callback function.

[0034] In a third aspect, the present application further provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method in any one of the first aspect when executing the computer program.

[0035] In a fourth aspect, the present application further provides a computer readable storage medium, which stores a computer program, and the computer program implements the steps of the method in any one of the first aspect when executed by a processor.

[0036] In a fifth aspect, the present application further provides a computer program product comprising a computer program, and the computer program implements the steps of the method in any one of the first aspect when executed by a processor.

[0037] The aforementioned asynchronous request processing method, apparatus, computer device, storage medium, and computer program product obtain the asynchronous request to be processed and the target callback function corresponding to the target object. When the asynchronous request to be processed is in a ready state, based on a preset configuration template and the asynchronous request to be processed, the target method corresponding to the asynchronous request to be processed is determined. The asynchronous request to be processed is then processed based on the target method to obtain the processing result corresponding to the asynchronous request to be processed. Finally, based on the target callback function, the processing result is sent to the target object. By determining the target method corresponding to the asynchronous request to be processed through the correspondence in the preset configuration template when the asynchronous request to be processed is in a ready state, compared to multi-level judgment, the time for determining the target method is shortened. The target method is called to process the asynchronous request to be processed, and the processing result corresponding to the asynchronous request to be processed is obtained. The processing result is then sent to the target object through the target callback function, thereby improving the processing efficiency of the asynchronous request to be processed. Attached Figure Description

[0038] Figure 1 This is an application environment diagram of an asynchronous request processing method in one embodiment;

[0039] Figure 2 This is a flowchart illustrating an asynchronous request processing method in one embodiment;

[0040] Figure 3 This is a flowchart illustrating the ready state determination step in one embodiment;

[0041] Figure 4 This is a flowchart illustrating the target network connection channel registration steps in one embodiment;

[0042] Figure 5 This is a schematic diagram of an asynchronous request processing system in one embodiment;

[0043] Figure 6 This is a schematic diagram of the injection module in one embodiment;

[0044] Figure 7 This is a structural block diagram of an asynchronous request processing device in one embodiment;

[0045] Figure 8 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0046] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0047] The asynchronous request processing method provided in this application embodiment can be applied to, for example,Figure 1 The application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data required by the server 104 to process. The data storage system can be integrated on the server 104, or placed on the cloud or other network servers. The terminal and the server can be used alone to execute the asynchronous request processing method provided in the embodiments of the application. The terminal and the server can also be used together to execute the asynchronous request processing method provided in the embodiments of the application. For example, the server obtains the target object corresponding to the to-be-processed asynchronous request and the target callback function, and in the case that the to-be-processed asynchronous request is in a ready state, determines the target method corresponding to the to-be-processed asynchronous request based on the preset configuration template and the to-be-processed asynchronous request, processes the to-be-processed asynchronous request based on the target method, obtains the processing result corresponding to the to-be-processed asynchronous request, and sends the processing result to the target object based on the target callback function. Among them, the terminal 102 can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things device can be a smart speaker, a smart TV, a smart air conditioner, a smart vehicle device, etc. The portable wearable device can be a smart watch, a smart bracelet, a head-mounted device, etc. The server 104 can be implemented by an independent server or a server cluster composed of multiple servers.

[0048] In one embodiment, as Figure 2 shown, an asynchronous request processing method is provided, and the embodiment takes the case where the method is applied to a server as an example for illustration, which includes steps 202 to 208.

[0049] Step 202, obtaining the to-be-processed asynchronous request corresponding to the target object and the target callback function.

[0050] Among them, the target object refers to the device that sends the to-be-processed asynchronous request, which can be understood as the sending end of the to-be-processed asynchronous request. The target object can be, but is not limited to, a terminal, a computer device, a server, etc. The asynchronous request refers to an asynchronous request, and the sending and processing of the asynchronous request will not block the thread or process that initiates the request. It can be understood that, compared with the synchronous request, the asynchronous request allows the target object to continue to perform other operations after sending the to-be-processed asynchronous request, without waiting for the completion of the to-be-processed asynchronous request. The callback function refers to the function of sending the to-be-processed asynchronous request to the target object.

[0051] Exemplarily, the target object sends the to-be-processed asynchronous request and the target callback function to the server, and the server receives the to-be-processed asynchronous request and the target callback function.

[0052] Step 204, in the case that the to-be-processed asynchronous request is in a ready state, determining the target method corresponding to the to-be-processed asynchronous request based on the preset configuration template and the to-be-processed asynchronous request.

[0053] The ready state refers to a state when the event state corresponding to the to-be-processed asynchronous request changes, and can be understood as a state in which the to-be-processed asynchronous request is ready to be processed. The ready state includes but is not limited to one of a connection ready state, a readable ready state, a writable ready state, and a receiving ready state. The preset configuration template refers to a pre-set configuration template, and the preset configuration template includes a plurality of sets of correspondence between methods, for example, correspondence between request addresses and methods or correspondence between paths and methods. The method refers to a piece of code in a class or object for executing a specific task, and can be understood as a method defining a series of statements for completing a specific function. The method can be an instance method and a class method. The instance method belongs to an object, and the instance method can be called only after an object of the class is created. The class method belongs to the class itself, and the class method can be directly called through the class name without creating an instance of the class.

[0054] Exemplarily, the server obtains the event state corresponding to the to-be-processed asynchronous request through the registration and listening module, judges the event state corresponding to the to-be-processed asynchronous request, obtains the preset configuration template in the case that the to-be-processed asynchronous request is in the ready state, determines the target method corresponding to the to-be-processed asynchronous request from the preset configuration template, and repeatedly executes the obtaining of the event state corresponding to the to-be-processed asynchronous request and the judging of the event state corresponding to the to-be-processed asynchronous request in the case that the to-be-processed asynchronous request is in the non-ready state until the to-be-processed asynchronous request is in the ready state.

[0055] In step 206, the to-be-processed asynchronous request is processed based on the target method, and a processing result corresponding to the to-be-processed asynchronous request is obtained.

[0056] The processing result refers to a result obtained after the server processes the to-be-processed asynchronous request, and can be a result of calculation, operation, or query, which is determined according to business logic and requirements of the to-be-processed asynchronous request.

[0057] Exemplarily, the server calls the target method to process the to-be-processed asynchronous request, and obtains a processing result corresponding to the to-be-processed asynchronous request.

[0058] In step 208, the processing result is sent to the target object based on the target callback function.

[0059] Exemplarily, after obtaining the processing result of the to-be-processed asynchronous request, the server sends the processing result to the target object through the target callback function.

[0060] In the asynchronous request processing method, the target object corresponding to the to-be-processed asynchronous request and the target callback function are obtained, in the case that the to-be-processed asynchronous request is in a ready state, a target method corresponding to the to-be-processed asynchronous request is determined based on a preset configuration template and the to-be-processed asynchronous request, the to-be-processed asynchronous request is processed based on the target method, a processing result corresponding to the to-be-processed asynchronous request is obtained, and the processing result is sent to the target object based on the target callback function. In the case that the to-be-processed asynchronous request is in a ready state, the target method corresponding to the to-be-processed asynchronous request is determined through the corresponding relationship in the preset configuration template, compared with multiple-layer judgment, the time length of determining the target method is shortened, the to-be-processed asynchronous request is processed by calling the target method, the processing result corresponding to the to-be-processed asynchronous request is obtained, and the processing result is sent to the target object through the target callback function, thereby improving the processing efficiency of the to-be-processed asynchronous request.

[0061] In one embodiment, the preset configuration template includes a corresponding relationship between a path and a method; determining the target method corresponding to the to-be-processed asynchronous request based on the preset configuration template and the to-be-processed asynchronous request includes:

[0062] The target path is obtained from the request address of the to-be-processed asynchronous request; and the method corresponding to the target path in the preset configuration template is determined as the target method corresponding to the to-be-processed asynchronous request.

[0063] The request address refers to a complete URL (Uniform Resource Locator, uniform resource locator) used by the target object when initiating the to-be-processed asynchronous request, including protocol, domain name or IP (Internet Protocol, Internet Protocol) address, port number, path and query parameter components, and is used to uniquely identify the location of the target object on the network. The path refers to the part remaining after removing the protocol, domain name, port number and query parameter in the request address, that is, the relative path of the to-be-processed asynchronous request, indicating the resource location of the to-be-processed asynchronous request on the server.

[0064] Exemplarily, the server obtains the request address from the to-be-processed asynchronous request, obtains the target path from the request address, and determines the method corresponding to the target path in the preset configuration template as the target method corresponding to the to-be-processed asynchronous request.

[0065] In one embodiment, the preset configuration template includes a mapping between paths and class methods. The server obtains the request address from the asynchronous request to be processed, obtains the target path from the request address, and determines the class method corresponding to the target path in the preset configuration template as the target class method corresponding to the asynchronous request to be processed. For example, the target class method is controller1 / method1, where controller1 is a class and method1 is a method in controller1.

[0066] In this embodiment, by using the correspondence between paths and methods in the preset configuration template, the target method corresponding to the asynchronous request to be processed is determined based on the target path in the asynchronous request to be processed. Compared with multi-level judgment, the time for determining the target method is shortened, thereby improving the processing efficiency of the asynchronous request to be processed.

[0067] In one embodiment, processing the asynchronous request to be processed based on the target method yields the following processing results:

[0068] Get the set of request parameters corresponding to the asynchronous request to be processed; call the target method to process the set of request parameters and get the processing result of the asynchronous request to be processed.

[0069] The request parameter set refers to a collection of multiple request parameters for an asynchronous request to be processed. The request parameter set includes, but is not limited to, the request address, request headers, and request body. The request header is a set of key-value pairs that conveys additional information about the request, and the request body is the main data used to convey the request's core information.

[0070] For example, after determining the target method corresponding to the asynchronous request to be processed, the server obtains the set of request parameters corresponding to the asynchronous request to be processed, and inputs at least one request parameter in the set of request parameters into the target method as an input parameter according to the actual setting of the input parameters of the target method, runs the target method, and obtains the processing result corresponding to the asynchronous request to be processed.

[0071] In this embodiment, the server calls the target method corresponding to the asynchronous request to be processed, processes the request parameter set, and obtains the processing result corresponding to the asynchronous request to be processed, thus realizing the server's processing of the asynchronous request to be processed.

[0072] In one embodiment, such as Figure 3 As shown, when the asynchronous request to be processed is in a ready state, before determining the target method corresponding to the asynchronous request to be processed based on the preset configuration template and the asynchronous request to be processed, the following steps are also included:

[0073] Step 302: Establish and register the target network connection channel corresponding to the asynchronous request to be processed.

[0074] The network connection channel refers to a channel for network communication, and provides a function of network communication through a TCP (Transmission Control Protocol) protocol. The network connection channel can be a Socket Channel in JAVA.

[0075] For example, the server receives an asynchronous request to be processed, saves the asynchronous request to be processed in a waiting queue, establishes a target network connection channel corresponding to the asynchronous request to be processed when the asynchronous request to be processed is the head of the waiting queue, binds the asynchronous request to be processed and the target network connection channel, and then registers the target network connection channel on a target listener. The target listener allows a thread to simultaneously listen to events on multiple network connection channels, and the thread is notified when any event on the network connection channel changes.

[0076] In step 304, an event state corresponding to the asynchronous request to be processed is obtained through the target network connection channel.

[0077] The event state refers to a state of an I / O (Input / Output) event on the target network connection channel corresponding to the asynchronous request to be processed, and is used to indicate whether the target network connection channel has a condition for an I / O operation at a certain time. The event state includes, but is not limited to, an unconnected state, a connection ready state, an unreadable state, a readable ready state, an unwritable state, a writable ready state, an unaccepted connection state, and a receiving ready state.

[0078] For example, the target listener of the server polls the registered network connection channel, obtains the event state of the target network connection channel, and determines the event state of the target network connection channel as the event state corresponding to the asynchronous request to be processed.

[0079] In one embodiment, the target listener of the server obtains the event state of the target network connection channel based on a preset time interval, and determines the event state of the target network connection channel as the event state corresponding to the asynchronous request to be processed.

[0080] In step 306, when the event state corresponding to the asynchronous request to be processed is a preset event state, it is determined that the asynchronous request to be processed is in a ready state.

[0081] The preset event state refers to a set of event states set in advance, and the preset event state includes a connection ready state, a readable ready state, a writable ready state, and a receiving ready state.

[0082] Exemplarily, the server compares the event state corresponding to the to-be-processed asynchronous request with preset event states, and determines that the to-be-processed asynchronous request is in the ready state when the event state corresponding to the to-be-processed asynchronous request is one of the preset event states.

[0083] In one embodiment, the to-be-processed asynchronous request is determined to be in the ready state when the event state corresponding to the to-be-processed asynchronous request changes, where the change refers to that the event state changes from the unconnected state to the connection ready state, from the unreadable state to the readable ready state, from the unwritable state to the writable ready state, or from the unaccepted connection state to the accepted connection ready state.

[0084] In this embodiment, the server determines the event state corresponding to the to-be-processed asynchronous request according to the event state of the target network connection channel corresponding to the to-be-processed asynchronous request by obtaining the event state of the target network connection channel corresponding to the to-be-processed asynchronous request, determines that the to-be-processed asynchronous request is in the ready state when the event state corresponding to the to-be-processed asynchronous request is a preset event state, and processes the to-be-processed asynchronous request when the to-be-processed asynchronous request is in the ready state, thereby avoiding that the to-be-processed asynchronous request is in the waiting state for a long time, and improving the processing efficiency of the asynchronous request.

[0085] In one embodiment, as shown in FIG. 4, the establishment and registration of the target network connection channel corresponding to the to-be-processed asynchronous request include: Figure 4

[0086] Step 402: storing the to-be-processed asynchronous request in a waiting queue.

[0087] The waiting queue refers to a queue for storing to-be-processed asynchronous requests. The queue is a first-in first-out data structure. It can be understood that the server receives a plurality of to-be-processed asynchronous requests, stores the plurality of to-be-processed asynchronous requests in the waiting queue before processing the to-be-processed asynchronous requests, and then processes the plurality of to-be-processed asynchronous requests in turn according to the arrangement order of the to-be-processed asynchronous requests in the waiting queue. The server can store the to-be-processed asynchronous requests in the waiting queue based on the priority and the receiving time of the to-be-processed asynchronous requests.

[0088] Exemplarily, the server stores the to-be-processed asynchronous request in the waiting queue after receiving the to-be-processed asynchronous request.

[0089] Step 404: generating the target network connection channel corresponding to the to-be-processed asynchronous request when the to-be-processed asynchronous request is the head of the waiting queue.

[0090] The head refers to the first element in the queue.

[0091] ​Exemplarily, the server processes asynchronous requests in the waiting queue in sequence, and when the to-be-processed asynchronous request is the head of the waiting queue, a target network connection channel corresponding to the to-be-processed asynchronous request is generated.

[0092] In step 406, the target network connection channel is registered on a target listener; the target listener is used to obtain an event state corresponding to the to-be-processed asynchronous request through the target network connection channel.

[0093] The target listener is a registration and listening module in the allocation module, and is used to listen to an event state of the registered network connection channel.

[0094] Exemplarily, the server registers the target network connection channel on the target listener.

[0095] In one embodiment, the server obtains the target listener, sets the target network connection channel to a non-blocking mode, calls a register(Selector selector, int interestOps, Object attachment) method of the network connection channel, and registers the target network connection channel on the target listener. The register is a registration method, the Selector is a selector, the selector parameter is the target listener to be registered, the int is an integer data, the interestOps parameter is a registered event type, the Object is a base class of a class in Java, and indicates a type of any object, and the attachment parameter is an optional additional object, which can be used to transmit additional information.

[0096] In this embodiment, by registering the target network connection channel on the target listener, an implementation basis is provided for subsequently determining an event state of the to-be-processed asynchronous request.

[0097] In one embodiment, when the to-be-processed asynchronous request is in the ready state, before determining a target method corresponding to the to-be-processed asynchronous request based on a preset configuration template and the to-be-processed asynchronous request, the method further includes:

[0098] A target thread corresponding to the to-be-processed asynchronous request is determined; and the to-be-processed asynchronous request is saved in a target queue corresponding to the target thread.

[0099] The thread is the smallest unit of operation scheduling of a computer operating system, and is an execution flow in a process, which can be independently run and scheduled. The target queue is a task queue used to save the to-be-processed asynchronous request to be processed by the target thread. It can be understood that the target thread processes the to-be-processed asynchronous request in the target queue.

[0100] Exemplarily, the server determines a target thread corresponding to the asynchronous request to be processed based on a preset allocation manner, and then saves the asynchronous request to be processed in a target queue corresponding to the target thread.

[0101] In one embodiment, the server determines a target thread pool corresponding to the asynchronous request to be processed based on a preset allocation manner, and saves the asynchronous request to be processed in a target queue corresponding to the target thread pool.

[0102] In this embodiment, by determining the target thread corresponding to the asynchronous request to be processed and saving the asynchronous request to be processed in the target queue corresponding to the target thread, it can be understood that the target thread only processes the asynchronous requests in the target queue, thereby shortening the waiting time of the asynchronous request to be processed and improving the processing efficiency of the asynchronous request to be processed.

[0103] In one embodiment, the target method is used to process the asynchronous request to be processed to obtain a processing result corresponding to the asynchronous request to be processed.

[0104] The target method is called by the target thread to process the request parameter set of the asynchronous request to be processed to obtain a processing result corresponding to the asynchronous request to be processed.

[0105] Exemplarily, the server calls the target method by the target thread, inputs the request parameter set of the asynchronous request to be processed into the target method as an input parameter, runs the target method, and obtains a processing result corresponding to the asynchronous request to be processed.

[0106] In this embodiment, the target thread is used to process the asynchronous request to be processed, thereby shortening the waiting time of the asynchronous request to be processed and improving the processing efficiency of the asynchronous request to be processed.

[0107] In one exemplary embodiment, as Figure 5As shown, an asynchronous request processing system is provided, including a bootstrap module, a receiving module, a network communication module, an allocation module, an automatic injection module and an execution module. Among them, the bootstrap module (Server Bootstrap) is used to guide and configure the startup of the server program, which is responsible for setting the basic parameters of the server and managing the entire startup process; the receiving module (Boss Group) is used to receive connection establishment request events, that is, to listen to the server's listening port. When a new connection request arrives, the receiving module will receive and process these requests. It does not directly handle the read-write operations of the request, but allocates connection requests to the allocation module for further processing; the network communication module (Channel) is used for asynchronous network I / O operations; the allocation module (Worker Group) is used to allocate thread processing requests, that is, to process actual read-write operations. When the connection is established, the receiving module will allocate the connection request to the thread in the allocation module for processing; the automatic injection module is used to obtain request parameters and automatically inject them into the execution module; the execution module (Handler) is used to execute specific business logic, such as reading and writing data, encoding and decoding, etc. It obtains the required parameters through the automatic injection module and processes according to the specific business needs.

[0108] The automatic injection module, as shown in Figure 6 As shown, it contains a configuration module, a matching module and an injection module. Among them, the configuration module is used to configure the required parameters of the request class, including request address, request header, request body, etc.; the matching module is used to match the method required by the asynchronous request to be processed; the injection module is used to inject the matched method into the execution module.

[0109] The sending end sends the asynchronous request to be processed and the target callback function to the server. The server receives the asynchronous request to be processed and the target callback function. The receiving module stores the asynchronous request to be processed in the waiting queue. When the asynchronous request to be processed is the head of the waiting queue, the target network connection channel corresponding to the asynchronous request to be processed is generated. The network communication module registers the target network connection channel on the allocation module. The listening and registration module in the allocation module polls the registered network connection channel to obtain the event state of the target network connection channel. The event state of the target network connection channel is determined as the event state corresponding to the asynchronous request to be processed. When the event state corresponding to the asynchronous request to be processed changes, it is determined that the asynchronous request to be processed is in the ready state.

[0110] The allocation module calls the automatic injection module when determining that the asynchronous request to be processed is in a ready state, a configuration module in the automatic injection module obtains a request parameter set corresponding to the asynchronous request to be processed, including a request address, a request header and a request body, obtains a target path from the request address, and a matching module obtains a preset configuration template. A method corresponding to the target path in the preset configuration template is determined as a target method corresponding to the asynchronous request to be processed, and the injection module injects the request parameter set and the target method into the execution module.

[0111] The execution module calls the target method, inputs the request parameter set into the target method as an input parameter, runs the target method, obtains a processing result corresponding to the asynchronous request to be processed, and the execution module transmits the processing result to the network communication module. The network communication module calls the target callback function and sends the processing result to the sending end.

[0112] In the asynchronous request processing method, the target object corresponding to the asynchronous request to be processed and the target callback function are obtained, the target method corresponding to the asynchronous request to be processed is determined based on the preset configuration template and the asynchronous request to be processed in the case that the asynchronous request to be processed is in a ready state, the asynchronous request to be processed is processed based on the target method, the processing result corresponding to the asynchronous request to be processed is obtained, and the processing result is sent to the target object based on the target callback function. In the case that the asynchronous request to be processed is in a ready state, the target method corresponding to the asynchronous request to be processed is determined through the corresponding relationship in the preset configuration template, compared with multiple layer judgments, the time length of determining the target method is shortened, the asynchronous request to be processed is processed by calling the target method, the processing result corresponding to the asynchronous request to be processed is obtained, and the processing result is sent to the target object through the target callback function, thereby improving the processing efficiency of the asynchronous request to be processed.

[0113] It should be understood that, although each step in the flowchart involved in each embodiment as described above is displayed in sequence according to the arrow, these steps are not necessarily executed in sequence according to the arrow. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other sequences. Moreover, at least part of the steps in the flowchart involved in each embodiment as described above can include multiple steps or stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution sequence of these steps or stages is not necessarily sequential, but can be alternately executed with at least part of other steps or steps or stages in other steps.

[0114] Based on the same inventive concept, the embodiments of the present application further provide an asynchronous request processing apparatus for implementing the asynchronous request processing method described above. The apparatus provides a solution to the implementation scheme as described in the method above, and thus the specific limitations in one or more asynchronous request processing apparatus embodiments provided below can refer to the limitations of the asynchronous request processing method described above, which will not be repeated here.

[0115] In one embodiment, as shown in Figure 7 An asynchronous request processing apparatus is provided, comprising: an obtaining module 702, a determining module 704, a processing module 706, and a callback module 708, wherein:

[0116] The obtaining module 702 is configured to obtain a target asynchronous request corresponding to a target object and a target callback function;

[0117] The determining module 704 is configured to, in a case where the target asynchronous request is in a ready state, determine a target method corresponding to the target asynchronous request based on a preset configuration template and the target asynchronous request.

[0118] The processing module 706 is configured to process the target asynchronous request based on the target method to obtain a processing result corresponding to the target asynchronous request.

[0119] The callback module 708 is configured to send the processing result to the target object based on the target callback function.

[0120] In one embodiment, the determining module 704 is further configured to: obtain a target path from a request address of the target asynchronous request; and determine a method corresponding to the target path in the preset configuration template as the target method corresponding to the target asynchronous request.

[0121] In one embodiment, the processing module 706 is further configured to: obtain a request parameter set corresponding to the target asynchronous request; and call the target method to process the request parameter set to obtain the processing result corresponding to the target asynchronous request.

[0122] In one embodiment, the asynchronous request processing apparatus further comprises a monitoring module, which is configured to: establish and register a target network connection channel corresponding to the target asynchronous request; obtain an event state corresponding to the target asynchronous request through the target network connection channel; and determine that the target asynchronous request is in the ready state when the event state corresponding to the target asynchronous request is a preset event state.

[0123] In an embodiment, the monitoring module is further configured to: store the to-be-processed asynchronous request in a waiting queue; generate a target network connection channel corresponding to the to-be-processed asynchronous request when the to-be-processed asynchronous request is a head of the waiting queue; and register the target network connection channel on a target listener, where the target listener is configured to acquire an event state corresponding to the to-be-processed asynchronous request through the target network connection channel.

[0124] In an embodiment, the asynchronous request processing apparatus further includes a storage module configured to: determine a target thread corresponding to the to-be-processed asynchronous request; and save the to-be-processed asynchronous request in a target queue corresponding to the target thread.

[0125] In an embodiment, the processing module 706 is further configured to: call the target method through the target thread, and process the request parameter set of the to-be-processed asynchronous request to obtain a processing result corresponding to the to-be-processed asynchronous request.

[0126] The modules in the asynchronous request processing apparatus described above can be implemented by software, hardware, or a combination thereof, in whole or in part. The modules described above can be embedded in or independent of a processor in a computer device in hardware form, or stored in a memory in a computer device in software form, so as to be called and executed by a processor to perform the operations corresponding to the modules.

[0127] In an embodiment, a computer device is provided, which can be a terminal, and an internal structure diagram of the computer device can be as shown in FIG. 7. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected through a system bus, and the communication interface, the display unit, and the input device are connected to the system bus through the input / output interface. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for running the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is configured to exchange information between the processor and external devices. The communication interface of the computer device is configured to perform wired or wireless communication with external terminals, and the wireless communication can be achieved through WIFI, mobile cellular network, NFC (near field communication), or other technologies. The computer program is executed by the processor to implement an asynchronous request processing method. The display unit of the computer device is configured to form a visually visible picture, which can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer overlaid on the display screen, or a key, trackball, or touchpad arranged on the shell of the computer device, or an external keyboard, touchpad, or mouse, etc. Figure 8 ​

[0128] Those skilled in the art can understand that Figure 8 Those skilled in the art can understand that

[0129] In an embodiment, a computer device is provided, including a memory and a processor, the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.

[0130] In an embodiment, a computer readable storage medium is provided, which stores a computer program, and the computer program is executed by a processor to implement the steps in the above method embodiments.

[0131] In an embodiment, a computer program product is provided, which includes a computer program, and the computer program is executed by a processor to implement the steps in the above method embodiments.

[0132] It should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties.

[0133] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (Read-Only Memory, ROM), magnetic tape, floppy disk, flash memory, optical storage, high-density embedded non-volatile memory, resistive memory (ReRAM), magnetoresistive random access memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric memory (Ferroelectric Random Access Memory, FRAM), phase change memory (Phase Change Memory, PCM), graphene memory, etc. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, etc. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.

[0134] Any combination of the technical features of the above embodiments can be made. In order to make the description simple, all possible combinations of the technical features in the above embodiments are not described, however, as long as the combination of the technical features does not exist contradictory, it should be considered as the scope of the present application.

[0135] The above embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent of the present application. It should be pointed out that for ordinary skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are within the scope of protection of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims

1. An asynchronous request processing method, characterized by, The method comprises: obtaining a target object corresponding to a to-be-processed asynchronous request and a target callback function; establishing and registering a target network connection channel corresponding to the to-be-processed asynchronous request; obtaining an event state corresponding to the to-be-processed asynchronous request through the target network connection channel; when the event state corresponding to the to-be-processed asynchronous request changes, determining that the to-be-processed asynchronous request is in a ready state; the change of the event state refers to that the event state changes from an unconnected state to a connection ready state, from an unreadable state to a readable ready state, from an unwritable state to a writable ready state, or from an unaccepted connection state to a connection ready state; based on a preset configuration template and the to-be-processed asynchronous request, determining a target method corresponding to the to-be-processed asynchronous request when the to-be-processed asynchronous request is in the ready state; processing the to-be-processed asynchronous request based on the target method to obtain a processing result corresponding to the to-be-processed asynchronous request; based on the target callback function, sending the processing result to the target object.

2. The method of claim 1, wherein, The preset configuration template comprises a corresponding relationship between a path and a method; based on a preset configuration template and the to-be-processed asynchronous request, determining a target method corresponding to the to-be-processed asynchronous request comprises: obtaining a target path from a request address of the to-be-processed asynchronous request; determining a method corresponding to the target path in the preset configuration template as the target method corresponding to the to-be-processed asynchronous request.

3. The method of claim 1, wherein, based on the target method, processing the to-be-processed asynchronous request to obtain a processing result corresponding to the to-be-processed asynchronous request comprises: obtaining a request parameter set corresponding to the to-be-processed asynchronous request; calling the target method to process the request parameter set to obtain the processing result corresponding to the to-be-processed asynchronous request.

4. The method of claim 3, wherein, The request parameter set refers to a set composed of multiple request parameters of the to-be-processed asynchronous request, and the request parameter set comprises but is not limited to a request address, a request header, and a request body.

5. The method of claim 1, wherein, The establishment and registration of the target network connection channel corresponding to the to-be-processed asynchronous request comprises: storing the to-be-processed asynchronous request in a waiting queue; generating a target network connection channel corresponding to the to-be-processed asynchronous request when the to-be-processed asynchronous request is at the head of the waiting queue; registering the target network connection channel on a target listener; the target listener is used to obtain an event state corresponding to the to-be-processed asynchronous request through the target network connection channel.

6. The method of claim 1, wherein, Before determining the target method corresponding to the to-be-processed asynchronous request based on the preset configuration template and the to-be-processed asynchronous request when the to-be-processed asynchronous request is in the ready state, the method further comprises: determining a target thread corresponding to the to-be-processed asynchronous request; saving the to-be-processed asynchronous request in a target queue corresponding to the target thread.

7. The method of claim 6, wherein, based on the target method, processing the to-be-processed asynchronous request to obtain a processing result corresponding to the to-be-processed asynchronous request comprises: The target method is called by the target thread, and a request parameter set of the asynchronous request to be processed is processed to obtain a processing result corresponding to the asynchronous request to be processed.

8. An asynchronous request processing apparatus characterized by comprising: The apparatus comprises: An acquisition module is configured to acquire a target object, an asynchronous request to be processed corresponding to the target object, and a target callback function; A monitoring module is configured to establish and register a target network connection channel corresponding to the asynchronous request to be processed, acquire an event state corresponding to the asynchronous request to be processed through the target network connection channel, and determine that the asynchronous request to be processed is in a ready state when the event state corresponding to the asynchronous request to be processed changes; the change of the event state refers to a change from an unconnected state to a connected ready state, a change from an unreadable state to a readable ready state, a change from an unwritable state to a writable ready state, or a change from an unaccepted connection state to an accepted ready state; A determination module is configured to determine a target method corresponding to the asynchronous request to be processed based on a preset configuration template and the asynchronous request to be processed when the asynchronous request to be processed is in the ready state; A processing module is configured to process the asynchronous request to be processed based on the target method to obtain a processing result corresponding to the asynchronous request to be processed; A callback module is configured to send the processing result to the target object based on the target callback function. 9.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-8 when the computer program is executed by the processor. The processor executes the computer program to implement the steps of the method in any one of claims 1 to 7.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 7.

11. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Remote procedure call method and apparatus, and computer device

    CN107277029A

  • Request processing and feedback method and device, computer equipment and readable storage medium

    CN113220481A