CN115408169A - Remote procedure calling method, device, equipment and readable storage medium - Google Patents
Remote procedure calling method, device, equipment and readable storage medium Download PDFInfo
- Publication number
- CN115408169A CN115408169A CN202210923206.6A CN202210923206A CN115408169A CN 115408169 A CN115408169 A CN 115408169A CN 202210923206 A CN202210923206 A CN 202210923206A CN 115408169 A CN115408169 A CN 115408169A
- Authority
- CN
- China
- Prior art keywords
- rpc
- protocol
- model
- parameter
- remote procedure
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/547—Remote procedure calls [RPC]; Web services
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/547—Remote procedure calls [RPC]; Web services
- G06F9/548—Object oriented; Remote method invocation [RMI]
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/544—Remote
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Communication Control (AREA)
Abstract
The invention provides a remote procedure call method, a device, equipment and a readable storage medium, wherein the method comprises the following steps: extracting a first input parameter corresponding to the call request, wherein the first input parameter comprises an RPC interface name corresponding to the service end and an RPC interface input parameter, and the first input parameter is a JSON format character string; converting the first input parameter from the JSON format character string into a first RPC protocol model; based on the RPC interface name and the first RPC protocol model, calling the RPC service corresponding to the service end by using the client corresponding to the RPC frame to obtain a second RPC protocol model comprising the parameter and the return value; and converting the second RPC protocol model into a JSON format character string, returning the JSON format character string to the Web service, and returning the JSON format character string to the client based on the HTTP protocol. The invention provides a layer of universal agent on the basis of RPC service, converts the RPC interface into HTTP interface to provide service to the outside, and is not limited by language limitation and model limitation of RPC framework.
Description
Technical Field
The present invention relates to the field of telecommunication network management, and in particular, to a method, an apparatus, a device and a readable storage medium for remote procedure call.
Background
An RPC (Remote Procedure Call) Remote Procedure Call is a protocol that requests services from a Remote computer program over a network without knowledge of the underlying network technology. For example, an application deployed on a server a wants to call a function/method provided by the application on a server B. Since the caller and the callee are not in one memory space, the caller and the callee cannot call directly, and need to express the semantics of the call and convey the data of the call through the network, which is the RPC.
Among them, the main functional goal of RPC is to make it easier to build distributed computing (applications) without losing the semantic simplicity of local calls when providing powerful remote call capabilities. To achieve this goal, the RPC framework needs to provide a transparent call mechanism to allow the user to not have to explicitly distinguish between local calls and remote calls. Currently, RPC is widely used in system environment construction and application program design in distributed systems. There are also many RPC frameworks in the industry, such as Dubbo of Alibara, thrift of FaceBook, gPCR of Google, ICE of Zeroc, and so on.
However, when the remote procedure call is performed based on the RPC interface, the following problems exist:
(1) And (3) adaptability limitation: when the caller and the callee adopt different RPC frames, because the transmission protocols and message models of the different RPC frames are different, the caller cannot directly call the callee, and the caller can only call the corresponding service of the callee after introducing the client of the frame adopted by the callee, as shown in FIG. 1, the client must introduce the RPC client of the RPC frame of the server to request the service from the RPC server of the server based on the RPC communication protocol;
(2) And (4) compatibility limitation: when the calling party and the called party adopt the same RPC framework, the RPC framework generates a message model of a corresponding language according to the protocol file, and the attribute and the method of the model are directly operated in the application layer. Once one of the calling party and the called party has the message model upgraded, and the other message model is not upgraded, the client used by the calling party and the client used by the called party (the client is the server side relative to the calling party) are not matched, and at this time, when the message model is analyzed in the application layer, the analysis fails, and the compatibility cannot be realized.
(3) Language limitation: if the RPC frame adopted by the called party supports languages 1, 2, 3 and 4, and the calling party just adopts language 5, the calling party cannot execute calling on the corresponding service of the called party through the same RPC frame.
Disclosure of Invention
The invention mainly aims to provide a remote procedure calling method, a remote procedure calling device, remote procedure calling equipment and a readable storage medium, and aims to solve the technical problems of adaptability, compatibility and language limitation when remote procedure calling is carried out based on an RPC framework in the prior art.
In a first aspect, the present invention provides a remote procedure call method, including the following steps:
when a call request triggered to a Web service by a client based on an HTTP protocol is received, extracting a first input parameter corresponding to the call request, wherein the first input parameter comprises an RPC interface name and an RPC interface input parameter corresponding to a server, and the first input parameter is a JSON format character string;
converting the first input parameter from a JSON format character string into a first RPC protocol model;
based on the RPC interface name and the first RPC protocol model, calling the RPC service corresponding to the service end by using the client corresponding to the RPC frame to obtain a second RPC protocol model comprising the parameter and the return value;
and converting the second RPC protocol model into a JSON format character string, returning the JSON format character string to the Web service, and returning the JSON format character string to the client based on the HTTP protocol.
Optionally, the step of converting the first entry parameter from the JSON format character string to the first RPC protocol model includes:
converting the first input parameter from a JSON format character string into a first general model;
and converting the RPC interface input parameters in the first general model into a first RPC protocol model.
Optionally, before the step of extracting the first entry corresponding to the invocation request when the invocation request triggered by the client to the Web service based on the HTTP protocol is received, the method further includes:
compiling RPC protocol files corresponding to all RPC frames based on a preset file specification;
determining a corresponding RPC protocol resolver based on the RPC frame;
and analyzing the RPC protocol file corresponding to the RPC frame based on an RPC protocol analyzer, and generating a general protocol file based on an analysis result, wherein the general protocol file is used for recording the RPC interface corresponding to the RPC frame, and the parameter entering, parameter exiting and return value data type and attribute definition of the corresponding RPC protocol model.
Optionally, the step of converting the second RPC protocol model into a JSON format string includes:
converting the second RPC protocol model including the parameter and the return value into a second general model;
and converting the second general model into a JSON format character string.
Optionally, the step of converting the second RPC protocol model including the argument and the return value into a second common model includes:
creating a general model;
identifying and obtaining the parameter data type and attribute definition of the parameter and return data in the second RPC protocol model based on the universal protocol file;
converting the parameter and return values in the second RPC protocol model into an MAP structure based on the conversion rule of the parameter and return value data types;
and filling the parameters and the return values of the MAP structure into corresponding fields in a general model to obtain a second general model.
Optionally, the Web service is implemented based on a Java-based Spring Boot framework, a POST interface based on an HTTP protocol is provided externally, and entry and exit of the POST interface adopt JSON-format character strings corresponding to a general model.
In a second aspect, the present invention further provides a remote procedure call device, including:
the system comprises an extraction module, a first parameter acquisition module and a second parameter acquisition module, wherein the extraction module is used for extracting a first parameter corresponding to a call request when the call request triggered to a Web service by a client based on an HTTP protocol is received, the first parameter acquisition module comprises an RPC interface name and an RPC interface parameter corresponding to a server, and the first parameter acquisition module is a JSON format character string;
the first conversion module is used for converting the first input parameter from the JSON format character string into a first RPC protocol model;
the call module is used for calling the RPC service corresponding to the service end by using the client corresponding to the RPC frame based on the RPC interface name and the first RPC protocol model to obtain a second RPC protocol model comprising the call-out value and the return value;
and the second conversion module is used for converting the second RPC protocol model into a JSON format character string, returning the JSON format character string to the Web service and returning the JSON format character string to the client based on the HTTP protocol.
Optionally, the first conversion module is specifically configured to:
converting the first input parameter from a JSON format character string into a first general model;
and converting the RPC interface input parameters in the first general model into a first RPC protocol model.
Optionally, the remote procedure call apparatus further includes a generating module, configured to:
compiling RPC protocol files corresponding to all RPC frames based on a preset file specification;
determining a corresponding RPC protocol resolver based on the RPC frame;
and analyzing the RPC protocol file corresponding to the RPC frame based on an RPC protocol analyzer, and generating a general protocol file based on an analysis result, wherein the general protocol file is used for recording the RPC interface corresponding to the RPC frame, and the parameter entering, parameter exiting and return value data type and attribute definition of the corresponding RPC protocol model.
Optionally, the second conversion module is specifically configured to:
converting the second RPC protocol model including the parameter and the return value into a second general model;
and converting the second general model into a JSON format character string.
Optionally, the second conversion module is further specifically configured to:
creating a general model;
identifying and obtaining the parameter data type and attribute definition of the parameter and return data in the second RPC protocol model based on the universal protocol file;
converting the parameter and return values in the second RPC protocol model into an MAP structure based on the conversion rule of the parameter and return value data types;
and filling the parameters and the return values of the MAP structure into corresponding fields in a general model to obtain a second general model.
Optionally, the Web service is implemented based on a Java-based Spring Boot framework, a POST interface based on an HTTP protocol is provided externally, and entry and exit of the POST interface adopt JSON-format character strings corresponding to a general model.
In a third aspect, the present invention further provides a remote procedure call device, which includes a processor, a memory, and a remote procedure call program stored on the memory and executable by the processor, wherein the remote procedure call program, when executed by the processor, implements the steps of the remote procedure call method as described above.
In a fourth aspect, the present invention further provides a readable storage medium, on which a remote procedure call program is stored, wherein when the remote procedure call program is executed by a processor, the steps of the remote procedure call method as described above are implemented.
The invention provides a remote procedure calling method, a device, equipment and a readable storage medium, wherein the remote procedure calling method comprises the following steps: when a call request triggered to a Web service by a client based on an HTTP protocol is received, extracting a first input parameter corresponding to the call request, wherein the first input parameter comprises an RPC interface name and an RPC interface input parameter corresponding to a server, and the first input parameter is a JSON format character string; converting the first input parameter from a JSON format character string into a first RPC protocol model; based on the RPC interface name and the first RPC protocol model, calling the RPC service corresponding to the service end by using the client corresponding to the RPC frame to obtain a second RPC protocol model comprising the parameter and the return value; and converting the second RPC protocol model into a JSON format character string, returning to the Web service, and returning to the client based on the HTTP. The invention provides a layer of universal agent on the basis of the original RPC service, converts the RPC interface into the HTTP interface to provide the service to the outside, and can not be limited by the language limit and the model limit of the RPC framework.
Drawings
FIG. 1 is a flow diagram illustrating an embodiment of a remote procedure call method in the prior art;
FIG. 2 is a diagram illustrating a hardware architecture of a remote procedure call device according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating a remote procedure call method according to an embodiment of the present invention;
FIG. 4 is a flowchart illustrating a remote procedure call method according to another embodiment of the present invention;
FIG. 5 is a functional block diagram of a remote procedure call device according to an embodiment of the present invention.
The implementation, functional features and advantages of the present invention will be further described with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and do not limit the invention.
In a first aspect, an embodiment of the present invention provides a remote procedure call device.
Referring to fig. 2, fig. 2 is a schematic diagram of a hardware structure of a remote procedure call device according to an embodiment of the present invention. In an embodiment of the present invention, 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 for realizing connection communication among the components; the user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard); the network interface 1004 may optionally include a standard wired interface, a WIreless interface (e.g., a WI-FI interface, WI-FI interface); the memory 1005 may be a Random Access Memory (RAM) or a non-volatile memory (non-volatile memory), such as a magnetic disk memory, and the memory 1005 may optionally be a storage device independent of the processor 1001. Those skilled in the art will appreciate that the hardware configuration depicted in FIG. 2 is not intended to be limiting of the present invention, and may include more or less components than those shown, or some components in combination, or a different arrangement of components.
With continued reference to FIG. 2, the memory 1005 of FIG. 2, which is one type of computer storage medium, may include an operating system, a network communication module, a user interface module, and a remote procedure call program. The processor 1001 may call a remote procedure call program stored in the memory 1005, and execute the remote procedure call method provided by the embodiment of the present invention.
In a second aspect, an embodiment of the present invention provides a remote procedure call method.
Referring to fig. 3, fig. 3 is a flowchart illustrating a remote procedure call method according to an embodiment of the present invention.
In an embodiment of the remote procedure call method of the present invention, the remote procedure call method includes:
step S10, when a call request triggered to a Web service by a client based on an HTTP protocol is received, extracting a first input parameter corresponding to the call request, wherein the first input parameter comprises an RPC interface name and an RPC interface input parameter corresponding to a server, and the first input parameter is a JSON format character string;
in this embodiment, based on the problems existing in the prior art, it is considered that if a layer of general proxy is provided on the basis of the original RPC service, the client can call the services of the server under different RPC frameworks in a unified manner, and is not limited by the language limitation and the model limitation of the RPC framework.
Therefore, in the scheme of the embodiment, a layer of universal agent is provided on the basis of the original RPC service, an RPC interface is converted into an HTTP interface to provide the service externally, the processes of conversion of a transmission protocol and conversion of a message model are increased, a unified HTTP interface is adopted for calling to shield the difference of the transmission protocol, and a JSON format character string is adopted for transmitting a message to shield the difference of the message model, so that a client can call corresponding services of service ends under different RPC frames in a unified mode and is not limited by language limitations and model limitations of the RPC frames.
When a client (a local system) calls the service of other systems, only a uniform HTTP interface is needed to call, and different RPC clients are not needed to be introduced. When a client needs to call a server, the client can request the Web service to call the server through an HTTP protocol, and a call path is 'HTTP:// IP: port/call'. When a call request triggered to the Web service by a client based on an HTTP protocol is received, the first access parameter corresponding to the call request can be extracted. The first entry is a JSON format character string, and comprises an RPC interface name and an RPC interface entry corresponding to a server (called by a client), wherein the RPC interface entry comprises a function/method name, a parameter type, a parameter value and the like which are required to be called in the server.
Further, in an embodiment, before step S10, the method further includes:
compiling RPC protocol files corresponding to all RPC frames based on a preset file specification;
determining a corresponding RPC protocol resolver based on the RPC frame;
and analyzing the RPC protocol file corresponding to the RPC frame based on an RPC protocol analyzer, and generating a universal protocol file based on an analysis result, wherein the universal protocol file is used for recording the RPC interface corresponding to the RPC frame, and the parameter input, parameter output and return value data type and attribute definition of a corresponding RPC protocol model.
In this embodiment, in consideration of the conventional RPC call, even if the client and the server use the same RPC frame, when the message model based on the corresponding RPC frame interactively calls semantics and call data, it is necessary to ensure that the message model is strongly correlated and completely matched. If the message model corresponding to one of the client and the server is upgraded and the message model corresponding to one of the client and the server is not upgraded, the message models corresponding to the two ends are not matched, and the call semantics and the call data cannot be analyzed, so that the remote procedure call fails. Therefore, when the traditional RPC is called, the message models corresponding to the client and the server must be one-to-one.
According to the scheme of the embodiment, the message models corresponding to the RPC frames are not directly used for exchanging call semantics and call data, but the message models are converted into JSON format character strings for transmitting data, and the JSON format character string transmission data naturally has compatibility characteristics. The RPC framework defines an RPC interface and a message model through an RPC protocol file, namely the RPC framework generates the message model of a corresponding language according to the RPC protocol file. Therefore, if the message model needs to be converted into the JSON format character string, the corresponding RPC protocol file needs to be analyzed. At this time, in order to facilitate identification of message model definitions such as interface definitions and interface participation field types in the RPC protocol file, a RPC protocol file writing specification needs to be formulated, and constraints and standards are added. On the basis, the RPC protocol files corresponding to the RPC frames are compiled based on the preset file specification. Wherein, the preset file specification comprises:
(1) The file coding is required to be UTF-8, when compiling is carried out, the compiling script can generate RPC protocol files through a tool carried by an RPC framework, cpp and java files, if the RPC protocol files are not UTF-8 codes and contain Chinese annotations, the generated java files can be disordered, and finally compiling and reporting errors are caused;
(2) The interface name must be an RPC key, defined by using the const string constant, which must contain "RPC" to distinguish between common constant and interface name definitions, such as const string rpcadjust tunnel = "RPC _ adjust _ tunnel";
(3) Method Advances are declared by the @ param Advance field, and the method defined by consot requires multiple lines in the annotation describing the type and meaning of the parameters of its respective Advance. The format is as follows:
the @ param argument is a parameter type (RPC protocol model or basic type) key, a parameter key (basic type is valid, and complex type is equivalent to parameter type) parameter meaning, or the @ param argument is none, such as:
// modify Tunnel (two references)
/@ param reference: tunnelIdTunnel numbering
/@ param reference: tunnel AdjustParamIce Tunnel routing adjustment parameter
const string RpcAdjustTunnel=“rpc_adjust_tunnel”;
(4) The method argument is declared through an @ param argument field, and the method defined by consot needs to describe the parameter type and meaning of each argument in a comment in multiple lines, and the meaning is multiplexed to be identified by a parameter key. If the basic data type is the basic data type, the basic model definition of the Java language is referred. The format is as follows:
the @ param argument type key parameter key (basic type valid, complex type equivalent to argument type) parameter meaning, or the @ param argument no, as:
// modify Tunnel (two references, one reference)
/@ param reference: tunnelIdTunnel numbering
/@ param reference: tunnel AdjustParamIce Tunnel routing adjustment parameter
/@ param out references: tunnel information adjusted by Tunnel Ice
const string RpcAdjustTunnel=“rpc_adjust_tunnel”;
(5) The method return value is stated through the @ return field, the method defined by the consot needs to describe the parameter types and meanings of all the references in the comments in multiple lines, and the meanings are multiplexed to be identified by the parameter key. If the basic data type is the basic data type, the basic model definition of the Java language is referred. The format is as follows:
the @ param argument type key parameter key (basic type valid, complex type equivalent to argument type) parameter meaning, or the @ param argument no, as:
// modify Tunnel (two references, one reference)
/@ param reference: tunnelIdTunnel numbering
/@ param reference: tunnel AdjustParamIce Tunnel routing adjustment parameter
/@ param out references: tunnel information adjusted by Tunnel Ice
/@ RETURN RPC _ RETURN _ CODE RETURN error CODE information
const string RpcAdjustTunnel=“rpc_adjust_tunnel”。
In addition, a corresponding RPC protocol parser is determined based on the RPC frame, and the RPC protocol parser can parse the RPC protocol file of the RPC frame based on the preset file specification to generate a corresponding general protocol file. The RPC protocol files are different due to different RPC frameworks, so protocol resolvers under different RPC frameworks are unique.
The generated universal protocol file is used for recording the RPC interface corresponding to the RPC frame, and the data types and attribute definitions of the input parameter, the output parameter and the return value of the corresponding RPC protocol model can shield the differences of different RPC protocol files. Meanwhile, the universal protocol file can be used for performing mutual conversion on the message model and the JSON format character string subsequently, so that the client does not sense the specific RPC message model, and one client can correspond to the servers of multiple versions.
JSON character strings are stored in a universal protocol file such as the font by adopting a UTF-8 coding format. The definition is as follows:
[
{
"functional name": interface definition, defined in the specification of the preset file ",
"desc": interface description ",
"inParams" [ "refer to type 1 and key, defined in the specification of the preset file," "refer to type 2 and key" ],
"outParams" [ "refer to type 1 and key, define in the preset file specification", "refer to type 2 and key" ],
"Return value" [ "Return value type, defined in the Preset File Specification" ]
}
]
For example:
[
{
“functionName”:”rpc_adjust_tunnel”,
"desc": modify Tunnel ",
“inParams”:[“int:tunnelId”,”TunnelAdjustParamIce”],
“outParams”:[“TunnelIce”],
“returnValue”:[“RPC_RETURN_CODE”]
}
]
the data types corresponding to the participation-in and participation-out return values comprise a complex message model defined by an RPC protocol and a basic data type. Referring to the definition of the basic model of the Java language, the definition of the general basic model is as follows: bolean, bolean [ ], the bolol type and the plural; byte, byte [ ], byte type and complex number; short [ ], short type and complex number; int, int [ ], integer type and plural; long, long [ ], long integer type and plural; float, float [ ], floating point type and complex number; double [ ], floating point type and complex number; string, string [ ], string type and complex number.
Step S20, converting the first input parameter from the JSON format character string into a first RPC protocol model;
in this embodiment, because the message models corresponding to the RPC frames are converted into JSON format character strings to transmit data, the client does not perceive a specific RPC message model, so that one client can correspond to multiple versions of servers. And finally, when the RPC call is executed, the mode of the original RPC call is adopted, so that after the call request is triggered based on the uniform HTTP interface, the first input parameter corresponding to the call request needs to be converted into a first RPC protocol model from the JSON format character string, so that the RPC call service corresponding to the RPC framework can be executed based on the first RPC protocol model.
Further, in an embodiment, the step S20 includes:
converting the first input parameter from a JSON format character string into a first general model;
and converting the RPC interface input parameters in the first general model into a first RPC protocol model.
In this embodiment, the JSON format string corresponding to the first input parameter is not the JSON string corresponding to the RPC protocol model, and therefore, the first input parameter needs to be converted from the JSON format string to the first general model based on the JSON parser. The first general model is a general model corresponding to the RPC interface entry parameter to be called, and the general model does not specifically define a specific object model any more. The Key in the general model is a parameter attribute name, and the Value is a parameter Value, which are all of character string types. The data type of the in-parameter \ out-parameter \ return value is a basic type, and the character string representation is directly converted; the data type of the join-join \ leave-join \ return value is of a complex type and is represented by a JSON character string in a Map form. Such as:
class CommonBean{
// interface name
String functionName=“rpc_adjust_tunnel”;
// join List
List < Map < stir, string > > inParams = [ < "tunnel": "< {" id ": 1)," desc ": modified" > > >;
// go-out List
List<Map<Stirng,String>>outParams;
// return value
Map<Stirng,String>returnValue;
}
After the first universal model is obtained, extracting each character string representation of the input parameter from a Map structure of the first universal model, and then transferring the character string representation to an RPC protocol parser to be converted into the first RPC protocol model. Specifically, the conversion between the RPC protocol model and the Map structure can be realized in a Java reflection manner, and the Key of the Map structure corresponds to the field name of the RPC protocol model. The first RPC protocol model is a message model corresponding to the RPC framework and comprises an RPC interface entry parameter to be called.
Step S30, based on the RPC interface name and the first RPC protocol model, calling the RPC service corresponding to the service end by using the client corresponding to the RPC frame to obtain a second RPC protocol model comprising the call-out value and the return value;
in this embodiment, after the RPC interface name and the first RPC protocol model are determined, the client side of the corresponding RPC framework is used to call the RPC service corresponding to the server side based on the RPC interface name and the first RPC protocol model, and then the second RPC protocol model including the parameter and the return value is obtained.
And step S40, converting the second RPC protocol model into a JSON format character string, returning to the Web service, and returning to the client based on the HTTP protocol.
In this embodiment, after the second RPC protocol model including the argument and the return value is obtained, the argument and the return value need to be returned to the client, that is, the whole call process is completed, where the second RPC protocol model including the argument and the return value needs to be returned to the client again through a process of model conversion and protocol conversion. Namely, the second RPC protocol model is required to be converted into a JSON format character string, and the JSON format character string is returned to the Web service and then returned to the client based on the HTTP protocol.
Further, in an embodiment, the step of converting the second RPC protocol model into a JSON format string includes:
converting the second RPC protocol model comprising the parameters and the return values into a second general model;
and converting the second general model into a JSON format character string.
In this embodiment, because the RPC protocol model and the Map structure may be converted into each other in a Java reflection manner, the Key of the Map structure corresponds to the field name of the RPC protocol model. Therefore, in the process of converting the second RPC protocol model into the JSON-format character string, the obtained second RPC protocol model including the parameter and the return value needs to be converted into the second general model. And because the parameters in the general model are all represented by character strings in the form of Map < String, string >, on the basis, the second general model can be converted into character strings in the JSON format by using a JSON parser for transmission. The JSON format character string is, for example:
“{
“functionName”:“rpc_adjust_tunnel”,
"outtargets" [ < "tunnel": "< {" id ": 1", "name": first traffic "," attr "{" desc ": modified", "createUser": "} >";
“returnValue“:”<”code”:”0”,“msg”:”success”>”;
}”
further, in an embodiment, referring to fig. 4, the step of converting the second RPC protocol model including the out-reference and the return value into a second general model includes:
s1, establishing a universal model;
s2, identifying and obtaining the data types and attribute definitions of the parameter and return values in the second RPC protocol model based on the universal protocol file;
s3, converting the parameter and return values in the second RPC protocol model into an MAP structure based on the conversion rule of the parameter and return value data types;
and S4, filling the parameters and the return values of the MAP structure into corresponding fields in a general model to obtain a second general model.
In this embodiment, specifically, the step of converting the second RPC protocol model into a JSON format character string includes: and creating a universal model, wherein the parameters in the universal model are represented in the form of Map < String, string >. And identifying to obtain the parameter and return value data types and the KEY attribute definition in the second RPC protocol model based on the universal protocol file. The data types comprise basic types and complex types, and each data type has a corresponding conversion rule.
If the data type is the basic type, converting according to the corresponding character String, calling the method of string.value of when converting to String, converting the basic type to the map structure of < String, string >, and filling to the fields of outParams and return value.
If the data type is a complex type, converting the basic type into a Map structure of < String, string >, filling in the fields of outParams and return value, wherein the value is a Map mapping structure character String of the complex type, such as:
<”tunnel”:”<{“id”:””,”name”:””,”attr”:”{“desc”:””,”createUser”:””}”}>”>;
and the corresponding second RPC protocol model is as follows: tunnelIce
Class TunnelIce{
int id; // numbering
String name; // name
Attr; // Properties
}
ClassAttr{
String desc; description of
String createUser; // Create user
}
After the parameter data type and the attribute definition in the second RPC protocol model are identified and obtained based on the common protocol file, the parameter data type and the attribute definition in the second RPC protocol model need to be converted into an MAP structure based on the conversion rule of the parameter data type and the attribute definition in the second RPC protocol model. And filling the parameters and the return values of the MAP structure into corresponding fields in the general model to obtain a second general model. Wherein, the second general model is for example:
class CommonBean{
// interface name
String functionName=“rpc_adjust_tunnel”;
// join List
List<Map<Stirng,String>>inParams;
// go-out List
List < Map < stir, string > > outParams = [ < "tunnel": "< {" id ": 1)," name ": first traffic", "attr": "{" desc ": modified", "createUser": "}" > ";
// return value
Map<Stirng,String>returnValue=<”code”:”0”,“msg”:”success”>;
}
Further, in an embodiment, the Web service is implemented based on a Java-based Spring Boot framework, a POST interface based on an HTTP protocol is provided externally, and the entry and exit of the POST interface adopt JSON-format character strings corresponding to a general model.
In this embodiment, the Web service is implemented by a Java-based Spring Boot framework, a POST interface based on an HTTP protocol is provided externally, and entry and exit of the POST interface use JSON-format character strings corresponding to a generic model, which facilitates conversion between the generic model and the JSON-format character strings during model conversion and message transmission.
In this embodiment, the remote procedure call method includes: when a call request triggered to a Web service by a client based on an HTTP protocol is received, extracting a first input parameter corresponding to the call request, wherein the first input parameter comprises an RPC interface name and an RPC interface input parameter corresponding to a server, and the first input parameter is a JSON format character string; converting the first input parameter from a JSON format character string into a first RPC protocol model; based on the RPC interface name and the first RPC protocol model, calling the RPC service corresponding to the service end by using the client corresponding to the RPC frame to obtain a second RPC protocol model comprising the parameter and the return value; and converting the second RPC protocol model into a JSON format character string, returning to the Web service, and returning to the client based on the HTTP. The invention provides a layer of universal agent on the basis of the original RPC service, converts an RPC interface into an HTTP interface to provide service externally, and increases the processes of conversion of a transmission protocol and message model conversion, so that a client can call corresponding services of service ends under different RPC frames in a unified mode. In addition, the invention also has the following advantages: the HTTP protocol is more universal, JS call can be directly performed on a browser side, and no JS call is supported by a general RPC framework; the compatibility is stronger, the JSON format character string stores data, and the compatibility is stronger in nature; and the HTTP protocol is adopted to expose services, so that the firewall and distributed environment multi-instance deployment are easier to penetrate.
In a third aspect, an embodiment of the present invention further provides a remote procedure call apparatus.
Referring to fig. 5, a functional block diagram of an embodiment of a remote procedure call device is shown.
In this embodiment, the remote procedure call apparatus includes:
the extraction module 10 is configured to, when a call request triggered to a Web service by a client based on an HTTP protocol is received, extract a first access parameter corresponding to the call request, where the first access parameter includes an RPC interface name and an RPC interface access parameter corresponding to a server, and the first access parameter is a JSON-format character string;
a first conversion module 20, configured to convert the first input parameter from a JSON format string to a first RPC protocol model;
the calling module 30 is used for calling the RPC service corresponding to the service end by using the client corresponding to the RPC frame based on the RPC interface name and the first RPC protocol model to obtain a second RPC protocol model comprising the parameter and the return value;
and the second conversion module 40 is used for converting the second RPC protocol model into a JSON format character string, returning the JSON format character string to the Web service, and returning the JSON format character string to the client based on the HTTP.
Further, in an embodiment, the first conversion module 20 is specifically configured to:
converting the first input parameter from a JSON format character string into a first general model;
and converting the RPC interface input parameters in the first general model into a first RPC protocol model.
Further, in an embodiment, the remote procedure call apparatus further includes a generation module, configured to:
compiling RPC protocol files corresponding to all RPC frames based on a preset file specification;
determining a corresponding RPC protocol resolver based on the RPC frame;
and analyzing the RPC protocol file corresponding to the RPC frame based on an RPC protocol analyzer, and generating a general protocol file based on an analysis result, wherein the general protocol file is used for recording the RPC interface corresponding to the RPC frame, and the parameter entering, parameter exiting and return value data type and attribute definition of the corresponding RPC protocol model.
Further, in an embodiment, the second converting module 40 is specifically configured to:
converting the second RPC protocol model including the parameter and the return value into a second general model;
and converting the second general model into a JSON format character string.
Further, in an embodiment, the second conversion module 40 is further specifically configured to:
creating a general model;
identifying and obtaining the parameter data type and attribute definition of the parameter and return data in the second RPC protocol model based on the universal protocol file;
converting the parameter and return values in the second RPC protocol model into an MAP structure based on the conversion rule of the parameter and return value data types;
and filling the parameters and the return values of the MAP structure into corresponding fields in a general model to obtain a second general model.
Further, in an embodiment, the Web service is implemented based on a Java-based Spring Boot framework, a POST interface based on an HTTP protocol is provided externally, and the entry and exit of the POST interface adopt JSON-format character strings corresponding to a general model.
The function implementation of each module in the remote procedure call device corresponds to each step in the remote procedure call method embodiment, and the function and implementation process are not described in detail herein.
In a fourth aspect, the embodiment of the present invention further provides a readable storage medium.
The readable storage medium of the present invention stores a remote procedure call program, wherein the remote procedure call program, when executed by a processor, implements the steps of the remote procedure call method as described above.
The method implemented when the remote procedure call program is executed may refer to various embodiments of the remote procedure call method of the present invention, and details are not described herein.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising a … …" does not exclude the presence of another identical element in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for causing a terminal device to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.
Claims (10)
1. A remote procedure call method, the remote procedure call method comprising:
when a call request triggered to a Web service by a client based on an HTTP protocol is received, extracting a first access parameter corresponding to the call request, wherein the first access parameter comprises an RPC interface name and an RPC interface access parameter corresponding to a server, and the first access parameter is a JSON format character string;
converting the first input parameter from a JSON format character string into a first RPC protocol model;
based on the RPC interface name and the first RPC protocol model, calling the RPC service corresponding to the service end by using the client corresponding to the RPC frame to obtain a second RPC protocol model comprising the parameter and the return value;
and converting the second RPC protocol model into a JSON format character string, returning to the Web service, and returning to the client based on the HTTP.
2. The remote procedure call method of claim 1, wherein the step of converting the first incoming argument from a JSON format string to a first RPC protocol model comprises:
converting the first input parameter from a JSON format character string into a first general model;
and converting the RPC interface input parameters in the first general model into a first RPC protocol model.
3. The remote procedure call method according to claim 1, wherein before the step of extracting the first entry corresponding to the call request when receiving the call request triggered by the client to the Web service based on the HTTP protocol, the method further comprises:
compiling RPC protocol files corresponding to all RPC frames based on a preset file specification;
determining a corresponding RPC protocol resolver based on the RPC frame;
and analyzing the RPC protocol file corresponding to the RPC frame based on an RPC protocol analyzer, and generating a general protocol file based on an analysis result, wherein the general protocol file is used for recording the RPC interface corresponding to the RPC frame, and the parameter entering, parameter exiting and return value data type and attribute definition of the corresponding RPC protocol model.
4. The remote procedure call method of claim 3, wherein the step of converting the second RPC protocol model to a JSON format string comprises:
converting the second RPC protocol model including the parameter and the return value into a second general model;
and converting the second general model into a JSON format character string.
5. The remote procedure call method according to claim 4, wherein the step of converting the second RPC protocol model including the argument and return values to a second generic model comprises:
creating a general model;
identifying and obtaining the parameter data type and attribute definition of the parameter and return data in the second RPC protocol model based on the universal protocol file;
converting the parameter and return values in the second RPC protocol model into a MAP structure based on the conversion rule of the parameter and return value data types;
and filling the parameters and the return values of the MAP structure into corresponding fields in a general model to obtain a second general model.
6. The remote procedure call method as claimed in claim 1, wherein: the Web service is realized based on a Java Spring Boot framework, a POST interface based on an HTTP protocol is provided externally, and the input parameter and the output parameter of the POST interface adopt JSON format character strings corresponding to a general model.
7. A remote procedure call apparatus, the remote procedure call apparatus comprising:
the system comprises an extraction module, a first parameter acquisition module and a second parameter acquisition module, wherein the extraction module is used for extracting a first parameter corresponding to a call request when the call request triggered to a Web service by a client based on an HTTP protocol is received, the first parameter acquisition module comprises an RPC interface name and an RPC interface parameter corresponding to a server, and the first parameter acquisition module is a JSON format character string;
the first conversion module is used for converting the first input parameter from the JSON format character string into a first RPC protocol model;
the call module is used for calling the RPC service corresponding to the service end by using the client corresponding to the RPC frame based on the RPC interface name and the first RPC protocol model to obtain a second RPC protocol model comprising the call-out value and the return value;
and the second conversion module is used for converting the second RPC protocol model into a JSON format character string, returning the JSON format character string to the Web service and returning the JSON format character string to the client based on the HTTP protocol.
8. The remote procedure call device according to claim 7, further comprising a generation module for:
compiling RPC protocol files corresponding to all RPC frames based on a preset file specification;
determining a corresponding RPC protocol resolver based on the RPC frame;
and analyzing the RPC protocol file corresponding to the RPC frame based on an RPC protocol analyzer, and generating a universal protocol file based on an analysis result, wherein the universal protocol file is used for recording the RPC interface corresponding to the RPC frame, and the parameter input, parameter output and return value data type and attribute definition of a corresponding RPC protocol model.
9. A remote procedure call device comprising a processor, a memory, and a remote procedure call procedure stored on the memory and executable by the processor, wherein the remote procedure call procedure, when executed by the processor, implements the steps of the remote procedure call method of any of claims 1 to 6.
10. A readable storage medium having stored thereon a remote procedure call procedure, wherein the remote procedure call procedure, when executed by a processor, performs the steps of the remote procedure call method according to any one of claims 1 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210923206.6A CN115408169A (en) | 2022-08-02 | 2022-08-02 | Remote procedure calling method, device, equipment and readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210923206.6A CN115408169A (en) | 2022-08-02 | 2022-08-02 | Remote procedure calling method, device, equipment and readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115408169A true CN115408169A (en) | 2022-11-29 |
Family
ID=84159111
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210923206.6A Pending CN115408169A (en) | 2022-08-02 | 2022-08-02 | Remote procedure calling method, device, equipment and readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115408169A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117555528A (en) * | 2024-01-12 | 2024-02-13 | 成都索贝视频云计算有限公司 | Method, device, equipment and medium for generating service code frame |
CN117724875A (en) * | 2024-02-07 | 2024-03-19 | 无锡芯享信息科技有限公司 | Semiconductor device communication method for realizing SESC drive based on Rust language |
-
2022
- 2022-08-02 CN CN202210923206.6A patent/CN115408169A/en active Pending
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117555528A (en) * | 2024-01-12 | 2024-02-13 | 成都索贝视频云计算有限公司 | Method, device, equipment and medium for generating service code frame |
CN117555528B (en) * | 2024-01-12 | 2024-03-26 | 成都索贝视频云计算有限公司 | Method, device, equipment and medium for generating service code frame |
CN117724875A (en) * | 2024-02-07 | 2024-03-19 | 无锡芯享信息科技有限公司 | Semiconductor device communication method for realizing SESC drive based on Rust language |
CN117724875B (en) * | 2024-02-07 | 2024-04-23 | 无锡芯享信息科技有限公司 | Semiconductor device communication method for realizing SESC drive based on Rust language |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110198247B (en) | Interface test method and system | |
CN115408169A (en) | Remote procedure calling method, device, equipment and readable storage medium | |
US7624370B2 (en) | System and method for facilitating development of an application and supporting access to a plurality of heterogeneous backend servers | |
US6757899B2 (en) | Dynamic CORBA gateway for CORBA and non-CORBA clients and services | |
US7870482B2 (en) | Web browser extension for simplified utilization of web services | |
Sayar et al. | Integrating AJAX approach into GIS visualization web services | |
CN109274773B (en) | Method, device and system for realizing remote service calling | |
CN108337236A (en) | A kind of gRPC call methods and device based on Protobuf and HTTP/1.1 | |
US20080282222A1 (en) | Xml push and remote execution of a wireless applications | |
US20100281311A1 (en) | Method and system for reconstructing error response messages under web application environment | |
CN111988171B (en) | Method, proxy server and system for calling SOAP Web service based on RESTful style request | |
CN113467775B (en) | Page generation method and device | |
JP2022523914A (en) | Methods, systems and computer readable media for data conversion using the Representational State Transfer (REST) application programming interface (API). | |
CN112882844B (en) | Joint debugging method, device and storage medium based on network front end and network back end | |
CN108200080B (en) | Remote service communication method | |
CN114490889A (en) | Configuration information processing method, device, equipment, medium and program product | |
CN113992641B (en) | Data processing method, device, equipment and storage medium | |
CN114443905A (en) | Interface document updating method and device, electronic equipment and readable storage medium | |
CN112363699B (en) | Interaction method and device applied to multi-language development platform | |
US20200110584A1 (en) | Automated code generation for functional testing of software applications | |
CN115221525A (en) | Vulnerability scanning method, device, equipment and storage medium | |
CN107239265B (en) | Binding method and device of Java function and C function | |
CN111953662A (en) | Data processing method, device and system and storage medium | |
CN101964742A (en) | Method, system and device for using network open ability | |
EP3757790A1 (en) | Accessing web applications |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |