Remote procedure call method, apparatus, device and readable storage medium
By introducing an HTTP interface conversion layer and JSON format transmission into the RPC service, the adaptability, compatibility, and language limitations of the RPC framework are resolved, achieving unified cross-framework calls and strong compatibility.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WUHAN FIBERHOME TECHNICAL SERVICES CO LTD
- Filing Date
- 2022-08-02
- Publication Date
- 2026-07-07
AI Technical Summary
Existing RPC frameworks have limitations in adaptability, compatibility, and language in remote procedure calls, resulting in incompatibility between the caller and the called party in terms of transport protocols, message models, and language support, leading to call failures.
By providing a generic proxy layer on top of the original RPC service, the RPC interface is converted into an HTTP interface, and messages are transmitted using JSON format strings. This shields the differences in transport protocols and message models, and allows the use of a unified HTTP interface to call services from different RPC frameworks.
It enables unified calls across RPC frameworks, resolves language and model limitations of RPC frameworks, improves compatibility and adaptability between callers and callees, supports calls to multiple server versions, and has stronger compatibility and firewall penetration capabilities.
Smart Images

Figure CN115408169B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of telecommunications network management, and in particular to a remote procedure call method, apparatus, device, and readable storage medium. Background Technology
[0002] RPC (Remote Procedure Call) is a protocol that allows a program on a remote computer to request services over a network without needing to understand the underlying network technology. For example, an application deployed on server A wants to call a function / method provided by an application on server B. Because the caller and the callee are not in the same memory space, a direct call is not possible. Instead, the semantics of the call and the data to be called need to be expressed over the network; this is the method of RPC.
[0003] The primary goal of RPC is to make building distributed computing (applications) easier, providing powerful remote call capabilities without sacrificing the semantic simplicity of local calls. To achieve this, RPC frameworks need to provide a transparent calling mechanism so that users don't need to explicitly distinguish between local and remote calls. Currently, RPC is widely used in the construction of system environments and application design in distributed systems. There are also many mainstream RPC frameworks in the industry, such as Alibaba's Dubbo, Facebook's Thrift, Google's gRpc, and ZeroC's ICE, etc.
[0004] However, existing methods for remote procedure calls based on RPC interfaces have the following problems:
[0005] (1) Adaptability Limitations: When the caller and the called party use different RPC frameworks, due to differences in the transport protocols and message models of different RPC frameworks, the caller cannot directly call the called party. Instead, it must introduce a client of the framework used by the called party before it can execute calls to the corresponding services of the called party, such as... Figure 1 The client must introduce the RPC client of the server-side RPC framework in order to request services from the server-side RPC server based on the RPC communication protocol;
[0006] (2) Compatibility limitations: When the caller and the called party use the same RPC framework, the RPC framework generates a message model in the corresponding language based on the protocol file, and the attributes and methods of this model are directly manipulated in the application layer. If one party upgrades its message model while the other does not, the client used by the caller and the client used by the called party (relative to the caller, this client is the server) will be incompatible. In this case, parsing the message model in the application layer will fail, resulting in incompatibility.
[0007] (3) Language restrictions: If the RPC framework used by the called party supports languages 1, 2, 3, and 4, and the caller happens to use language 5, then the caller cannot use the same RPC framework to make calls to the corresponding services of the called party. Summary of the Invention
[0008] The main objective of this invention is to provide a remote procedure call method, apparatus, device, and readable storage medium, aiming to solve the technical problems of adaptability, compatibility, and language limitations that exist in existing remote procedure calls based on RPC frameworks.
[0009] In a first aspect, the present invention provides a remote procedure call method, the remote procedure call method comprising the following steps:
[0010] When a client sends a call request to the web service based on the HTTP protocol, the first input parameter corresponding to the call request is extracted. The first input parameter includes the RPC interface name and RPC interface input parameters corresponding to the server. The first input parameter is a JSON format string.
[0011] Convert the first input parameter from a JSON format string to the first RPC protocol model;
[0012] Based on the RPC interface name and the first RPC protocol model, the client of the corresponding RPC framework calls the corresponding RPC service on the server to obtain the second RPC protocol model, which includes output parameters and return values.
[0013] The second RPC protocol model is converted into a JSON format string and returned to the web service, which then returns it to the client based on the HTTP protocol.
[0014] Optionally, the step of converting the first input parameter from a JSON format string to a first RPC protocol model includes:
[0015] Convert the first input parameter from a JSON format string into the first general model;
[0016] The RPC interface input parameters in the first general model are converted into the first RPC protocol model.
[0017] Optionally, before the step of extracting the first input parameter corresponding to the call request when a client triggers a call request to the Web service based on the HTTP protocol, the method further includes:
[0018] Write the RPC protocol files corresponding to each RPC framework based on the preset file specifications;
[0019] Determine the corresponding RPC protocol parser based on the RPC framework;
[0020] The RPC protocol file corresponding to the RPC framework is parsed using an RPC protocol parser, and a general protocol file is generated based on the parsing results. The general protocol file is used to record the RPC interface corresponding to the RPC framework, and the input parameters, output parameters, return value data types, and attribute definitions of the corresponding RPC protocol model.
[0021] Optionally, the step of converting the second RPC protocol model into a JSON format string includes:
[0022] The second RPC protocol model, which includes output parameters and return values, is converted into a second general model.
[0023] Convert the second general model into a JSON format string.
[0024] Optionally, the step of converting the second RPC protocol model, which includes output parameters and return values, into a second general model includes:
[0025] Create a general model;
[0026] Based on the general protocol file, the data types and attribute definitions of output parameters and return values in the second RPC protocol model are identified;
[0027] Based on the conversion rules for the data types of output parameters and return values, the output parameters and return values in the second RPC protocol model are converted into a MAP structure;
[0028] The output parameters and return values of the MAP structure are filled into the corresponding fields in the general model to obtain the second general model.
[0029] Optionally, the web service is implemented based on the Java Spring Boot framework and provides an HTTP POST interface to the outside world. The input and output parameters of the POST interface adopt JSON format strings corresponding to a general model.
[0030] Secondly, the present invention also provides a remote procedure call apparatus, the remote procedure call apparatus comprising:
[0031] The extraction module is used to extract the first input parameter corresponding to the call request when a client triggers a call request to the Web service based on the HTTP protocol. The first input parameter includes the RPC interface name and RPC interface input parameters corresponding to the server. The first input parameter is a JSON format string.
[0032] The first conversion module is used to convert the first input parameter from a JSON format string into a first RPC protocol model;
[0033] The calling module is used to call the corresponding RPC service of the server using the client of the corresponding RPC framework based on the RPC interface name and the first RPC protocol model, and obtain the second RPC protocol model including output parameters and return values.
[0034] The second conversion module is used to convert the second RPC protocol model into a JSON format string, return it to the Web service, and then return it to the client based on the HTTP protocol.
[0035] Optionally, the first conversion module is specifically used for:
[0036] Convert the first input parameter from a JSON format string into the first general model;
[0037] The RPC interface input parameters in the first general model are converted into the first RPC protocol model.
[0038] Optionally, the remote procedure call apparatus further includes a generation module for:
[0039] Write the RPC protocol files corresponding to each RPC framework based on the preset file specifications;
[0040] Determine the corresponding RPC protocol parser based on the RPC framework;
[0041] The RPC protocol file corresponding to the RPC framework is parsed using an RPC protocol parser, and a general protocol file is generated based on the parsing results. The general protocol file is used to record the RPC interface corresponding to the RPC framework, and the input parameters, output parameters, return value data types, and attribute definitions of the corresponding RPC protocol model.
[0042] Optionally, the second conversion module is specifically used for:
[0043] The second RPC protocol model, which includes output parameters and return values, is converted into a second general model.
[0044] Convert the second general model into a JSON format string.
[0045] Optionally, the second conversion module is further specifically used for:
[0046] Create a general model;
[0047] Based on the general protocol file, the data types and attribute definitions of output parameters and return values in the second RPC protocol model are identified;
[0048] Based on the conversion rules for the data types of output parameters and return values, the output parameters and return values in the second RPC protocol model are converted into a MAP structure;
[0049] The output parameters and return values of the MAP structure are filled into the corresponding fields in the general model to obtain the second general model.
[0050] Optionally, the web service is implemented based on the Java Spring Boot framework and provides an HTTP POST interface to the outside world. The input and output parameters of the POST interface adopt JSON format strings corresponding to a general model.
[0051] Thirdly, the present invention also provides a remote procedure call device, the remote procedure call device including a processor, a memory, and a remote procedure call program stored in the memory and executable by the processor, wherein when the remote procedure call program is executed by the processor, it implements the steps of the remote procedure call method as described above.
[0052] Fourthly, the present invention also provides a readable storage medium storing a remote procedure call program, wherein when the remote procedure call program is executed by a processor, it implements the steps of the remote procedure call method as described above.
[0053] This invention provides a remote procedure call method, apparatus, device, and readable storage medium. The remote procedure call method includes: upon receiving a call request triggered by a client to a web service based on the HTTP protocol, extracting a first input parameter corresponding to the call request, the first input parameter including the RPC interface name and RPC interface input parameters corresponding to the server, the first input parameter being a JSON format string; converting the first input parameter from the JSON format string into a first RPC protocol model; based on the RPC interface name and the first RPC protocol model, using a client of the corresponding RPC framework to call the corresponding RPC service of the server, obtaining a second RPC protocol model including output parameters and return values; converting the second RPC protocol model into a JSON format string, returning it to the web service, and then returning it to the client based on the HTTP protocol. This invention provides a general proxy layer on top of the original RPC service, converting the RPC interface into an HTTP interface to provide services externally, thus no longer being limited by the language and model restrictions of the RPC framework. Attached Figure Description
[0054] Figure 1 This is a flowchart illustrating an embodiment of a prior art remote procedure call method.
[0055] Figure 2 This is a schematic diagram of the hardware structure of the remote procedure call device involved in the embodiments of the present invention;
[0056] Figure 3 This is a flowchart illustrating an embodiment of the remote procedure call method of the present invention;
[0057] Figure 4 This is a flowchart illustrating another embodiment of the remote procedure call method of the present invention;
[0058] Figure 5 This is a schematic diagram of the functional modules of an embodiment of the remote procedure call device of the present invention.
[0059] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0060] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0061] In a first aspect, embodiments of the present invention provide a remote procedure call device.
[0062] Reference Figure 2 , Figure 2 This is a schematic diagram of the hardware structure of the remote procedure call device involved in the embodiments of the present invention. In these embodiments, the remote procedure call device may include a processor 1001 (e.g., a Central Processing Unit, CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to implement communication between these components; the user interface 1003 may include a display screen or an input unit such as a keyboard; the network interface 1004 may optionally include a standard wired interface or a wireless interface (e.g., Wireless Fidelity, Wi-Fi); the memory 1005 may be high-speed random access memory (RAM) or stable memory (non-volatile memory), such as a disk storage device. Alternatively, the memory 1005 may also be a storage device independent of the aforementioned processor 1001. Those skilled in the art will understand that… Figure 2 The hardware structure shown does not constitute a limitation of the invention and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0063] Continue to refer to Figure 2 , Figure 2 The memory 1005, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and a remote procedure call (RPC) program. The processor 1001 can call the RPC program stored in the memory 1005 and execute the RPC method provided in this embodiment of the invention.
[0064] Secondly, embodiments of the present invention provide a remote procedure call method.
[0065] Reference Figure 3 , Figure 3 This is a flowchart illustrating an embodiment of the remote procedure call method of the present invention.
[0066] In one embodiment of the remote procedure call method of the present invention, the remote procedure call method includes:
[0067] Step S10: When a call request triggered by a client to a Web service based on the HTTP protocol is received, the first input parameter corresponding to the call request is extracted. The first input parameter includes the RPC interface name and RPC interface input parameters corresponding to the server. The first input parameter is a JSON format string.
[0068] In this embodiment, based on the problems existing in the above-mentioned background technology, considering that if a general proxy layer can be provided on the basis of the original RPC service, the client can use a unified method to call the services of the server under different RPC frameworks, and is no longer limited by the language and model limitations of the RPC framework.
[0069] Therefore, this embodiment provides a general proxy layer on top of the original RPC service, converting the RPC interface into an HTTP interface to provide services externally. This adds the process of converting the transport protocol and the message model, using a unified HTTP interface call to shield the differences in transport protocols, and using JSON format strings to transmit messages to shield the differences in message models. This allows customers to call the corresponding services of different RPC frameworks in a unified way, no longer limited by the language and model restrictions of the RPC framework.
[0070] When a client (local system) calls services from other systems, only a unified HTTP interface is needed, eliminating the need for different RPC clients. Specifically, when a client needs to call a server, it can request the server from the web service via HTTP, using a path such as "http: / / IP:Port / call". Upon receiving the client's HTTP request to the web service, the first input parameter of the request can be extracted. This first input parameter is a JSON string containing the RPC interface name (the one the client needs to call) and its input parameters. The RPC input parameters include the name of the function / method to be called on the server, parameter types, and parameter values.
[0071] Furthermore, in one embodiment, before step S10, the method further includes:
[0072] Write the RPC protocol files corresponding to each RPC framework based on the preset file specifications;
[0073] Determine the corresponding RPC protocol parser based on the RPC framework;
[0074] The RPC protocol file corresponding to the RPC framework is parsed using an RPC protocol parser, and a general protocol file is generated based on the parsing results. The general protocol file is used to record the RPC interface corresponding to the RPC framework, and the input parameters, output parameters, return value data types, and attribute definitions of the corresponding RPC protocol model.
[0075] In this embodiment, considering that in traditional RPC calls, even if the client and server use the same RPC framework, the message models must be strongly correlated and completely matched when exchanging call semantics and call data based on the message models of the corresponding RPC frameworks. If the message model corresponding to one end of the client and server is upgraded while the message model corresponding to the other end is not upgraded, the message models of the two ends will be mismatched, making it impossible to parse the call semantics and call data, resulting in the failure of the remote procedure call. Therefore, in traditional RPC calls, the message models corresponding to the client and server must be one-to-one.
[0076] This embodiment does not directly use the message models corresponding to each RPC framework for interactive call semantics and call data. Instead, it converts the message models into JSON format strings for data transmission, as JSON format strings inherently possess compatibility characteristics. The RPC framework defines RPC interfaces and message models through RPC protocol files; that is, the RPC framework generates message models in the corresponding language based on the RPC protocol files. Therefore, if it is necessary to convert the message model into a JSON format string, the corresponding RPC protocol file needs to be parsed. At this point, to facilitate the identification of message model definitions such as interface definitions, interface input parameters, and field types in the RPC protocol files, it is necessary to formulate RPC protocol file writing specifications to add constraints and standards. Based on this, the RPC protocol files corresponding to each RPC framework are then written according to the preset file specifications. The preset file specifications include:
[0077] (1) The file encoding must be UTF-8. During compilation, the compilation script will use the tools provided by the RPC framework to generate .cpp and .java files from the RPC protocol file. If the RPC protocol file is not UTF-8 encoded and contains Chinese comments, the generated java file will be garbled, which will eventually lead to a compilation error.
[0078] (2) The interface name must be an RPC keyword. The interface name is defined by using a const string constant. The constant name and constant value must contain "Rpc" to distinguish it from ordinary constants and interface name definitions. For example, const stringRpcAdjustTunnel = "rpc_adjust_tunnel";
[0079] (3) Method parameters are declared using `@param`. For methods defined using `const`, the parameter types and meanings of each parameter need to be described in multiple lines within the comments. The format is:
[0080] @param input parameter: parameter type (RPC protocol model or basic type) key: parameter key (valid for basic types, value is the same as parameter type for complex types) parameter meaning, or @param input parameter: none, such as:
[0081] / / Modify Tunnel (two input parameters)
[0082] / / @param Input parameter: intkey:tunnelIdTunnel ID
[0083] / / @param Input parameter: TunnelAdjustParamIce Tunnel routing adjustment parameter
[0084] const string RpcAdjustTunnel="rpc_adjust_tunnel";
[0085] (4) Method parameters are declared using `@param`. For methods defined using `const`, the parameter types and meanings of each parameter need to be described in multiple lines within the comments. The meanings are reused as parameter keys for identification. For basic data types, refer to the Java Language Basic Model definition. The format is:
[0086] @param output parameter: parameter type key: parameter key (valid for basic types, value is the same as parameter type for complex types) parameter meaning, or @param output parameter: none, such as:
[0087] / / Modify Tunnel (two input parameters, one output parameter)
[0088] / / @param Input parameter: intkey:tunnelIdTunnel ID
[0089] / / @param Input parameter: TunnelAdjustParamIce Tunnel routing adjustment parameter
[0090] / / @param Output parameter: Tunnel information after TunnelIce adjustment
[0091] const string RpcAdjustTunnel="rpc_adjust_tunnel";
[0092] (5) Method return values are declared using the `@return` field. For methods defined using `const`, the parameter types and meanings of each output parameter need to be described in multiple lines within the comments. The meanings are reused for parameter key identification. For basic data types, refer to the Java Language Basic Model definition. The format is:
[0093] @param output parameter: parameter type key: parameter key (valid for basic types, value is the same as parameter type for complex types) parameter meaning, or @param output parameter: none, such as:
[0094] / / Modify Tunnel (two input parameters, one output parameter)
[0095] / / @param Input parameter: intkey:tunnelIdTunnel ID
[0096] / / @param Input parameter: TunnelAdjustParamIce Tunnel routing adjustment parameter
[0097] / / @param Output parameter: Tunnel information after TunnelIce adjustment
[0098] / / @returnRPC_RETURN_CODE returns error code information
[0099] const string RpcAdjustTunnel="rpc_adjust_tunnel".
[0100] Furthermore, a corresponding RPC protocol parser is determined based on the RPC framework. This parser parses the RPC protocol file of the RPC framework according to the aforementioned preset file specifications, generating a corresponding general protocol file. Note that since different RPC frameworks result in different RPC protocol files, the protocol parser for each RPC framework is unique.
[0101] The generated generic protocol file records the RPC interfaces corresponding to the RPC framework, the input parameters, output parameters, return value data types, and attribute definitions of the corresponding RPC protocol model, thus masking the differences between different RPC protocol files. Simultaneously, this generic protocol file can be used for subsequent conversion between message models and JSON format strings, ensuring that the client is unaware of the specific RPC message model, allowing a single client to correspond to multiple versions of the server.
[0102] The common protocol files, such as function.json, use UTF-8 encoding to store JSON strings. The definition is as follows: [
[0104] {
[0105] "functionName": "Interface definition, defined in the default file specification",
[0106] "desc": "Interface description",
[0107] "inParams":["Input parameter 1 type and key, defined in the default file specification", "Input parameter 2 type and key"],
[0108] "outParams":["Output parameter 1 type and key, defined in the default file specification", "Output parameter 2 type and key"],
[0109] "returnValue": ["Return value type, defined in the default file specification"]
[0110] } ]
[0112] For example: [
[0114] {
[0115] "functionName":"rpc_adjust_tunnel",
[0116] "desc": "Modify Tunnel"
[0117] "inParams":["int:tunnelId","TunnelAdjustParamIce"],
[0118] "outParams":["TunnelIce"],
[0119] "returnValue":["RPC_RETURN_CODE"]
[0120] } ]
[0122] The data types corresponding to the input parameters, output parameters, and return values include the complex message model defined by the RPC protocol and basic data types. Referring to the basic model definition of the Java language, the general basic model definition is as follows: boolean, boolean[]: bool type and complex number; byte, byte[]: byte type and complex number; short, short[]: short integer type and complex number; int, int[]: integer type and complex number; long, long[]: long integer type and complex number; float, float[]: floating-point type and complex number; double, double[]: floating-point type and complex number; String, String[]: string type and complex number.
[0123] Step S20: Convert the first input parameter from a JSON format string to a first RPC protocol model;
[0124] In this embodiment, because the message models corresponding to each RPC framework are converted into JSON format strings for data transmission, the client is unaware of the specific RPC message model, allowing a single client to correspond to multiple versions of the server. However, when the RPC call is finally executed, the original RPC call method is still used. Therefore, after triggering the call request based on a unified HTTP interface, the first input parameter corresponding to the call request needs to be converted from a JSON format string into the first RPC protocol model, so that the RPC call service of the corresponding RPC framework can be executed based on the first RPC protocol model.
[0125] Furthermore, in one embodiment, step S20 includes:
[0126] Convert the first input parameter from a JSON format string into the first general model;
[0127] The RPC interface input parameters in the first general model are converted into the first RPC protocol model.
[0128] In this embodiment, the JSON string corresponding to the first input parameter is not the JSON string corresponding to the RPC protocol model. Therefore, it is necessary to first convert the first input parameter from a JSON string to a first general model using a JSON parser. The first general model is the general model corresponding to the input parameter of the RPC interface to be called, and the general model does not specifically define a concrete object model. In the general model, the Key is the parameter attribute name, and the Value is the parameter value, both of which are string types. If the data type of the input parameter, output parameter, or return value is a basic type, it is directly converted to a string representation; if the data type of the input parameter, output parameter, or return value is a complex type, it is represented as a JSON string in Map form. For example:
[0129] class CommonBean{
[0130] / / Interface name
[0131] String functionName="rpc_adjust_tunnel";
[0132] / / Input parameter list
[0133] List <Map<Stirng,String> >inParams=[<”tunnel”:”<{”id”:”1”,”desc”:”Modify”>”>];
[0134] / / Parameter list
[0135] List <Map<Stirng,String> >outParams;
[0136] / / Return value
[0137] Map<Stirng,String> returnValue;
[0138] }
[0139] After obtaining the first general model, the string representation of each input parameter is extracted from the Map structure of the first general model, and then passed to the RPC protocol parser to be converted into the first RPC protocol model. Specifically, the mutual conversion between the RPC protocol model and the Map structure can be achieved through Java reflection, where the key of the Map structure corresponds to the field name of the RPC protocol model. The first RPC protocol model mentioned above corresponds to the message model of the RPC framework, including the input parameters of the RPC interface to be called.
[0140] Step S30: Based on the RPC interface name and the first RPC protocol model, use the client of the corresponding RPC framework to call the corresponding RPC service of the server to obtain the second RPC protocol model including output parameters and return values.
[0141] In this embodiment, after determining the RPC interface name and the first RPC protocol model, the client of the corresponding RPC framework is used to call the corresponding RPC service of the server based on the RPC interface name and the first RPC protocol model to obtain the second RPC protocol model including output parameters and return values.
[0142] Step S40: Convert the second RPC protocol model into a JSON format string, return it to the Web service, and then return it to the client based on the HTTP protocol.
[0143] In this embodiment, after obtaining the second RPC protocol model including output parameters and return values, it is necessary to return the output parameters and return values to the client, thus completing the entire call process. Returning the second RPC protocol model, including output parameters and return values, to the client requires another model and protocol conversion process. Specifically, the second RPC protocol model needs to be converted into a JSON format string and returned to the Web service, and then returned to the client based on the HTTP protocol.
[0144] Furthermore, in one embodiment, the step of converting the second RPC protocol model into a JSON format string includes:
[0145] The second RPC protocol model, which includes output parameters and return values, is converted into a second general model.
[0146] Convert the second general model into a JSON format string.
[0147] In this embodiment, since the conversion between the RPC protocol model and the Map structure can be achieved through Java reflection, and the keys of the Map structure correspond to the field names of the RPC protocol model, the process of converting the second RPC protocol model into a JSON string requires first converting the second RPC protocol model, which includes output parameters and return values, into a second general model. Furthermore, since the parameters in the general model are all Maps...<String,String> The string representation is in the form of a JSON string, therefore, a JSON parser can be used to convert the above second general model into a JSON format string for transmission. For example, a JSON format string might look like this:
[0148] {
[0149] "functionName":"rpc_adjust_tunnel",
[0150] “outParams”:[<”tunnel”:”<{”id”:”1”,”name”:”First business”,”attr”:”{”desc”:”Modify”,”createUser”:””}”}>”>];
[0151] "returnValue":"<"code":"0","msg":"success">";
[0152] }”
[0153] Furthermore, in one embodiment, reference is made to Figure 4 The step of converting the second RPC protocol model, which includes output parameters and return values, into a second general model includes:
[0154] Step S1: Create a general model;
[0155] Step S2: Based on the general protocol file, identify the data types and attribute definitions of the output parameters and return values in the second RPC protocol model;
[0156] Step S3: Based on the conversion rules of the output parameters and return value data types, convert the output parameters and return values in the second RPC protocol model into a MAP structure;
[0157] Step S4: Fill the output parameters and return values of the MAP structure into the corresponding fields in the general model to obtain the second general model.
[0158] In this embodiment, specifically, the step of converting the second RPC protocol model into a JSON format string includes: creating a general model, where the parameters are all Maps.<String,String> Formal representation. Based on the general protocol file, the data types of output parameters and return values, as well as the KEY attribute definitions, in the second RPC protocol model are identified. The data types include basic and complex types, each with its corresponding conversion rules.
[0159] If the data type is a primitive type, it will be converted according to the corresponding string. When converting to String, the String.valueOf(primitive type) method will be called to convert the primitive type to String.<String,String> The map structure is populated into the outParams and returnValue fields.
[0160] If the data type is complex, convert the basic types within it to...<String,String> The map structure is populated into the outParams and returnValue fields, where the values are complex type Map mapping structure strings, such as:
[0161] <"tunnel":"<{"id":"","name":"","attr":"{"desc":"","createUser":""}"}>">;
[0162] The corresponding second RPC protocol model is: TunnelIce
[0163] Class TunnelIce{
[0164] int id; / / ID
[0165] String name; / / Name
[0166] Attr attr; / / attribute
[0167] }
[0168] ClassAttr{
[0169] String desc; / / Description
[0170] String createUser; / / Create a user
[0171] }
[0172] After identifying the data types and attribute definitions of output parameters and return values in the second RPC protocol model based on the general protocol file, it is necessary to convert the output parameters and return values in the second RPC protocol model into a MAP structure according to the conversion rules of the output parameter and return value data types. Then, the output parameters and return values of the MAP structure are filled into the corresponding fields in the general model to obtain the second general model. For example, the second general model is as follows:
[0173] class CommonBean{
[0174] / / Interface name
[0175] String functionName="rpc_adjust_tunnel";
[0176] / / Input parameter list
[0177] List <Map<Stirng,String> >inParams;
[0178] / / Parameter list
[0179] List <Map<Stirng,String> >outParams = [<"tunnel":"<{"id":"1","name":"First Business","attr":"{"desc":"Modify","createUser":""}"}>">];
[0180] / / Return value
[0181] Map<Stirng,String> returnValue="<"code":"0","msg":"success">;
[0182] }
[0183] Furthermore, in one embodiment, the Web service is implemented based on the Java Spring Boot framework and provides a POST interface based on the HTTP protocol. The input and output parameters of the POST interface adopt JSON format strings corresponding to a general model.
[0184] In this embodiment, the above-mentioned Web service is implemented based on the Java Spring Boot framework and provides a POST interface based on the HTTP protocol. The input and output parameters of the POST interface adopt JSON format strings corresponding to the general model, which facilitates the conversion between the general model and the JSON format strings when performing model conversion and message transmission.
[0185] In this embodiment, the remote procedure call method includes: when receiving a call request triggered by a client to a Web service based on the HTTP protocol, extracting the first input parameter corresponding to the call request, the first input parameter including the RPC interface name and RPC interface input parameters corresponding to the server, the first input parameter being a JSON format string; converting the first input parameter from the JSON format string into a first RPC protocol model; based on the RPC interface name and the first RPC protocol model, using a client of the corresponding RPC framework to call the RPC service corresponding to the server, obtaining a second RPC protocol model including output parameters and return values; converting the second RPC protocol model into a JSON format string, returning it to the Web service, and then returning it to the client based on the HTTP protocol. This invention provides a universal proxy layer on top of the original RPC service, converting the RPC interface into an HTTP interface to provide services externally. This involves adding a process of transport protocol conversion and message model conversion, allowing clients to use a unified method to call corresponding services from different RPC frameworks. When a client (local system) calls services from other systems, it only needs to use the unified HTTP interface, eliminating the need for different RPC clients. This removes the language and model limitations of existing RPC frameworks, solving the technical problems of adaptability, compatibility, and language limitations inherent in existing remote procedure calls based on RPC frameworks. Furthermore, this invention has the following advantages: the HTTP protocol is more universal, allowing direct calls via JavaScript in the browser, which most RPC frameworks do not support; it has stronger compatibility, storing data as JSON strings inherently provides greater compatibility; and exposing services using the HTTP protocol makes it easier to penetrate firewalls and deploy in distributed environments with multiple instances.
[0186] Thirdly, embodiments of the present invention also provide a remote procedure call device.
[0187] Reference Figure 5 A schematic diagram of the functional modules of an embodiment of a remote procedure call device.
[0188] In this embodiment, the remote procedure call device includes:
[0189] Extraction module 10 is used to extract the first input parameter corresponding to the call request when a client triggers a call request to the Web service based on the HTTP protocol. The first input parameter includes the RPC interface name and RPC interface input parameters corresponding to the server. The first input parameter is a JSON format string.
[0190] The first conversion module 20 is used to convert the first input parameter from a JSON format string into a first RPC protocol model;
[0191] The calling module 30 is used to call the corresponding RPC service of the server using the client of the corresponding RPC framework based on the RPC interface name and the first RPC protocol model, so as to obtain the second RPC protocol model including output parameters and return values.
[0192] The second conversion module 40 is used to convert the second RPC protocol model into a JSON format string, return it to the Web service, and then return it to the client based on the HTTP protocol.
[0193] Furthermore, in one embodiment, the first conversion module 20 is specifically used for:
[0194] Convert the first input parameter from a JSON format string into the first general model;
[0195] The RPC interface input parameters in the first general model are converted into the first RPC protocol model.
[0196] Furthermore, in one embodiment, the remote procedure call apparatus further includes a generation module, used for:
[0197] Write the RPC protocol files corresponding to each RPC framework based on the preset file specifications;
[0198] Determine the corresponding RPC protocol parser based on the RPC framework;
[0199] The RPC protocol file corresponding to the RPC framework is parsed using an RPC protocol parser, and a general protocol file is generated based on the parsing results. The general protocol file is used to record the RPC interface corresponding to the RPC framework, and the input parameters, output parameters, return value data types, and attribute definitions of the corresponding RPC protocol model.
[0200] Furthermore, in one embodiment, the second conversion module 40 is specifically used for:
[0201] The second RPC protocol model, which includes output parameters and return values, is converted into a second general model.
[0202] Convert the second general model into a JSON format string.
[0203] Furthermore, in one embodiment, the second conversion module 40 is also specifically used for:
[0204] Create a general model;
[0205] Based on the general protocol file, the data types and attribute definitions of output parameters and return values in the second RPC protocol model are identified;
[0206] Based on the conversion rules for the data types of output parameters and return values, the output parameters and return values in the second RPC protocol model are converted into a MAP structure;
[0207] The output parameters and return values of the MAP structure are filled into the corresponding fields in the general model to obtain the second general model.
[0208] Furthermore, in one embodiment, the Web service is implemented based on the Java Spring Boot framework and provides a POST interface based on the HTTP protocol. The input and output parameters of the POST interface adopt JSON format strings corresponding to a general model.
[0209] The functions of each module in the aforementioned remote procedure call device correspond to the steps in the aforementioned remote procedure call method embodiment, and their functions and implementation processes will not be described in detail here.
[0210] Fourthly, embodiments of the present invention also provide a readable storage medium.
[0211] The present invention provides a remote procedure call program stored on a readable storage medium, wherein when the remote procedure call program is executed by a processor, it implements the steps of the remote procedure call method as described above.
[0212] The method implemented when the remote procedure call program is executed can be referred to in various embodiments of the remote procedure call method of the present invention, and will not be repeated here.
[0213] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0214] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0215] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of the present invention.
[0216] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.
Claims
1. A remote procedure call method, characterized in that, The remote procedure call method includes: When a client sends a call request to the web service based on the HTTP protocol, the first input parameter corresponding to the call request is extracted. The first input parameter includes the RPC interface name and RPC interface input parameters corresponding to the server. The first input parameter is a JSON format string. Convert the first input parameter from a JSON format string to the first RPC protocol model; Based on the RPC interface name and the first RPC protocol model, the client of the corresponding RPC framework calls the corresponding RPC service on the server to obtain the second RPC protocol model, which includes output parameters and return values. The second RPC protocol model is converted into a JSON format string and returned to the web service, which then returns it to the client based on the HTTP protocol.
2. The remote procedure call method as described in claim 1, characterized in that, The step of converting the first input parameter from a JSON format string to a first RPC protocol model includes: Convert the first input parameter from a JSON format string into the first general model; The RPC interface input parameters in the first general model are converted into the first RPC protocol model.
3. The remote procedure call method as described in claim 1, characterized in that, Before the step of extracting the first input parameter corresponding to the call request when a client triggers a call request to the Web service based on the HTTP protocol, the method further includes: Write the RPC protocol files corresponding to each RPC framework based on the preset file specifications; Determine the corresponding RPC protocol parser based on the RPC framework; The RPC protocol file corresponding to the RPC framework is parsed using an RPC protocol parser, and a general protocol file is generated based on the parsing results. The general protocol file is used to record the RPC interface corresponding to the RPC framework, and the input parameters, output parameters, return value data types, and attribute definitions of the corresponding RPC protocol model.
4. The remote procedure call method as described in claim 3, characterized in that, The step of converting the second RPC protocol model into a JSON format string includes: The second RPC protocol model, which includes output parameters and return values, is converted into a second general model. Convert the second general model into a JSON format string.
5. The remote procedure call method as described in claim 4, characterized in that, The step of converting the second RPC protocol model, which includes output parameters and return values, into a second general model includes: Create a general model; Based on the general protocol file, the data types and attribute definitions of output parameters and return values in the second RPC protocol model are identified; Based on the conversion rules for the data types of the output parameters and return values, the output parameters and return values in the second RPC protocol model are converted into a MAP structure; The output parameters and return values of the MAP structure are filled into the corresponding fields in the general model to obtain the second general model.
6. The remote procedure call method as described in claim 1, characterized in that: The web service is implemented based on the Java Spring Boot framework and provides an HTTP POST interface. The input and output parameters of the POST interface are JSON format strings corresponding to a common model.
7. A remote procedure call device, characterized in that, The remote procedure call device includes: The extraction module is used to extract the first input parameter corresponding to the call request when a client triggers a call request to the Web service based on the HTTP protocol. The first input parameter includes the RPC interface name and RPC interface input parameters corresponding to the server. The first input parameter is a JSON format string. The first conversion module is used to convert the first input parameter from a JSON format string into a first RPC protocol model; The calling module is used to call the corresponding RPC service of the server using the client of the corresponding RPC framework based on the RPC interface name and the first RPC protocol model, and obtain the second RPC protocol model including output parameters and return values. The second conversion module is used to convert the second RPC protocol model into a JSON format string, return it to the Web service, and then return it to the client based on the HTTP protocol.
8. The remote procedure call apparatus as described in claim 7, characterized in that, The remote procedure call device further includes a generation module, used for: Write the RPC protocol files corresponding to each RPC framework based on the preset file specifications; Determine the corresponding RPC protocol parser based on the RPC framework; The RPC protocol file corresponding to the RPC framework is parsed using an RPC protocol parser, and a general protocol file is generated based on the parsing results. The general protocol file is used to record the RPC interface corresponding to the RPC framework, and the input parameters, output parameters, return value data types, and attribute definitions of the corresponding RPC protocol model.
9. A remote procedure call device, characterized in that, The remote procedure call device includes a processor, a memory, and a remote procedure call program stored in the memory and executable by the processor, wherein when the remote procedure call program is executed by the processor, it implements the steps of the remote procedure call method as described in any one of claims 1 to 6.
10. A readable storage medium, characterized in that, The readable storage medium stores a remote procedure call program, wherein when the remote procedure call program is executed by a processor, it implements the steps of the remote procedure call method as described in any one of claims 1 to 6.