Remote procedure calling method and device
Through automated generating executable files and HTTP requests, the problem of low manual conversion efficiency in traditional RPC development has been solved, and a more efficient RPC call process is achieved.
Patent Information
- Application Number
- CN202310886122.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-18
- Publication Date
- 2025-01-21
AI Technical Summary
During the traditional RPC development process, it is necessary to manually convert the RPC interface and data types defined in the intermediate language into code files in the corresponding language, which is inefficient.
Provide a remote process call method. By obtaining the Thrift file path and configuration parameters in the configuration file, automatically generate executable files, and automatically generate HTTP requests when receiving trigger instructions. Essence
No need to manually convert the Thrift file, which improves the efficiency of RPC and simplifies the development process.
Smart Images

Figure CN119342083A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a remote procedure call method and device. Background Art
[0002] Thrift is a cross-language service deployment framework that is used to achieve efficient collaboration and joint development among multiple languages. In the development process of Remote Procedure Call Protocol (RPC) based on Thrift, it is first necessary to define the RPC interface and data type based on an intermediate language, and then convert the RPC interface and data type defined in the intermediate language into several server-side code files and client-side code files in the corresponding language, so that the server-side and client-side executable programs can be compiled to meet actual needs when necessary.
[0003] In the traditional RPC development process, it is necessary to manually convert the RPC interface and data types defined in the intermediate language into code files in the corresponding language. However, manually converting the RPC interface and data types defined in the intermediate language into code files in the corresponding language is inefficient. Summary of the invention
[0004] In view of this, an embodiment of the present application provides a remote procedure call method and apparatus for improving the efficiency of RPC.
[0005] In order to achieve the above purpose, the embodiments of the present application provide the following technical solutions:
[0006] In a first aspect, an embodiment of the present application provides an RPC method, which is applied to an RPC calling end device, and the method includes:
[0007] Obtain a configuration file, the configuration file including: a path of a thrift file corresponding to a target RPC and configuration parameters corresponding to the target RPC; the thrift file is used to define a request interface and data type of the target RPC;
[0008] Read the thrift file according to the path of the thrift file;
[0009] Generate an executable file corresponding to the thrift file based on the configuration parameters and the thrift file;
[0010] When receiving a trigger instruction for triggering the target RPC, executing the executable file to generate an HTTP request corresponding to the target RPC;
[0011] The HTTP request is sent to the RPC forwarding end device, so that the RPC forwarding end device converts the HTTP request into an RPC request and sends the target RPC request to the RPC receiving end device.
[0012] As an optional implementation of the embodiment of the present application, the generating of the executable file corresponding to the thrift file based on the configuration parameters and the thrift file includes:
[0013] Convert the thrift file into an abstract syntax tree;
[0014] The abstract syntax tree is converted into the executable file based on the configuration parameters.
[0015] As an optional implementation of the embodiment of the present application, converting the thrift file into an abstract syntax tree includes:
[0016] Performing a lexical scan on the thrift file to obtain at least one data array from the thrift file;
[0017] Performing syntax analysis on the at least one data array to determine a type declaration corresponding to the at least one data array;
[0018] The at least one word array is assembled into the abstract syntax tree according to the type declaration corresponding to the at least one data array.
[0019] As an optional implementation of the embodiment of the present application, the thrift file is a DL file, and the executable file is a Typescript language file; the converting the abstract syntax tree into the executable file based on the configuration parameters includes:
[0020] According to the configuration parameters, the preset conversion rules and the type declaration corresponding to the at least one data array, the at least one data array is converted into a corresponding Typescript language file; the preset conversion rules include conversion rules for converting data arrays of various types into Typescript language files of corresponding types;
[0021] The converted Typescript language files are spliced into the executable file.
[0022] As an optional implementation of the embodiment of the present application, converting the at least one data array into a corresponding Typescript language file according to the configuration parameters, the preset conversion rules and the type declaration corresponding to the at least one data array includes:
[0023] Determining, according to the type declaration corresponding to the at least one data array, a target data array of service type in the at least one data array;
[0024] The target data array is converted into a Typescript language file of class type, the RPC call method in the target data array is transformed into a static method, and the service name corresponding to the target RPC, the method name corresponding to the target RPC, and the call parameters corresponding to the target RPC are injected into the static method.
[0025] As an optional implementation of the embodiment of the present application, before injecting the service name corresponding to the target RPC, the method name corresponding to the target RPC, and the call parameters corresponding to the target RPC into the static method, the method further includes:
[0026] The calling parameters corresponding to the target RPC are obtained from the trigger instruction.
[0027] As an optional implementation of the embodiment of the present application, executing the executable file to generate an HTTP request corresponding to the target RPC includes:
[0028] The executable file is executed to generate the HTTP request carrying the method name corresponding to the target RPC, the service name corresponding to the target RPC, and the call parameters corresponding to the target RPC.
[0029] In a second aspect, an embodiment of the present application provides an RPC method, which is applied to an RPC forwarding end device, and the method includes:
[0030] Detect the HTTP request sent by the RPC caller;
[0031] When an HTTP request sent by the RPC calling end is detected, converting the HTTP request into a target RPC request corresponding to the HTTP request;
[0032] The target RPC request is sent to the RPC receiving device.
[0033] As an optional implementation of the embodiment of the present application, the HTTP request carries a method name corresponding to the target RPC, a service name corresponding to the target RPC, and a call parameter corresponding to the target RPC, and converting the HTTP request into a target RPC request corresponding to the HTTP request includes:
[0034] According to the method name corresponding to the target RPC and the service name corresponding to the target RPC, obtain the target RPC method corresponding to the target RPC;
[0035] The target RPC request is generated according to the target RPC method and the call parameters corresponding to the target RPC.
[0036] As an optional implementation of the embodiment of the present application, before obtaining the target RPC method corresponding to the target RPC according to the method name corresponding to the target RPC and the service name corresponding to the target RPC, the method further includes:
[0037] The RPC method corresponding to each RPC is preconfigured in the RPC forwarding end device.
[0038] In a third aspect, an embodiment of the present application provides an RPC calling end device, including:
[0039] An acquisition module is used to read a configuration file, wherein the configuration file includes: a path of a thrift file corresponding to a target RPC and configuration parameters corresponding to the target RPC; the thrift file is used to define a request interface and a data type of the target RPC;
[0040] A reading module, used for reading the thrift file according to the path of the thrift file;
[0041] A generation module, used for generating an executable file corresponding to the thrift file based on the configuration parameters and the thrift file;
[0042] an execution unit, configured to execute the executable file upon receiving a trigger instruction for triggering the target RPC, so as to generate an HTTP request corresponding to the target RPC;
[0043] The sending unit is used to send the HTTP request to the RPC forwarding end device, so that the RPC forwarding end device converts the HTTP request into an RPC request and sends the target RPC request to the RPC receiving end device.
[0044] As an optional implementation of the embodiment of the present application, the generation module is specifically used to convert the thrift file into an abstract syntax tree; and convert the abstract syntax tree into the executable file based on the configuration parameters.
[0045] As an optional implementation of an embodiment of the present application, the generation module is specifically used to perform lexical scanning on the thrift file to obtain at least one data array from the thrift file; perform syntax analysis on the at least one data array to determine the type declaration corresponding to the at least one data array; and assemble the at least one word array into the abstract syntax tree according to the type declaration corresponding to the at least one data array.
[0046] As an optional implementation of the embodiment of the present application, the thrift file is an interface definition language IDL file, and the executable file is a Typescript language file;
[0047] The generation module is specifically used to convert the at least one data array into a corresponding Typescript language file according to the configuration parameters, the preset conversion rules and the type declaration corresponding to the at least one data array; the preset conversion rules include conversion rules for converting each type of data array into a corresponding type of Typescript language file; and the converted Typescript language files are spliced into the executable file.
[0048] As an optional implementation of an embodiment of the present application, the generation unit is specifically used to determine a target data array of service type in the at least one data array according to the type declaration corresponding to the at least one data array; convert the target data array into a Typescript language file of class type, transform the RPC call method in the target data array into a static method, and inject the service name corresponding to the target RPC, the method name corresponding to the target RPC, and the call parameters corresponding to the target RPC into the static method.
[0049] As an optional implementation of an embodiment of the present application, the generation unit is also used to obtain the calling parameters corresponding to the target RPC from the trigger instruction before injecting the service name corresponding to the target RPC, the method name corresponding to the target RPC and the calling parameters corresponding to the target RPC into the static method.
[0050] As an optional implementation of the embodiment of the present application, the execution unit is specifically used to execute the executable file to generate the HTTP request carrying the method name corresponding to the target RPC, the service name corresponding to the target RPC, and the calling parameters corresponding to the target RPC.
[0051] In a fourth aspect, an embodiment of the present application provides an RPC forwarding end device, including:
[0052] A detection unit, used for detecting the HTTP request sent by the RPC calling end;
[0053] A conversion unit, configured to, when detecting an HTTP request sent by the RPC calling end, convert the HTTP request into a target RPC request corresponding to the HTTP request;
[0054] The sending unit is used to send the target RPC request to the RPC receiving device.
[0055] As an optional implementation of the embodiment of the present application, the HTTP request carries the method name corresponding to the target RPC, the service name corresponding to the target RPC, and the call parameters corresponding to the target RPC;
[0056] The conversion unit is specifically used to obtain the target RPC method corresponding to the target RPC according to the method name corresponding to the target RPC and the service name corresponding to the target RPC; and generate the target RPC request according to the target RPC method and the calling parameters corresponding to the target RPC.
[0057] As an optional implementation of the embodiment of the present application, the conversion unit is also used to pre-configure the RPC methods corresponding to each RPC in the RPC forwarding end device before obtaining the target RPC method corresponding to the target RPC based on the method name corresponding to the target RPC and the service name corresponding to the target RPC.
[0058] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising: a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to enable the electronic device to implement the RPC method described in any of the above embodiments when executing the computer program.
[0059] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, which, when the computer program is executed by a computing device, enables the computing device to implement the RPC method described in any of the above-mentioned embodiments.
[0060] In a seventh aspect, an embodiment of the present application provides a computer program product, which, when executed on a computer, enables the computer to implement the RPC method described in any one of the above-mentioned embodiments.
[0061] In the RPC method provided in the embodiment of the present application, a configuration file including the path of the thrift file corresponding to the target RPC and the configuration parameters corresponding to the target RPC is first obtained, and then the thrift file is read according to the path of the thrift file, and then an executable file corresponding to the thrift file is generated based on the configuration parameters and the thrift file, and when a trigger instruction for triggering the target RPC is received, the executable file is executed to generate an HTTP request corresponding to the target RPC and send the HTTP request to the RPC forwarding end device, so that the RPC forwarding end device converts the HTTP request into an RPC request and sends the target RPC request to the RPC receiving end device. Since the RPC method provided in the embodiment of the present application can automatically generate an HTTP request corresponding to the target RPC when receiving a trigger instruction for triggering the target RPC, and send the HTTP request to the RPC forwarding end device, so that the RPC forwarding end device converts the HTTP request into an RPC request and sends the target RPC request to the RPC receiving end device, the RPC method provided in the embodiment of the present application does not require the user to manually convert the thrift file corresponding to the target RPC into a code file of the corresponding language, so the RPC method provided in the embodiment of the present application can improve the efficiency of RPC. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0063] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings required in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0064] Figure 1 A scenario architecture diagram of the RPC method provided in the embodiment of the present application;
[0065] Figure 2 An interactive flow chart of the RPC method provided in the embodiment of the present application;
[0066] Figure 3 A schematic diagram of the structure of the RPC calling end device provided in the embodiment of the present application;
[0067] Figure 4 A schematic diagram of the structure of an RPC forwarding terminal device provided in an embodiment of the present application;
[0068] Figure 5A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0069] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the scheme of the present application will be further described below. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.
[0070] In the following description, many specific details are set forth to facilitate a full understanding of the present application, but the present application may also be implemented in other ways different from those described herein. Obviously, the embodiments in the specification are only part of the embodiments of the present application, rather than all of the embodiments.
[0071] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete way. In addition, in the description of the embodiments of the present application, unless otherwise specified, the meaning of "multiple" refers to two or more.
[0072] RPC refers to remote procedure call. When there are two servers, an application is deployed on one of the servers. If you want to call the function / method provided by the application on the other server, since they are not in the same memory space, they cannot be called directly. The semantics of the call and the data of the call need to be expressed through the network, and this process is RPC.
[0073] The following first describes the scenario architecture of the RPC method provided in the embodiment of the present application.
[0074] Reference Figure 1 As shown, the scenario architecture of the RPC method provided in the embodiment of the present application includes: an RPC calling end device 10, an RPC forwarding end device 20 and an RPC receiving end device 30.
[0075] Among them, the RPC calling end device 10 is a device that initiates a remote procedure call; the RPC forwarding end device 20 is a device that converts and transfers the communication information between the RPC calling end device 10 and the RPC receiving end device 30 during the remote procedure call process; the RPC receiving end device 30 is a device that accepts remote procedure calls.
[0076] In the process of remote procedure call, the RPC calling end device 10 is mainly used to obtain a configuration file including the path of the thrift file corresponding to the RPC and the configuration parameters corresponding to the RPC, read the thrift file according to the path of the thrift file, generate an executable file corresponding to the thrift file based on the configuration parameters and the thrift file, and when receiving a trigger instruction for triggering the RPC, execute the executable file to send the HTTP request to the RPC forwarding end device 20. The RPC forwarding end device 20 is mainly used to convert the HTTP request sent by the RPC calling end 10 into a corresponding RPC request when receiving the HTTP request, and send the RPC request to the RPC receiving end device 30. The RPC receiving end device is mainly used to call the corresponding function or method in response to the RPC request to obtain the call result of the remote procedure call, and return the call result of the remote procedure call to the RPC calling end 10 through the RPC forwarding end device 20.
[0077] The present application embodiment provides an RPC method, referring to Figure 2 As shown, the RPC method includes the following steps S201 to S207:
[0078] S201, the RPC calling end device obtains a configuration file.
[0079] The configuration file includes: a path of a thrift file corresponding to the target RPC and configuration parameters corresponding to the target RPC; the thrift file is used to define a request interface and data type of the target RPC.
[0080] That is, the configuration file in the embodiment of the present application includes two parts, one part is the thrift file corresponding to the target RPC, which is used to specify the reading path of the thrift file, and the other part is the configuration parameters corresponding to the target RPC, which are used to intervene in the parsing of the thrift file and the generation of the executable file.
[0081] In some embodiments, the thrift file in the embodiments of the present application may be a file written based on an Interface Definition Language (IDL).
[0082] In some embodiments, the configuration file may also include multiple personalized configurations, such as whether a signed 64-bit integer (int64) is converted into a string or a number, whether a map type is converted into an object, etc.
[0083] In the embodiment of the present application, the configuration parameters corresponding to the target RPC mainly include two parts, one part is idlOptions, and the other part is tslOptions. IdlOptions is used to intervene in the parsing of thrift files, and tsOptions is used to intervene in the generation of executable files.
[0084] Furthermore, the configuration items of idlOptions can be shown in Table 1 below, and the configuration items of tslOptions can be shown in Table 2 below:
[0085] Table 1
[0086] Configuration items type illustrate idlRootDir string The root path of the interface description language file guluRootDir String The root path of the gulu project, automatically parsing the configuration file outDir String Path to the output file int64 String innt64 type, default is value (number) constEnum Boolean Whether to generate a constant enumeration (const enum), the default is no ignoreEnumZeroOctal Boolean Whether to ignore the leading 0 in the enumeration value to indicate octal binary String Binary type, default is string mapAsobject Boolean Whether to convert the map into an object, the default is no setAsArray Boolean Whether to convert the set (Set) into a matrix (Array), the default is no ignoreStructFieldName Regular Expressions Struct field names matching this regular expression will be ignored. defaultRequiredness Structure The default requirement rules are official by default. searchPaths String Binary type, default is string exportDeps Boolean Whether to export dependencies InterfacePrefix String You can add prefixes to structures optionalBase Boolean Whether to set the base type to any type, the default is yes prettirr Boolean prettirr format, default is yes guluConfigFolders String Parse the configuration file name of the gulu project
[0087] Table 2
[0088] Configuration items type illustrate rpcUrl string rpc routing address customRequest function Custom injected front-end function that calls the rpc method commonParams Record<string, matrix> Common parameters are automatically injected into all methods and can be overridden customMethodParams Record<string, matrix> Custom parameters, which are injected into specific methods in advance and can be overwritten
[0089] S202: The RPC calling end device reads the thrift file according to the path of the thrift file.
[0090] In some embodiments, the implementation of reading the thrift file according to the path of the thrift file includes: reading all files with a suffix of .thrift under the path of the thrift file.
[0091] S203: The RPC calling end device generates an executable file corresponding to the thrift file based on the configuration parameters and the thrift file.
[0092] In some embodiments, the above step S203 (generating an executable file corresponding to the thrift file based on the configuration parameters and the thrift file) includes the following steps a and b:
[0093] Step a: converting the thrift file into an Abstract Syntax Tree (AST).
[0094] In some embodiments, the above step a (converting the thrift file into an abstract syntax tree) includes the following steps a1 to a3:
[0095] Step a1: perform lexical scanning on the thrift file to obtain at least one data array (Token) from the thrift file.
[0096] Step a2: perform syntax analysis on the at least one data array to determine a type declaration corresponding to the at least one data array.
[0097] Step a3: assembling the at least one word array into the abstract syntax tree according to the type declaration corresponding to the at least one data array.
[0098] That is, first perform a lexical scan on the thrift file, convert the original file into a Token array, then perform syntax analysis on these Tokens, assemble the Tokens according to the declaration (Definition) provided by the thrift file, and finally output the abstract syntax tree.
[0099] Step b: converting the abstract syntax tree into the executable file based on the configuration parameters.
[0100] In some embodiments, the abstract syntax tree is converted into the executable file based on the configuration parameters. The above step b (converting the abstract syntax tree into the executable file based on the configuration parameters) includes the following steps b1 and b2:
[0101] Step b1: convert the at least one data array into a corresponding Typescript language file according to the configuration parameters, the preset conversion rules and the type declaration corresponding to the at least one data array.
[0102] The preset conversion rules include conversion rules for converting data arrays of various types into Typescript language files of corresponding types.
[0103] In some embodiments, the preset conversion rules include the following:
[0104] 1. Convert the enumeration type in the thrift file to the enumeration type in the Typescript language, that is, enum->enum.
[0105] 2. Convert the structure type in the thrift file to the interface type in the Typescript language, that is, struct->interface.
[0106] 3. Convert the type definition (typedef) in the thrift file to the type in the Typescript language, that is, typedef->type.
[0107] 4. Convert the constant (const) type in the thrift file to the constant (const) type in the Typescript language, that is, const->const.
[0108] 5. Convert the service type in the thrift file to the class type in Typescript, i.e. service->class.
[0109] In some embodiments, step b1 (converting the at least one data array into a corresponding Typescript language file according to the configuration parameters, the preset conversion rules, and the type declaration corresponding to the at least one data array) includes the following steps b11 and b12:
[0110] Step b11: Determine a target data array of service type in the at least one data array according to the type declaration corresponding to the at least one data array.
[0111] That is, the target data array in the embodiment of the present application is a data array of service type.
[0112] Step b12: convert the target data array into a Typescript language file of class type, transform the RPC call method in the target data array into a static method, and inject the service name (serviceName) corresponding to the target RPC, the method name (methodName) corresponding to the target RPC, and the call parameters (params) corresponding to the target RPC into the static method.
[0113] Step b2: splicing the converted Typescript language files into the executable file.
[0114] Since the preset conversion rules include the five declarations of enum, struct, typedef, const, and service in the thrift file, and convert these five declarations into corresponding ts type declarations, and this conversion is done based on the abstract syntax tree as a bridge, the structure of the abstract syntax tree can clearly indicate: type, name, value, location, comment and other information, so the Typescript language file can be obtained by splicing this information one by one.
[0115] S204. When receiving a trigger instruction for triggering the target RPC, the RPC calling end device executes the executable file to generate an HTTP request corresponding to the target RPC.
[0116] S205: The RPC calling end device sends the HTTP request to the RPC forwarding end device.
[0117] Correspondingly, the RPC forwarding end device receives the HTTP request sent by the RPC calling end device.
[0118] S206: The RPC forwarding end device converts the HTTP request into a target RPC request corresponding to the HTTP request.
[0119] All HTTP requests carry three parameters: method name, service name, and call parameters. If an HTTP request is received, the unique RPC method can be identified based on the method name and service name, and the call parameters are used as the parameters of the RPC request to generate a new RPC request, thus completing the conversion process from HTTP request to RPC request.
[0120] That is, the implementation method of the above step S206 (converting the HTTP request into a target RPC request corresponding to the HTTP request) includes the following steps 1 and 2:
[0121] Step 1: Obtain the target RPC method corresponding to the target RPC according to the method name corresponding to the target RPC and the service name corresponding to the target RPC.
[0122] Step 2: Generate the target RPC request according to the target RPC method and the call parameters corresponding to the target RPC.
[0123] That is, the call parameters corresponding to the target RPC are injected into the target RPC method to generate the target RPC request.
[0124] In some embodiments, the RPC method provided by the embodiments of the present application also includes: pre-configuring RPC methods corresponding to each RPC in the RPC forwarding end device, so that the RPC forwarding end device obtains the target RPC method corresponding to the target RPC according to the method name corresponding to the target RPC and the service name corresponding to the target RPC, and obtains the target RPC method from the pre-configured RPC methods corresponding to each RPC.
[0125] S207: The RPC forwarding end device sends the target RPC request to the RPC receiving end device.
[0126] Correspondingly, the RPC receiving device receives the RPC request sent by the RPC forwarding device.
[0127] In the RPC method provided in the embodiment of the present application, a configuration file including the path of the thrift file corresponding to the target RPC and the configuration parameters corresponding to the target RPC is first obtained, and then the thrift file is read according to the path of the thrift file, and then an executable file corresponding to the thrift file is generated based on the configuration parameters and the thrift file, and when a trigger instruction for triggering the target RPC is received, the executable file is executed to generate an HTTP request corresponding to the target RPC and send the HTTP request to the RPC forwarding end device, so that the RPC forwarding end device converts the HTTP request into an RPC request and sends the target RPC request to the RPC receiving end device. Since the RPC method provided in the embodiment of the present application can automatically generate an HTTP request corresponding to the target RPC when receiving a trigger instruction for triggering the target RPC, and send the HTTP request to the RPC forwarding end device, so that the RPC forwarding end device converts the HTTP request into an RPC request and sends the target RPC request to the RPC receiving end device, the RPC method provided in the embodiment of the present application does not require the user to manually convert the thrift file corresponding to the target RPC into a code file of the corresponding language, so the RPC method provided in the embodiment of the present application can improve the efficiency of RPC.
[0128] Based on the same inventive concept, as an implementation of the above method, the embodiment of the present application also provides an RPC calling end device and an RPC forwarding end device. This embodiment corresponds to the aforementioned method embodiment. For ease of reading, this embodiment will no longer repeat the details of the aforementioned method embodiment one by one, but it should be clear that the RPC calling end device and the RPC forwarding end device in this embodiment can correspond to all the contents in the aforementioned method embodiment.
[0129] The present application embodiment provides an RPC calling end device, Figure 3 This is a schematic diagram of the structure of the RPC calling end device, such as Figure 3 As shown, the RPC calling end device 300 includes:
[0130] The acquisition module 31 is used to read a configuration file, wherein the configuration file includes: a path of a thrift file corresponding to a target RPC and configuration parameters corresponding to the target RPC; the thrift file is used to define a request interface and a data type of the target RPC;
[0131] A reading module 32, used for reading the thrift file according to the path of the thrift file;
[0132] A generating module 33, used for generating an executable file corresponding to the thrift file based on the configuration parameters and the thrift file;
[0133] An execution unit 34 is used to execute the executable file to generate an HTTP request corresponding to the target RPC when receiving a trigger instruction for triggering the target RPC;
[0134] The sending unit 35 is used to send the HTTP request to the RPC forwarding end device, so that the RPC forwarding end device converts the HTTP request into an RPC request and sends the target RPC request to the RPC receiving end device.
[0135] As an optional implementation of the embodiment of the present application, the generating module 33 is specifically used to convert the thrift file into an abstract syntax tree; and convert the abstract syntax tree into the executable file based on the configuration parameters.
[0136] As an optional implementation of an embodiment of the present application, the generation module 33 is specifically used to perform lexical scanning on the thrift file to obtain at least one data array from the thrift file; perform syntax analysis on the at least one data array to determine the type declaration corresponding to the at least one data array; and assemble the at least one word array into the abstract syntax tree according to the type declaration corresponding to the at least one data array.
[0137] As an optional implementation of the embodiment of the present application, the thrift file is an interface definition language IDL file, and the executable file is a Typescript language file;
[0138] The generation module 33 is specifically used to convert the at least one data array into a corresponding Typescript language file according to the configuration parameters, the preset conversion rules and the type declaration corresponding to the at least one data array; the preset conversion rules include conversion rules for converting each type of data array into a corresponding type of Typescript language file; and splicing the converted Typescript language files into the executable file.
[0139] As an optional implementation of an embodiment of the present application, the generation unit 33 is specifically used to determine a target data array of service type in the at least one data array according to the type declaration corresponding to the at least one data array; convert the target data array into a Typescript language file of class type, transform the RPC call method in the target data array into a static method, and inject the service name corresponding to the target RPC, the method name corresponding to the target RPC, and the call parameters corresponding to the target RPC into the static method.
[0140] As an optional implementation of an embodiment of the present application, the generation unit 33 is also used to obtain the calling parameters corresponding to the target RPC from the trigger instruction before injecting the service name corresponding to the target RPC, the method name corresponding to the target RPC and the calling parameters corresponding to the target RPC into the static method.
[0141] As an optional implementation of the embodiment of the present application, the execution unit 34 is specifically used to execute the executable file to generate the HTTP request carrying the method name corresponding to the target RPC, the service name corresponding to the target RPC, and the calling parameters corresponding to the target RPC.
[0142] The present application embodiment provides an RPC forwarding terminal device, Figure 4 This is a schematic diagram of the structure of the RPC forwarding end device, such as Figure 4 As shown, the RPC forwarding end device 400 includes:
[0143] A detection unit 41, configured to detect the HTTP request sent by the RPC call end;
[0144] The conversion unit 42 is used for converting the HTTP request sent by the RPC calling end into a target RPC request corresponding to the HTTP request when the HTTP request is detected;
[0145] The sending unit 43 is used to send the target RPC request to the RPC receiving device.
[0146] As an optional implementation of the embodiment of the present application, the HTTP request carries the method name corresponding to the target RPC, the service name corresponding to the target RPC, and the call parameters corresponding to the target RPC;
[0147] The conversion unit 42 is specifically used to obtain the target RPC method corresponding to the target RPC according to the method name corresponding to the target RPC and the service name corresponding to the target RPC; and generate the target RPC request according to the target RPC method and the call parameters corresponding to the target RPC.
[0148] As an optional implementation of the embodiment of the present application, the conversion unit 42 is also used to pre-configure the RPC methods corresponding to each RPC in the RPC forwarding end device before obtaining the target RPC method corresponding to the target RPC based on the method name corresponding to the target RPC and the service name corresponding to the target RPC.
[0149] The RPC calling end device and the RPC forwarding end device provided in this embodiment can execute the RPC method provided in the above method embodiment. The implementation principle and technical effect are similar and will not be repeated here.
[0150] Based on the same inventive concept, an embodiment of the present application also provides an electronic device. Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Figure 5 As shown, the electronic device provided in this embodiment includes: a memory 501 and a processor 502, wherein the memory 501 is used to store a computer program, and the processor 502 is used to execute the RPC method provided in the above embodiment when executing the computer program.
[0151] Based on the same inventive concept, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the computing device implements the RPC method provided in the above embodiment.
[0152] Based on the same inventive concept, an embodiment of the present application further provides a computer program product. When the computer program product is run on a computer, the computing device implements the RPC method provided in the above embodiment.
[0153] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media that include computer-usable program code.
[0154] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0155] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0156] Computer readable media include permanent and non-permanent, removable and non-removable storage media. Storage media can be implemented by any method or technology to store information, and the information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0157] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some or all of the technical features therein, and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A remote procedure call (RPC) method, characterized in that: Applied to an RPC calling end device, the method comprises: Obtain a configuration file, the configuration file including: a path of a thrift file corresponding to a target RPC and configuration parameters corresponding to the target RPC; the thrift file is used to define a request interface and data type of the target RPC; Read the thrift file according to the path of the thrift file; Generate an executable file corresponding to the thrift file based on the configuration parameters and the thrift file; When receiving a trigger instruction for triggering the target RPC, executing the executable file to generate a Hypertext Transfer Protocol HTTP request corresponding to the target RPC; The HTTP request is sent to the RPC forwarding end device, so that the RPC forwarding end device converts the HTTP request into an RPC request and sends the target RPC request to the RPC receiving end device.
2. The method according to claim 1, characterized in that The generating an executable file corresponding to the thrift file based on the configuration parameters and the thrift file includes: Convert the thrift file into an abstract syntax tree; The abstract syntax tree is converted into the executable file based on the configuration parameters.
3. The method according to claim 2, characterized in that The step of converting the thrift file into an abstract syntax tree comprises: Performing a lexical scan on the thrift file to obtain at least one data array from the thrift file; Performing syntax analysis on the at least one data array to determine a type declaration corresponding to the at least one data array; The at least one word array is assembled into the abstract syntax tree according to the type declaration corresponding to the at least one data array.
4. The method according to claim 3, characterized in that The thrift file is an interface definition language IDL file, and the executable file is a Typescript language file; and converting the abstract syntax tree into the executable file based on the configuration parameters includes: According to the configuration parameters, the preset conversion rules and the type declaration corresponding to the at least one data array, the at least one data array is converted into a corresponding Typescript language file; the preset conversion rules include conversion rules for converting data arrays of various types into Typescript language files of corresponding types; The converted Typescript language files are spliced into the executable file.
5. The method according to claim 4, characterized in that The converting the at least one data array into a corresponding Typescript language file according to the configuration parameters, the preset conversion rules, and the type declaration corresponding to the at least one data array includes: Determining, according to the type declaration corresponding to the at least one data array, a target data array of service type in the at least one data array; The target data array is converted into a Typescript language file of class type, the RPC call method in the target data array is transformed into a static method, and the service name corresponding to the target RPC, the method name corresponding to the target RPC, and the call parameters corresponding to the target RPC are injected into the static method.
6. The method according to claim 5, characterized in that Before injecting the service name corresponding to the target RPC, the method name corresponding to the target RPC, and the call parameters corresponding to the target RPC into the static method, the method further includes: The calling parameters corresponding to the target RPC are obtained from the trigger instruction.
7. The method according to claim 5, characterized in that The executing the executable file to generate an HTTP request corresponding to the target RPC includes: The executable file is executed to generate the HTTP request carrying the method name corresponding to the target RPC, the service name corresponding to the target RPC, and the call parameters corresponding to the target RPC.
8. A remote procedure call (RPC) method, characterized in that: Applied to an RPC forwarding end device, the method comprises: Detect the HTTP request sent by the RPC caller; When an HTTP request sent by the RPC calling end is detected, converting the HTTP request into a target RPC request corresponding to the HTTP request; The target RPC request is sent to the RPC receiving device.
9. The method according to claim 8, characterized in that The HTTP request carries a method name corresponding to the target RPC, a service name corresponding to the target RPC, and a call parameter corresponding to the target RPC, and converting the HTTP request into a target RPC request corresponding to the HTTP request includes: According to the method name corresponding to the target RPC and the service name corresponding to the target RPC, obtain the target RPC method corresponding to the target RPC; The target RPC request is generated according to the target RPC method and the call parameters corresponding to the target RPC.
10. The method according to claim 8, characterized in that Before acquiring the target RPC method corresponding to the target RPC according to the method name corresponding to the target RPC and the service name corresponding to the target RPC, the method further includes: The RPC method corresponding to each RPC is preconfigured in the RPC forwarding end device.
11. A remote procedure call (RPC) calling end device, characterized in that: include: An acquisition module is used to read a configuration file, wherein the configuration file includes: a path of a thrift file corresponding to a target RPC and configuration parameters corresponding to the target RPC; the thrift file is used to define a request interface and a data type of the target RPC; A reading module, used for reading the thrift file according to the path of the thrift file; A generation module, used for generating an executable file corresponding to the thrift file based on the configuration parameters and the thrift file; an execution unit, configured to execute the executable file upon receiving a trigger instruction for triggering the target RPC, so as to generate an HTTP request corresponding to the target RPC; The sending unit is used to send the HTTP request to the RPC forwarding end device, so that the RPC forwarding end device converts the HTTP request into an RPC request and sends the target RPC request to the RPC receiving end device.
12. A remote procedure call (RPC) forwarding terminal device, characterized in that: include: A detection unit, used for detecting the HTTP request sent by the RPC calling end; A conversion unit, configured to, when detecting an HTTP request sent by the RPC calling end, convert the HTTP request into a target RPC request corresponding to the HTTP request; The sending unit is used to send the target RPC request to the RPC receiving device.
13. An electronic device, characterized in that: include: A memory and a processor, wherein the memory is used to store a computer program and the processor is used to enable the electronic device to implement the RPC method described in any one of claims 1 to 10 when executing the computer program.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a computing device, the computing device implements the RPC method according to any one of claims 1 to 10.