Request message processing method, device, apparatus, and storage medium
By decoding and processing request messages, the problem of cross-programming language communication between different devices is solved, enabling flexible device communication and reducing development complexity.
Patent Information
- Application Number
- CN202210849160.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-19
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2042-07-19
AI Technical Summary
In existing technologies, the backend development of applications is limited by a particular programming language, resulting in inflexible development and an inability to achieve cross-programming language communication between different devices.
By receiving encoding request messages, determining their encoding type, and calling the corresponding decoding function to decode them, and combining reflection information and wrapping functions to process the original request messages, cross-programming language communication between different devices can be achieved.
It improves the flexibility of communication and interaction between devices, enables cross-programming language communication between different devices, and reduces the development burden on developers.
Smart Images

Figure CN117459591B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of the Internet and computers, and in particular to a method, apparatus, device and storage medium for processing request messages. Background Technology
[0002] Application developers can use programming languages to develop the backend of their applications.
[0003] Currently, backend development requires the use of a unified programming language to ensure a consistent application development environment. When the first server interacts with the second server to exchange request messages, this unified development environment allows for consistent encoding and decoding methods, ensuring that different servers can recognize the request messages.
[0004] However, in the aforementioned related technologies, the backend development of applications is limited by a certain programming language, making backend development inflexible. Summary of the Invention
[0005] This application provides a method, apparatus, device, and storage medium for processing request messages, enabling cross-programming language communication between different devices. This allows communication and interaction between devices to be extended beyond the limitations of using the same programming language, improving the flexibility of interaction between devices. The technical solution is as follows.
[0006] According to one aspect of the embodiments of this application, a method for processing a request message is provided, the method comprising the following steps: Receive a first request message, the first request message including a first encoding request message and the encoding type of the first encoding request message; wherein, different types of programming languages correspond to different encoding types; From more than one decoding function, determine the decoding function corresponding to the encoding type of the first encoding request message, and use it as the first decoding function; The first decoding function is called to decode the first encoded request message to obtain the first original request message; The first original request message is processed to obtain the processing result for the first original request message.
[0007] According to one aspect of the embodiments of this application, a request message processing apparatus is provided, the apparatus comprising the following modules: A request message receiving module is used to receive a first request message, the first request message including a first encoded request message and the encoding type of the first encoded request message; wherein, different types of programming languages correspond to different encoding types; The decoding function determination module is used to determine, from more than one decoding function, a decoding function corresponding to the encoding type of the first encoding request message, as the first decoding function; The encoded message decoding module is used to call the first decoding function to decode the first encoded request message to obtain the first original request message; The original message processing module is used to process the first original request message to obtain the processing result for the first original request message.
[0008] According to one aspect of the embodiments of this application, the present application provides a computer device, the computer device including a processor and a memory, the memory storing at least one program, the at least one program being loaded and executed by the processor to implement the above-described request message processing method.
[0009] According to one aspect of the embodiments of this application, the embodiments of this application provide a computer-readable storage medium storing at least one program, which is loaded and executed by a processor to implement the above-described request message processing method.
[0010] According to one aspect of the embodiments of this application, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the aforementioned request message processing method.
[0011] The technical solution provided in this application can bring the following beneficial effects: By determining the corresponding decoding function from multiple decoding functions based on the decoding type, and then using the corresponding decoding function to decode the encoding request message, the system takes into account the situation where different programming languages correspond to different encoding types. It determines the encoding type of the encoding request message and assigns the corresponding decoding function to the encoding request message based on the encoding type. This enables cross-programming language communication between different devices, making the communication interaction between devices not limited to the interaction of the same programming language, and improving the flexibility of interaction between devices. Attached Figure Description
[0012] Figure 1 This is a schematic diagram of a request message processing system provided in one embodiment of this application; Figure 2 A schematic diagram of a request message processing system is shown as an example; Figure 3 This is a flowchart of a request message processing method provided in one embodiment of this application; Figure 4 An exemplary schematic diagram of a heterogeneous network graph is shown; Figure 5 An exemplary schematic diagram of a heterogeneous network subgraph is shown; Figure 6 An exemplary diagram of a heterogeneous network graph after edge deletion processing is shown. Figure 7 An exemplary schematic diagram of a request message processing method is shown; Figure 8 This is a flowchart of a request message processing method provided in another embodiment of this application; Figure 9 This is a block diagram of a request message processing apparatus provided in one embodiment of this application; Figure 10 This is a block diagram of a request message processing apparatus provided in another embodiment of this application; Figure 11 This is a structural block diagram of a computer device provided in one embodiment of this application. Detailed Implementation
[0013] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0014] Please refer to Figure 1 This illustration shows a schematic diagram of a request message processing system according to an embodiment of this application. The request message processing system may include a terminal device 10 and a server 20.
[0015] Terminal device 10 can be electronic devices such as mobile phones, tablets, PCs (Personal Computers), intelligent voice interaction devices, smart home appliances, vehicle terminals, aircraft, etc., and this application embodiment does not limit it.
[0016] Server 20 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
[0017] The aforementioned terminal device 10 and the aforementioned server 20 can be connected directly or indirectly through wired or wireless communication, and this application does not impose any restrictions on this.
[0018] In some embodiments, different devices in a request message processing system can communicate and interact using request messages. These request messages can be RPC request messages. For example, a server... Figure 2 As shown, the first server generates an original request message and specifies its encoding type. Further, the encoding / decoding module in the first server encodes the original request message based on the specified encoding type to obtain an encoded request message. Further, the asynchronous processing module saves the context message corresponding to the encoded request message and creates a corresponding number for the encoded request message, recording the mapping relationship between the context message and the number. Then, the first server sends a request message to the second server, which includes the encoded request message and its encoding type. Correspondingly, after receiving the request message, the second server's encoding / decoding module decodes the encoded request message based on the encoding type using the corresponding decoding method to obtain the original request message. Then, the distribution module parses the wrapping function from the original request message, executes the wrapping logic corresponding to the wrapping function to obtain the corresponding execution logic for the original request message, and calls the corresponding logic function based on this execution logic to process the original request message, obtaining the processing result of the original request message. Next, the second server specifies the encoding type for the processing result. The second server's encoding / decoding module encodes the processing result based on the specified encoding type to obtain an encoded processing result message, which is then sent to the first server. This result message includes the encoded processing result message and its corresponding encoding type. Then, based on the mapping relationship between the number and the context message, the first server determines the corresponding context message for the encoded processing result message. The encoding / decoding module then decodes the encoded processing result message using the corresponding decoding method based on the encoding type to obtain the processing result. The second server then performs subsequent processing on the result according to the context message.
[0019] It should be noted that the above description of device interaction in the request message processing system is merely exemplary and explanatory. In the exemplary embodiment, all devices in the request message processing system can interact and communicate with each other. For example, a terminal device and a server can also interact and communicate using request messages. This application embodiment does not limit this.
[0020] Please refer to Figure 3 This document illustrates a flowchart of a request message processing method according to an embodiment of this application. The steps in this method can be performed by the methods described above. Figure 1 The method is executed by server 20. It may include at least one of the following steps (301-304): Step 301: Receive the first request message.
[0021] The first request message refers to a request message sent by the message requester to the message processor. In this application example, the server receives the first request message from another device. The server can be referred to as the message processor, and the other device can be referred to as the message requester. The aforementioned other device can be a terminal device or another server; this application embodiment does not limit this.
[0022] In this embodiment, the first request message includes a first encoded request message and an encoding type for the first encoded request message. The first encoded request message refers to the encoded original request message. In some embodiments, the message requester encodes the first original request message after generating it to obtain the first encoded request message. Furthermore, since different types of programming languages correspond to different encoding types, the message requester can determine the encoding type based on the programming language of the message processor when performing encoding.
[0023] In some embodiments, the first request message is sent to the server in the form of a data packet, and the encoding type is stored in the header of the data packet.
[0024] Step 302: Determine the decoding function corresponding to the encoding type of the first encoding request message from more than one decoding function, and use it as the first decoding function.
[0025] Decoding functions are used to decode encoded request messages, and different decoding functions are suitable for different encoding types. In this embodiment, the server includes multiple decoding functions. After obtaining the aforementioned request message, the server obtains a first encoding request and the encoding type of the first encoding request message from the first request message. Further, the server determines the decoding function corresponding to the encoding type of the first encoding request message from the multiple decoding functions as the first decoding function, and subsequently calls the first decoding function to decode the first encoding request message.
[0026] In some embodiments, the decoding function can be stored directly on the server or stored on the server as a plugin.
[0027] In one possible implementation, the decoding function is stored directly in the server. After determining the encoding type corresponding to the first encoding request message, the server selects a first decoding function from among multiple decoding functions based on the encoding type, and then calls the first decoding function to decode the first encoding request message.
[0028] In another possible implementation, the decoding function is stored in the server as a plugin. In some embodiments, the decoding function is stored in codec plugins, with different types of codec plugins corresponding to different programming languages. Each codec plugin includes an encoding function and a decoding function. After determining the codec type corresponding to the first encoding request message, the server determines the corresponding codec plugin based on that encoding type, and then calls the decoding function in the plugin to decode the first encoding request message. In some embodiments, the server has a codec manager that is used to assign the corresponding codec plugin to the encoding request message according to the encoding type. For example, as shown... Figure 4 As shown, the encoding / decoding module of the server includes an encoding / decoding manager 40, which can uniformly manage the first type of encoding / decoding plugin 41, the second type of encoding / decoding plugin 42, and the third type of encoding / decoding plugin 43. Furthermore, after receiving the first request message, the server assigns the encoding / decoding plugin corresponding to the encoding type to the first encoding request message based on the encoding type in the first request message, and then decodes the first encoding request through the encoding / decoding plugin.
[0029] It should be noted that since the same programming language can correspond to one or more encoding / decoding methods, the appropriate encoding / decoding type can be determined by testing the TPS of empty messages. Taking Lua and C++ as examples, the test results are shown in Table 1 below: Table 1 Compatibility between different programming languages and different encoding / decoding types
[0030] As can be seen from the above, on the Lua side, Luna is based on Lua's native table encoding and decoding, making it the most convenient to use and offering the best performance. It is recommended for use in Lua. On the C++ side, protobuf and msgpack have comparable performance, and the choice can be made based on actual needs.
[0031] Step 303: Call the first decoding function to decode the first encoded request message to obtain the first original request message.
[0032] In this embodiment, after obtaining the first decoding function, the server calls the first decoding function to decode the first encoded request message to obtain the first original request message. In some embodiments, since different types of data correspond to different decoding rules, the server determines the decoding rule corresponding to the first encoded request message through the first decoding function during decoding, and then decodes the first encoded request based on the decoding rule.
[0033] Step 304: Process the first original request message to obtain the processing result for the first original request message.
[0034] In this embodiment of the application, after obtaining the first original request message, the server processes the original request message to obtain the processing result for the first original request message.
[0035] In some embodiments, after obtaining the above processing result, the server may feed back the processing result to the message requester, or it may continue to perform subsequent processing based on the processing result. This application embodiment does not limit this.
[0036] In summary, the technical solution provided in this application determines the corresponding decoding function from multiple decoding functions by decoding type, and then uses the corresponding decoding function to decode the encoding request message. It takes into account the situation that different programming languages correspond to different encoding types, determines the encoding type of the encoding request message, and assigns the corresponding decoding function to the encoding request message for decoding according to the encoding type. This realizes cross-programming language communication between different devices, so that the communication interaction between devices is not limited to the interaction of the same programming language, and improves the flexibility of interaction between devices.
[0037] The decoding method for the first encoded request message will be described below.
[0038] In an exemplary embodiment, step 303 above includes at least one of the following: 1. The reflection information is obtained by parsing the first encoding request message through the first decoding function.
[0039] The reflection information is used to indicate the data type of the first original request message. In some embodiments, different data types correspond to different encoding and decoding rules. In this embodiment, when the server decodes the first encoded request message, it parses the reflection information from the first encoded request using the first decoding function.
[0040] In some embodiments, after obtaining the first decoding function, the server uses the first decoding function to parse the abstract syntax tree (AST) information from the first encoding request message; further, it uses the first decoding function to parse the glue code file of the reflection information from the AST information, and uses the first decoding function to parse the reflection information from the glue code file of the reflection information.
[0041] It should be noted that, due to the different data types, the reflected message can be a reflection message that comes with the data itself, or it can be annotation information added to the data structure of the first encoded request message.
[0042] Taking Lua type data as an example, since Lua type data can carry reflection information, if the first encoding request message includes Lua type data, then the aforementioned reflection information includes the data type. After obtaining the first decoding function, the server directly determines the data type from the first encoding request message through the first decoding function, and determines the decoding rules for the first encoding request message based on the data type.
[0043] Taking C++ type data as an example, since C++ type data cannot inherently contain reflection information, annotation information can be written when generating the original encoding request to characterize the data type. Furthermore, if the first encoding request message includes C++ type data, the aforementioned reflection information includes information used to characterize the annotation information in the original encoding request. After obtaining the first decoding function, the server parses the aforementioned reflection information from the first encoding request using the first decoding function, and then determines the decoding rules for the first encoding request message based on the reflection. For example, the annotation information in the C++ type is as follows: #define CLASS (...) \ __attribute__((annotate("reflect-class;" #__VA_ARGS__))) #define FUNCTION(...) \ __attribute__((annotate("reflect-function;" #__VA_ARGS__))).
[0044] It should be noted that when the original encoded request data does not contain reflection information, a corresponding annotation template can be set for this type of data to assist in writing annotation information. In this case, developers can write annotation information more efficiently based on the annotation template, reducing the development burden on developers while ensuring automatic encoding.
[0045] 2. The first encoding request message is decoded by the first decoding function according to the decoding rules indicated by the reflection information to obtain the first original request message.
[0046] In some embodiments, different data types correspond to different encoding and decoding rules. In this embodiment, after obtaining the reflected message, the server determines the encoding rule indicated by the reflected message, and then uses the first encoding function to decode the first encoded request message using the encoding rule to obtain the first original request message.
[0047] In summary, the technical solution provided in this application uses reflection information to characterize data types, thereby determining the encoding method corresponding to the data type to decode the encoding request message, thus achieving automatic decoding of the encoding request message and improving the decoding efficiency of the encoding request message.
[0048] The following section describes how the first original request message is processed.
[0049] In an exemplary embodiment, step 304 above includes at least one of the following steps: 1. Determine the wrapper function instruction information from the first original request message; 2. Based on the wrapping function indication information, determine the wrapping function corresponding to the first original request message from more than one wrapping function, and use it as the first wrapping function; 3. Execute the wrapping logic corresponding to the first wrapping function to obtain the execution logic corresponding to the first original request message; 4. Based on the execution logic, call the logic function to process the first original request message and obtain the processing result for the first original request message.
[0050] The wrapper function indication information is used to indicate the wrapper function corresponding to the first original request message. The wrapper function is a function that can represent specific execution logic. In this embodiment, the server determines the wrapper function indication information from the first original request.
[0051] In some embodiments, the wrapper function indication information includes the request message type and the request message instruction name. When the server obtains the above wrapper function indication information, it determines the request message type (type) and the request message instruction name (cmd) from the original request message.
[0052] In this embodiment of the application, after obtaining the above-mentioned wrapping function indication information, the server determines the wrapping function corresponding to the first original request message from multiple wrapping functions according to the wrapping function indication information, and uses it as the first wrapping function. Then, it executes the wrapping logic corresponding to the first wrapping function to obtain the execution logic corresponding to the first original request message, and calls the logic function based on the execution logic to process the first original request message to obtain the processing result for the first original request message.
[0053] In some embodiments, when processing the first original request, the server obtains the parameter call order and logic function indicated by the execution logic; further, based on the parameter call order, the server processes the parameters in the first original request message through the logic function to obtain the processing result for the first original request message.
[0054] In some embodiments, the server assigns a corresponding wrapper function to the first original request message through a function manager. For example, such as... Figure 5 As shown, the distribution module in the server includes a function manager 51. After the server obtains the first original request message, the function manager allocates a corresponding wrapper function to the first original request message according to the wrapper function instruction information, and then calls the logic function according to the wrapper function.
[0055] In summary, the technical solution provided in this application embodiment indicates the execution logic through a wrapper function, and then calls the corresponding logic function to process the original request message based on the execution logic. The execution logic can indicate the parameter processing order and the logic function to be called. Both the wrapper function and the logic function are directly deployed in the server. When generating the original request, only the parameters need to be provided, and there is no need to develop additional parameter processing rules, which reduces the development burden of developers.
[0056] The following section will use Lua and C++ data as examples to introduce the generation of wrapper functions.
[0057] Lua data: Let the actual function to be executed be f. Based on some Lua code, the steps for generating the wrapper function are as follows: 1. Use the debug library to obtain the list of parameter names for f and insert them into the Lua table in sequence; 2. Iterate through the list of parameter names. For each function name, append the prefix "param." and insert it into the Lua table (assuming the table variable is "src"). For example, if the function name is "foo", the appended name will be "param.foo". 3. Using the Lua table concatenated in step 2, generate a string that returns the Lua closure: "return function(param) return " .. tconcat(src,",") .. " end" 4. Load the string from step three into memory to generate a closure (let's assume it's unpack_f): load("return function(param) return " .. tconcat(src,",") .. " end")() 5. Then, use unpack_f and function f to generate a new closure, which is stored in the function manager as the final wrapper function: wrapper_f = function (param) return f(unpack_f(param)) end.
[0058] In this scenario, assuming the received original request message has the command name `cmd = f` and parameters `param = {a=1, b=2, c=3}`, and the prototype of `f` is `function f(a, b, c) end`, the wrapper `f(param)` is called first, ultimately actually calling `f(param.a, param.b, param.c)`. Clearly, after wrapping the function, the parameters are automatically passed in the order declared in the function parameters. Even if function refactoring involves adding, deleting, or changing the order of parameters (e.g., changing the prototype of `f` to `function f(a, c, b) end`), without changing the request parameters on the requesting side, `f(param.a, param.c, param.b)` is actually called, achieving parameter adaptation and ensuring version compatibility.
[0059] C++ data: 1. Label the function as an RPC function, and specify the corresponding encoding / decoding type: For example, FUNCTION(RpcCallable, ProtoType = "c2s-msgpack") annotates a C++ RPC function of type C2S encoded and decoded by msgpack; 2. Use reflection (cppreflect) to find the reflection information of all RPC functions, such as function name, parameter list and type; 3. Generate code for parameter stream decoding using the codec library based on the specified codec type. Only one code generation template needs to be added for each codec type, so the workload is controllable. 4. Generate code that calls the actual RPC function (i.e., the logic function mentioned above) using the decoded parameter list; 5. Register the RPC wrapper function to the function manager.
[0060] It should be noted that the above description of the message request processing method in this application is from the perspective of the message recipient. Below, the message request processing method is described from the perspective of the message requester.
[0061] Please refer to Figure 6 This illustrates a flowchart of a request message processing method provided in another embodiment of this application. The steps in this method can be performed by the methods described above. Figure 1 The method is executed by server 20. It may include at least one of the following steps (601-605): Step 601: Obtain the second original request message and the encoding type of the second original request message.
[0062] In this embodiment, the server, acting as the message requester, obtains a second original request message and its encoding type. This encoding type can be determined by the server based on the programming language of the message processor.
[0063] Step 602: Determine the encoding function corresponding to the encoding type of the second original request message from more than one encoding function.
[0064] In this embodiment of the application, after obtaining the above-mentioned encoding type, the server determines the encoding function corresponding to the encoding type of the second original request message from a plurality of encoding functions.
[0065] In some embodiments, the above-described encoding functions can be stored directly on the server or stored on the server as a plugin; this application does not limit this.
[0066] Step 603: Call the encoding function corresponding to the encoding type of the second original request message to encode the second original request message and obtain the second encoded request message.
[0067] In this embodiment of the application, after obtaining the above-mentioned encoding function, the server calls the encoding function to encode the second original request message to obtain the second encoded request message.
[0068] Step 604: If the second encoding request message is an asynchronous processing message, save the context message corresponding to the second encoding request message.
[0069] In this embodiment, for the second encoding request message, if the server determines that the second encoding request is an asynchronous processing message, it saves the context message corresponding to the second encoding request message. In some embodiments, the second encoding request message corresponds to an asynchronous processing identifier, and the server determines whether to perform asynchronous processing on the second encoding request based on the asynchronous processing identifier.
[0070] In one possible implementation, the server performs asynchronous processing of the second encoding request message by creating a coroutine. In some embodiments, when the server determines that the second encoding request message is an asynchronous processing message, it creates a coroutine corresponding to the second encoding request message and assigns a number to the second encoding request message. The coroutine is in a waiting state, which corresponds to a waiting action, and there is a mapping relationship between the coroutine and the number.
[0071] In another possible implementation, the server uses a callback function to perform asynchronous processing of the second encoded request message. In some embodiments, when the server determines that the second encoded request message is an asynchronous processing message, it creates a callback function corresponding to the second encoded request message and assigns a number to the second encoded request message. There is a mapping relationship between the function name and the number of the callback function.
[0072] Step 605: Upon receiving the processing result encoding message for the second encoding request message, process the processing result encoding message based on the context message.
[0073] In some embodiments, after obtaining the second encoding request message, the server generates a second request message based on the second encoding request message and the encoding type, and sends the second request message to the message processor.
[0074] Correspondingly, when the server receives the processing result encoding message for the second encoding request message, it processes the processing result encoding message based on the aforementioned context message.
[0075] In one possible implementation, the server asynchronously processes the second encoded request message by creating a coroutine. Upon receiving the processed result encoded message for the second encoded request message, the server determines that a response event for a waiting action has been detected. Then, based on the number of the second encoded request message, the server determines the coroutine corresponding to the second encoded request message, transitions the coroutine from a waiting state to a running state, decodes the processed result encoded message to obtain the processed result message for the second encoded request message, and performs subsequent processing on the data in the processed result message based on the aforementioned context message. Here, the aforementioned waiting action indicates the reason for the coroutine to enter the waiting state, and the aforementioned response event indicates that the coroutine meets the running conditions indicated by the waiting reason. One waiting action can correspond to one or more response events; this embodiment of the application does not limit this.
[0076] For example, such as Figure 7 As shown, using Lua data and RPC functions as examples, the asynchronous processing flow of coroutines is introduced: 1. Create a coroutine CoObjc in the init (initialization) state using CoMgr with an RPC function as a parameter, and generate a unique number to bind to the cache; 2. Start the coroutine via CoMgr, switch the coroutine status to running, and execute the RPC function logic; 3. When executing asynchronous request logic, encode the unique number into the request message and send it to the receiver; 4. Suspend the coroutine via CoMgr, and finally call the Lua coroutine yield function to save the function context information and switch the coroutine state to wait state; 5. After receiving the response message from the other end, extract the unique code of the coroutine and look up the corresponding coroutine using CoMgr; 6. Call the Lua coroutine resume function to restore the function context and switch the state to running to continue executing subsequent logic; 7. To prevent the requester from being permanently suspended due to peer anomalies causing the requester to be unable to receive response messages, CoMgr will periodically scan for coroutines that have timed out in the wait state and force them to wake up after the timeout.
[0077] In some embodiments, an init state coroutine is created via CoMgr using an RPC function as a parameter, and a unique number is created and cached for the coroutine. Then, if asynchronous processing is not required, the coroutine is started via CoMgr, its state is directly switched to running, and the RPC function is called to execute subsequent logic. If asynchronous processing is required, the unique number is encoded into a request message (such as the second request message mentioned above). Furthermore, the yield function is called via CoMgr to save the function context information, and the coroutine state is switched to wait, with a corresponding waiting action. Then, upon receiving a response message to the request message, the coroutine's unique code is extracted from the response message, the corresponding coroutine is found via CoMgr, the resume function is called to restore the function context, the coroutine state is switched to running, and the RPC function is called to execute subsequent logic based on the function context. The response message also includes a response event corresponding to the waiting task. In some embodiments, if a coroutine fails to run or encounters an exception, the coroutine is switched to a free state to indicate that it has ended or encountered an exception, and then the coroutine in the free state is deleted. It should be noted that the aforementioned coroutines have a timeout duration, which indicates the maximum duration a coroutine can remain in a wait state. Therefore, CoMgr periodically scans for coroutines in the wait state, and if a coroutine's wait time reaches the timeout duration, it forcibly wakes the coroutine, switches its state to running, and executes subsequent logic. This prevents the requesting party from failing to receive a response message due to a peer-end exception, thus avoiding permanent suspension of the coroutine.
[0078] In another possible implementation, the server uses a callback function to asynchronously process the second encoded request message. Upon receiving the processed result encoded message for the second encoded request message, the server determines the callback function corresponding to the second encoded request message based on its number, and then, based on the context message, calls the callback function to perform subsequent processing on the data in the processed result message.
[0079] For example, such as Figure 8 As shown, using C++ data and RPC functions as examples, the asynchronous processing flow of callback functions is introduced: 1. Initiate an asynchronous request; 2. Create a unique identifier for the request message; 3. Specify the callback function name; 4. Cache the unique code and callback function name mapping in the RPC context manager; 5. Send an RPC request message to the recipient; 6. Receive the processing result from the recipient; 7. Locate the RPC context; 8. Obtain the callback function name from the RPC context; 9. Locate the callback wrapper function from the callback function manager; 10. Call the callback wrapper function to perform asynchronous callback processing.
[0080] The aforementioned callback function manager is used to store all automatically generated callback function wrapper functions, thus solving the callback function distribution problem.
[0081] In some embodiments, after initiating an asynchronous request, a unique number is created for the RPC request message, and a callback function name is specified. Further, this unique number and callback function name are mapped and cached in the RPC context manager, and the RPC request message is sent to the receiving party. The RPC context manager caches multiple sets of mapping relationships between numbers and callback function names. Then, after receiving the processing result of the RPC request message from the receiver, the unique number is retrieved from the processing result. Based on the RPC context manager, the RPC context is searched according to the unique number, and then the callback function name is retrieved from the RPC context. Next, based on the callback function manager, a wrapper function pointer is determined according to the callback function name, and then the corresponding wrapper function is determined according to the wrapper function pointer. Finally, subsequent logic is executed based on the processing result using this wrapper function. It should be noted that in the above RPC context manager, each unique number also corresponds to a timeout period, starting from when the RPC request message is sent. If the corresponding processing result is not received after the timeout period, the wrapper function pointer is forcibly determined based on the callback function manager and the callback function name to continue executing subsequent logic.
[0082] In summary, the technical solution provided in this application embodiment achieves asynchronous message processing through coroutines, and the waiting state of the coroutine corresponds to a waiting action that represents the reason for waiting. The waiting action corresponds to a response event, and the response event can represent that the coroutine meets the running conditions indicated by the reason for waiting. Based on the waiting work and response time, the reason for the state transition of the coroutine can be intuitively determined, thereby improving the transparency of the coroutine execution process.
[0083] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0084] Please refer to Figure 9 This diagram illustrates a block diagram of a request message processing apparatus according to an embodiment of this application. The apparatus has the function of implementing the aforementioned request message processing method; this function can be implemented in hardware or by hardware executing corresponding software. The apparatus 900 can be a computer device or can be installed within a computer device. The apparatus 900 may include: a request message receiving module 910, a decoding function determination module 920, an encoded message decoding module 930, and a raw message processing module 940.
[0085] The request message receiving module 910 is used to receive a first request message, which includes a first encoding request message and an encoding type of the first encoding request message; wherein, different types of programming languages correspond to different encoding types.
[0086] The decoding function determination module 920 is used to determine, from more than one decoding function, a decoding function corresponding to the encoding type of the first encoding request message, as the first decoding function.
[0087] The encoded message decoding module 930 is used to call the first decoding function to decode the first encoded request message to obtain the first original request message.
[0088] The original message processing module 940 is used to process the first original request message to obtain the processing result for the first original request message.
[0089] In an exemplary embodiment, such as Figure 10 As shown, the encoded message decoding module 930 includes: a reflection information acquisition unit 931 and an encoded message decoding unit 932.
[0090] The reflection information acquisition unit 931 is used to parse reflection information from the first encoded request message through the first decoding function, wherein the reflection information is used to indicate the data type in the first original request message.
[0091] The encoded message decoding unit 932 is used to decode the first encoded request message according to the decoding rules indicated by the reflection information through the first decoding function to obtain the first original request message.
[0092] In an exemplary embodiment, the reflection information acquisition unit 931 is further configured to: The first decoding function is used to parse the abstract syntax tree (AST) information from the first encoding request message. The glue code file containing the reflection information is obtained by parsing the AST information using the first decoding function; The reflection information is obtained by parsing the glue code file containing the reflection information using the first decoding function.
[0093] In an exemplary embodiment, such as Figure 10 As shown, the original message processing module 940 includes: an instruction information determination unit 941, a packaging function determination unit 942, an execution logic acquisition unit 943, and an original message processing unit 944.
[0094] The instruction information determination unit 941 is used to determine the packaging function instruction information from the first original request message.
[0095] The packaging function determination unit 942 is used to determine, based on the packaging function indication information, the packaging function corresponding to the first original request message from more than one packaging function, and use it as the first packaging function.
[0096] The execution logic acquisition unit 943 is used to execute the packaging logic corresponding to the first packaging function to obtain the execution logic corresponding to the first original request message.
[0097] The original message processing unit 944 is used to process the first original request message by calling a logic function based on the execution logic, and to obtain a processing result for the first original request message.
[0098] In an exemplary embodiment, the original message processing unit 944 is further configured to: Obtain the parameter call order and logical function indicated by the execution logic; Based on the parameter calling order, the parameters in the first original request message are processed through the logical function to obtain the processing result for the first original request message.
[0099] In an exemplary embodiment, such as Figure 10 As shown, the device 900 further includes: a request message acquisition module 950, a request message encoding module 960, and an encoded message processing module 970.
[0100] The request message acquisition module 950 is used to acquire the second original request message and the encoding type of the second original request message.
[0101] The request message encoding module 960 is used to determine, from more than one encoding function, an encoding function corresponding to the encoding type of the second original request message; and to call the encoding function corresponding to the encoding type of the second original request message to encode the second original request message to obtain a second encoded request message. The encoding message processing module 970 is used to save the context message corresponding to the second encoding request message when the second encoding request message is an asynchronous processing message; and to process the processing result encoding message based on the context message when a processing result encoding message for the second encoding request message is received.
[0102] In an exemplary embodiment, such as Figure 10 The device 900 further includes a message coroutine creation module 980.
[0103] The message coroutine creation module 980 is used to create a coroutine corresponding to the second encoding request message and the number of the second encoding request message; wherein, the state of the coroutine is a waiting state, the waiting state corresponds to a waiting action, and there is a mapping relationship between the coroutine and the number.
[0104] In an exemplary embodiment, the encoded message processing module 970 is further configured to: Upon receiving a processing result encoding message for the second encoding request message, it is determined that a response event for the waiting action has been detected; The coroutine corresponding to the second encoding request message is determined based on the number of the second encoding request message; and the coroutine is changed from the waiting state to the running state. The processing result encoded message is decoded to obtain the processing result message for the second encoded request message; The data in the processing result message is further processed based on the context message.
[0105] In summary, the technical solution provided in this application determines the corresponding decoding function from multiple decoding functions by decoding type, and then uses the corresponding decoding function to decode the encoding request message. It takes into account the situation that different programming languages correspond to different encoding types, determines the encoding type of the encoding request message, and assigns the corresponding decoding function to the encoding request message for decoding according to the encoding type. This realizes cross-programming language communication between different devices, so that the communication interaction between devices is not limited to the interaction of the same programming language, and improves the flexibility of interaction between devices.
[0106] It should be noted that the apparatus provided in the above embodiments is only illustrated by the division of the above functional modules when implementing its functions. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0107] Please refer to Figure 11 This diagram illustrates a structural block diagram of a computer device according to an embodiment of this application. This computer device can be used to implement the functions of the above-described request message processing method. Specifically: Computer device 1100 includes a central processing unit (CPU) 1101, a system memory 1104 including random access memory (RAM) 1102 and read-only memory (ROM) 1103, and a system bus 1105 connecting the system memory 1104 and the CPU 1101. Computer device 1100 also includes a basic input / output system (I / O system) 1106 that facilitates information transfer between various devices within the computer, and a mass storage device 1107 for storing the operating system 1113, application programs 1114, and other program modules 1115.
[0108] The basic input / output system 1106 includes a display 1108 for displaying information and an input device 1109 for user input, such as a mouse or keyboard. Both the display 1108 and the input device 1109 are connected to the central processing unit 1101 via an input / output controller 1110 connected to the system bus 1105. The basic input / output system 1106 may also include the input / output controller 1110 for receiving and processing input from multiple other devices such as a keyboard, mouse, or electronic stylus. Similarly, the input / output controller 1110 also provides output to a display screen, printer, or other types of output devices.
[0109] Mass storage device 1107 is connected to central processing unit 1101 via a mass storage controller (not shown) connected to system bus 1105. Mass storage device 1107 and its associated computer-readable media provide non-volatile storage for computer device 1100. That is, mass storage device 1107 may include computer-readable media (not shown) such as hard disk or CD-ROM (Compact Disc Read-Only Memory) drive.
[0110] Without loss of generality, computer-readable media can include computer storage media and communication media. Computer storage media includes volatile and non-volatile, removable and non-removable media implemented using any method or technology for storing information such as computer-readable instructions, data structures, program modules, or other data. Computer storage media includes RAM, ROM, EPROM (Erasable Programmable Read Only Memory), EEPROM (Electrically Erasable Programmable Read Only Memory), flash memory or other solid-state storage devices, CD-ROM, DVD (Digital Video Disc), or other optical storage, magnetic tape cassettes, magnetic tape, disk storage, or other magnetic storage devices. Of course, those skilled in the art will recognize that computer storage media are not limited to the above-mentioned types. The system memory 1104 and mass storage device 1107 described above can be collectively referred to as memory.
[0111] According to various embodiments of this application, the computer device 1100 can also be connected to a remote computer on a network, such as the Internet. That is, the computer device 1100 can be connected to the network 1112 via the network interface unit 1111 connected to the system bus 1105, or the network interface unit 1111 can be used to connect to other types of networks or remote computer systems (not shown).
[0112] The memory also includes a computer program stored in the memory and configured to be executed by one or more processors to implement the above-described method for processing request messages.
[0113] In an exemplary embodiment, a computer-readable storage medium is also provided, the storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set, when executed by a processor, implements the above-described method for processing the request message.
[0114] Optionally, the computer-readable storage medium may include: ROM (Read Only Memory), RAM (Random Access Memory), SSD (Solid State Drives), or optical disc, etc. The random access memory may include ReRAM (Resistance Random Access Memory) and DRAM (Dynamic Random Access Memory).
[0115] In an exemplary embodiment, a computer program product or computer program is also provided, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the aforementioned request message processing method.
[0116] It should be understood that "multiple" as used herein refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. Furthermore, the step numbers described herein are merely illustrative of one possible execution order. In some other embodiments, the steps may not be executed in numerical order, such as two steps with different numbers being executed simultaneously, or two steps with different numbers being executed in the reverse order of the illustration. This application does not limit this.
[0117] The above description is merely an exemplary embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for processing request messages, characterized in that, The method includes: A first request message is received, the first request message including a first encoding request message and the encoding type of the first encoding request message; wherein, different types of programming languages correspond to different encoding types; the first encoding request message is obtained by encoding the first original request message by calling the encoding function corresponding to the encoding type of the first encoding request message, and the encoding type of the first encoding request message is determined by the message requester of the first request message from among the multiple encoding types corresponding to the programming language of the message processor; From more than one decoding function, determine the decoding function corresponding to the encoding type of the first encoding request message, and use it as the first decoding function; The first decoding function is called to decode the first encoded request message to obtain the first original request message; The first original request message is processed to obtain the processing result for the first original request message.
2. The method according to claim 1, characterized in that, The step of calling the first decoding function to decode the first encoded request message to obtain the first original request message includes: The reflection information is parsed from the first encoded request message using the first decoding function. The reflection information is used to indicate the data type in the first original request message. The first decoding function decodes the first encoded request message according to the decoding rules indicated by the reflection information to obtain the first original request message.
3. The method according to claim 2, characterized in that, The step of parsing the reflection information from the first encoding request message using the first decoding function includes: The first decoding function is used to parse the abstract syntax tree (AST) information from the first encoding request message. The glue code file containing the reflection information is obtained by parsing the AST information using the first decoding function; The reflection information is obtained by parsing the glue code file containing the reflection information using the first decoding function.
4. The method according to claim 1, characterized in that, The processing of the first original request message to obtain a processing result for the first original request message includes: Determine the wrapper function indication information from the first original request message; Based on the packaging function indication information, the packaging function corresponding to the first original request message is determined from more than one packaging function and used as the first packaging function; Execute the packaging logic corresponding to the first packaging function to obtain the execution logic corresponding to the first original request message; Based on the execution logic, the logic function is called to process the first original request message, and the processing result for the first original request message is obtained.
5. The method according to claim 4, characterized in that, The step of processing the first original request message by calling the logic function based on the execution logic to obtain the processing result for the first original request message includes: Obtain the parameter call order and logical function indicated by the execution logic; Based on the parameter calling order, the parameters in the first original request message are processed through the logical function to obtain the processing result for the first original request message.
6. The method according to any one of claims 1 to 5, characterized in that, The method further includes: Obtain the second original request message and the encoding type of the second original request message; Determine the encoding function corresponding to the encoding type of the second original request message from more than one encoding function; Call the encoding function corresponding to the encoding type of the second original request message to encode the second original request message to obtain the second encoded request message; If the second encoding request message is an asynchronous processing message, save the context message corresponding to the second encoding request message; Upon receiving a processing result encoding message for the second encoding request message, the processing result encoding message is processed based on the context message.
7. The method according to claim 6, characterized in that, After saving the context message corresponding to the second encoding request message, the method further includes: Create a coroutine corresponding to the second encoding request message and the number of the second encoding request message; wherein, the state of the coroutine is a waiting state, the waiting state corresponds to a waiting action, and there is a mapping relationship between the coroutine and the number; Upon receiving a processing result encoding message for the second encoding request message, processing the processing result encoding message based on the context message includes: Upon receiving a processing result encoding message for the second encoding request message, it is determined that a response event for the waiting action has been detected; The coroutine corresponding to the second encoding request message is determined based on the number of the second encoding request message; and the coroutine is changed from the waiting state to the running state. The processing result encoded message is decoded to obtain the processing result message for the second encoded request message; The data in the processing result message is further processed based on the context message.
8. A request message processing apparatus, characterized in that, The device includes: A request message receiving module is used to receive a first request message, the first request message including a first encoded request message and an encoding type of the first encoded request message; wherein, different types of programming languages correspond to different encoding types; the first encoded request message is obtained by encoding a first original request message by calling an encoding function corresponding to the encoding type of the first encoded request message, and the encoding type of the first encoded request message is determined by the message requester of the first request message from among multiple encoding types corresponding to the programming language of the message processor; The decoding function determination module is used to determine, from more than one decoding function, a decoding function corresponding to the encoding type of the first encoding request message, as the first decoding function; The encoded message decoding module is used to call the first decoding function to decode the first encoded request message to obtain the first original request message; The original message processing module is used to process the first original request message to obtain the processing result for the first original request message.
9. The apparatus according to claim 8, characterized in that, The encoded message decoding module includes: a reflection information acquisition unit and an encoded message decoding unit; The reflection information acquisition unit is used to parse reflection information from the first encoded request message through the first decoding function, and the reflection information is used to indicate the data type in the first original request message; The encoded message decoding unit is used to decode the first encoded request message according to the decoding rules indicated by the reflection information through the first decoding function to obtain the first original request message.
10. The apparatus according to claim 9, characterized in that, The reflection information acquisition unit is used to parse the abstract syntax tree (AST) information from the first encoding request message using the first decoding function; and to parse the glue code file of the reflection information from the AST information using the first decoding function. The reflection information is obtained by parsing the glue code file containing the reflection information using the first decoding function.
11. The apparatus according to claim 8, characterized in that, The original message processing module includes an instruction information determination unit, a wrapper function determination unit, an execution logic acquisition unit, and an original message processing unit; The indication information determining unit is used to determine the packaging function indication information from the first original request message; The packaging function determining unit is configured to determine, based on the packaging function indication information, the packaging function corresponding to the first original request message from more than one packaging function, and use it as the first packaging function; The execution logic acquisition unit is used to execute the packaging logic corresponding to the first packaging function to obtain the execution logic corresponding to the first original request message. The original message processing unit is used to process the first original request message by calling a logic function based on the execution logic, and to obtain a processing result for the first original request message.
12. The apparatus according to claim 11, characterized in that, The original message processing unit is used to obtain the parameter calling order and logic function indicated by the execution logic; based on the parameter calling order, the parameters in the first original request message are processed by the logic function to obtain the processing result for the first original request message.
13. The apparatus according to any one of claims 8 to 12, characterized in that, The device further includes: a request message acquisition module, a request message encoding module, and an encoded message processing module; The request message acquisition module is used to acquire the second original request message and the encoding type of the second original request message; The request message encoding module is used to determine, from more than one encoding function, an encoding function corresponding to the encoding type of the second original request message; and to call the encoding function corresponding to the encoding type of the second original request message to encode the second original request message to obtain a second encoded request message. The encoded message processing module is configured to save the context message corresponding to the second encoded request message when the second encoded request message is an asynchronous processing message; and to process the processing result encoded message based on the context message when a processing result encoded message for the second encoded request message is received.
14. The apparatus according to claim 13, characterized in that, The device further includes: a message coroutine creation module; The message coroutine creation module is used to create a coroutine corresponding to the second encoded request message and the number of the second encoded request message; wherein, the state of the coroutine is a waiting state, the waiting state corresponds to a waiting action, and there is a mapping relationship between the coroutine and the number; The encoded message processing module is configured to, upon receiving a processing result encoded message for the second encoded request message, determine that a response event for the waiting action has been detected; determine the coroutine corresponding to the second encoded request message based on the number of the second encoded request message; and change the coroutine from the waiting state to the running state; decode the processing result encoded message to obtain a processing result message for the second encoded request message; and perform subsequent processing on the data in the processing result message based on the context message.
15. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one program, which is loaded and executed by the processor to implement the request message processing method as described in any one of claims 1 to 7.
16. A computer-readable storage medium, characterized in that, The storage medium stores at least one program, which is loaded and executed by a processor to implement the request message processing method as described in any one of claims 1 to 7.
17. A computer program product, characterized in that, The computer program product includes computer instructions stored in a computer-readable storage medium, a processor of a computer device reading the computer instructions from the computer-readable storage medium, and the processor executing the computer instructions to cause the computer device to perform the request message processing method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
User login authentication processing method, server and client
CN108881320A
