CN114398191A - Remote service calling method, system, computer equipment and storage medium - Google Patents

Remote service calling method, system, computer equipment and storage medium Download PDF

Info

Publication number
CN114398191A
CN114398191A CN202111594354.XA CN202111594354A CN114398191A CN 114398191 A CN114398191 A CN 114398191A CN 202111594354 A CN202111594354 A CN 202111594354A CN 114398191 A CN114398191 A CN 114398191A
Authority
CN
China
Prior art keywords
service
request
remote
interface
client
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
Application number
CN202111594354.XA
Other languages
Chinese (zh)
Inventor
范豪
范渊
刘博�
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
DBAPPSecurity Co Ltd
Original Assignee
DBAPPSecurity Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by DBAPPSecurity Co Ltd filed Critical DBAPPSecurity Co Ltd
Priority to CN202111594354.XA priority Critical patent/CN114398191A/en
Publication of CN114398191A publication Critical patent/CN114398191A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • G06F9/4451User profiles; Roaming
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/544Remote

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)

Abstract

The application relates to a remote service calling method, a system, computer equipment and a storage medium, wherein the method comprises the following steps: the public interface layer, the request end and the response end respectively introduce a remote service calling component to carry out service annotation and parameter configuration; the request terminal acquires a corresponding interface in a public interface layer based on service requirements; declaring a service annotation on the interface; the request end and the response end carry out parameter configuration on the service; starting a client and a server of the gPC, and automatically finishing initialization of the client and the server; the client generates an interface proxy class in an initialization process; carrying out remote service calling based on the interface proxy class, responding and executing the service by the server side, and transmitting an execution result to the client side; according to the method, the remote calling process of the gPC is packaged, a developer only needs to annotate and configure the service interface, the remote service calling of the gPC can be realized without compiling calling codes, and the problem that the efficiency of the remote service calling process based on the gPC is low is solved.

Description

Remote service calling method, system, computer equipment and storage medium
Technical Field
The present application relates to the field of network communication technologies, and in particular, to a remote service invocation method, system, computer device, and storage medium.
Background
The gRPC is a high-performance open source software framework issued by Google based on HTTP 2.0 transport layer protocol bearer for high-performance communication between services. The gPC complies with a server/client communication model, and in use, the client can invoke services provided by the server as if it were using local methods. The client of the gRPC describes the service interface and payload message structure through ProtoBuf as an interface definition language. The network communication process comprises the following steps: compiling a proto file, establishing a gPC channel between a client and a server, and sending a request message to the server through a gPC protocol; after receiving the request message, the server side can interpret the proto file through the ProtoBuf, restore the data structure with the originally defined format and perform service processing; after the business processing is finished, the server side recompiles the response data by using the ProtoBuf, and sends a response message to the client side through the gPC protocol.
Regardless of the client or the server of the gRPC, in the process of performing remote service invocation and response, the flow steps of service invocation, service start/stop, response processing and the like are complex, developers need to write a large amount of codes to complete service configuration and data processing, and the efficiency is low. In addition, using the ProtoBuf definition service, it is usually necessary to define a corresponding IDL (interface description language), and then generate a serialization tool class using IDL compilers in different languages. Every time a new gRPC service interface needs to be developed, a new IDL, i.e., a proto file, needs to be written and recompiled. Compiling and compiling proto files are tedious, and efficiency of developers is reduced.
Aiming at the problem of low process efficiency of remote service calling based on gRPC in the related technology, no effective solution is provided at present.
Disclosure of Invention
The embodiment provides a remote service calling method, a remote service calling system, a computer device and a storage medium, so as to solve the problem that the process efficiency of remote service calling through a gPC is low in the related art.
In a first aspect, in this embodiment, a remote service invocation method is provided, which is used for a service system, where the service system includes a common interface layer, and a request end and a response end that depend on the common interface layer, and the method includes:
the public interface layer, the request end and the response end respectively introduce a remote service calling component; the remote service calling component comprises service annotation and parameter configuration;
the request terminal acquires an interface corresponding to the service requirement in the public interface layer based on the service requirement; declaring a service annotation on the interface through the remote service invocation component, wherein the service annotation comprises a service name corresponding to the service requirement and a serialization mode of request information;
the request end and the response end carry out parameter configuration on the service corresponding to the service name on the basis of the remote service calling component;
starting a client and a server of the gPC based on the service system, and automatically completing initialization of the client and the server based on the parameter configuration; the client generates an interface proxy class corresponding to the interface in an initialization process;
the client terminal carries out remote service calling based on the interface proxy class, the server terminal responds to the remote service calling and executes the service, and a corresponding execution result is transmitted to the client terminal.
In some embodiments, the client makes a remote service call based on the interface proxy class, the server responds to the remote service call and executes the service, and transmitting a corresponding execution result to the client includes:
the client initiates a remote calling request by calling the interface proxy class; the remote call request comprises a serialization mode and request information of the service annotation statement;
the server receives the remote calling request through gRPC communication connection, obtains the serialization mode and deserializes the request information;
the server side obtains an execution result based on the request information;
the server serializes the execution result based on the serialization mode, transmits the serialized execution result to the client based on the gRPC communication connection, and the client receives and deserializes the execution result to obtain the execution result.
In some embodiments, the remote invocation request is a universal request file defined by the remote service invocation component, the universal request file includes a data header and a first message body, the data header is used for storing the serialization manner, the first message body is used for storing the request information, and the request information includes the interface name, the method name and the method execution parameter after serialization.
In some embodiments, the performing, by the request side and the response side, parameter configuration on the service corresponding to the service name based on the remote service invoking component includes:
the request terminal generates a request terminal configuration file based on the remote service calling component, and configures an IP port or a DNS domain name corresponding to the service name; and the response end generates a response end configuration file based on the remote service calling component, and configures the service port and the starting switch.
In some embodiments, the starting a client and a server of a gRPC based on the service system, and automatically completing initialization of the client and the server based on the parameter configuration includes:
the request terminal generates a client of the gPC based on the configuration file of the request terminal and registers the proxy class instance corresponding to the interface into a Spring container;
and the response end starts the gPC service of the corresponding port based on the response end configuration file, generates a service end, and registers the implementation class instance corresponding to the interface into a Spring container.
In some embodiments, the obtaining, by the server, an execution result based on the request information includes:
the server deserializes the request information to obtain an interface name, a method name and a method execution parameter to be executed;
the server side obtains a corresponding implementation class instance in a Spring container through the interface name, calls a method corresponding to the method name in the implementation class, transmits the method execution parameter, and obtains an execution result.
In some of these embodiments, the server transmitting the serialized execution results to the client over the gRPC communication connection includes:
the server side generates response information according to the serialized execution result, wherein the response information is a general response file defined by the remote service calling assembly, the general response file comprises a second message body, and the second message body is used for storing the response information.
In a second aspect, in this embodiment, there is provided a remote service invocation system apparatus, including:
the public interface layer is used for introducing a remote service calling component;
the request end is used for introducing a remote service calling component and acquiring an interface corresponding to the service requirement in the public interface layer based on the service requirement; declaring a service annotation on the interface through the remote service invocation component, wherein the service annotation comprises a service name corresponding to the service requirement and a serialization mode of request information; performing parameter configuration on the service corresponding to the service name based on the remote service calling component, and starting a client of a gPC (gateway GPRS controller) based on a service system;
the response end is used for introducing a remote service calling component, performing parameter configuration on the service corresponding to the service name based on the remote service calling component, and starting the service end of the gPC based on a service system;
the client is used for automatically finishing the initialization of the client based on the parameter configuration, generating an interface proxy class corresponding to the interface in the initialization process, and calling remote service based on the interface proxy class;
and the server is used for automatically finishing the initialization of the server based on the parameter configuration, responding to the remote service call and executing the service, and transmitting a corresponding execution result to the client.
In a third aspect, there is provided a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the remote service invocation method according to the first aspect when executing the computer program.
In a fourth aspect, in the present embodiment, there is provided a storage medium having stored thereon a computer program which, when executed by a processor, implements the remote service invocation method of the first aspect described above.
Compared with the related art, in the remote service calling method provided by the embodiment, the remote service calling components are respectively introduced into the public interface layer, the request end and the response end, so that the request end and the response end have the functions of performing service annotation and parameter configuration in the public interface layer; a request end and a response end annotate an interface which is used for meeting service requirements in a common interface layer, and perform parameter configuration on the service corresponding to the interface through an external configuration file, thereby shielding code compiling of parameter configuration and initialization of a gPC bottom layer; the request end and the response end start and initialize the client and the server based on the parameter configuration, and establish gPC communication connection between the request end and the server; the client terminal automatically generates an interface proxy class corresponding to the interface in the initialization process, the remote service calling is completed by calling the interface proxy class, the proxy class automatically sends the calling request and obtains the execution result of the server terminal, and a user does not need to pay attention to the bottom execution process of the remote service calling sending request and the obtained result. The remote service calling method provided in the embodiment encapsulates the remote calling process of the gPC, and a developer can realize the remote service calling of the gPC only by annotating and configuring the service interface and without compiling a calling code, so that the problem of low process efficiency of remote service calling based on the gPC is solved, and the development efficiency of the remote service calling of the gPC is improved.
The details of one or more embodiments of the application are set forth in the accompanying drawings and the description below to provide a more thorough understanding of the application.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
FIG. 1 is a schematic diagram of an application system of a remote service invocation method according to the embodiment;
FIG. 2 is a flowchart of a remote service invocation method of the present embodiment;
FIG. 3 is a flowchart of a method for remote service invocation between a client and a server according to the embodiment;
FIG. 4 is a flow chart of a remote service invocation method of the preferred embodiment;
fig. 5 is a schematic structural diagram of the remote service invocation system of the present embodiment.
Detailed Description
For a clearer understanding of the objects, aspects and advantages of the present application, reference is made to the following description and accompanying drawings.
Unless defined otherwise, technical or scientific terms used herein shall have the same general meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The use of the terms "a" and "an" and "the" and similar referents in the context of this application do not denote a limitation of quantity, either in the singular or the plural. The terms "comprises," "comprising," "has," "having," and any variations thereof, as referred to in this application, are intended to cover non-exclusive inclusions; for example, a process, method, and system, article, or apparatus that comprises a list of steps or modules (elements) is not limited to the listed steps or modules, but may include other steps or modules (elements) not listed or inherent to such process, method, article, or apparatus. Reference throughout this application to "connected," "coupled," and the like is not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. Reference to "a plurality" in this application means two or more. "and/or" describes an association relationship of associated objects, meaning that three relationships may exist, for example, "A and/or B" may mean: a exists alone, A and B exist simultaneously, and B exists alone. In general, the character "/" indicates a relationship in which the objects associated before and after are an "or". The terms "first," "second," "third," and the like in this application are used for distinguishing between similar items and not necessarily for describing a particular sequential or chronological order.
The remote service calling method provided in the embodiment can be applied to the application environment shown in fig. 1. The requesting end 102 and the responding end 104 can communicate through a network, and the number of the requesting end 102 and the responding end 104 is not limited. The requesting end 102 may be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices, the server end 104 may be, but is not limited to, various servers, server clusters, hosts, workstations, and the like, and the common interface layer 106 is disposed on the requesting end 102 and the responding end 104. The remote service calling method provided by the embodiment of the application may be executed at the request terminal 102 and the response terminal 104, and the request terminal 102 and the response terminal 104 may include one or more processors and memories for storing data, where the processors may include, but are not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA. The memory may be used to store computer programs, for example, software programs and modules of application software, such as a computer program corresponding to the remote service calling method in the embodiment, and the processor executes various functional applications and data processing by running the computer programs stored in the memory, so as to implement the above-mentioned method. The memory may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some embodiments, the memory may further include memory located remotely from the processor, and these remote memories may be connected to the processor through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof. It will be understood by those of ordinary skill in the art that the structure shown in fig. 1 is merely an illustration and is not intended to limit the structure of the terminal described above. For example, the requesting end 102 and the responding end 104 may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
In this embodiment, a remote service calling method is provided for a service system, where the service system includes a common interface layer, and a request end and a response end that depend on the common interface layer. Fig. 2 is a flowchart of the remote service invocation method of the present embodiment. The embodiment is a process that a request end and a response end finish remote service calling in a service system through the method. As shown in fig. 2, the process includes the following steps:
step 201, a public interface layer, a request end and a response end respectively introduce a remote service calling component; the remote service invocation component includes service annotations and parameter configurations.
The common interface layer in this embodiment is a set of interfaces on which the request side and the response side depend together. The request end and the response end can meet the self requirements by utilizing the existing interfaces of the common interface layer, and the local code writing work is reduced. The functions to be realized are specified in the interfaces, each interface corresponds to a service, and a specific method for realizing the functions is given in the service. Therefore, to implement a specific function, the requesting end or the responding end not only needs to find the interface corresponding to the function, but also needs to run the service corresponding to the interface to obtain the corresponding result to implement the function. When the service is not local, remote calling needs to be performed through the gRPC, namely, the request end sends a remote service calling request, the response end receives the request and operates the corresponding service, and the operated result is sent back to the request end. This process requires multiple code writings to complete parameter configuration and data transmission due to the service invocation and network communication, and the intermediate execution steps are complicated. The remote service calling component in the embodiment encapsulates part of method steps in the remote service calling process of the gPC, and when the common interface layer, the request end and the response end introduce the remote service calling component, the component can be utilized to complete corresponding functions. In this embodiment, the remote service call component includes service annotation and parameter configuration, so that the request end and the response end have a function of performing service annotation and parameter configuration through the remote service call component in a common interface layer.
Step 202, a request terminal acquires an interface corresponding to a service demand in a public interface layer based on the service demand; a service annotation is declared on the interface by the remote service invocation component, the service annotation including a service name corresponding to the service requirement and a serialization of the request information.
After the request end generates the service requirement, an interface corresponding to the service requirement can be found in the dependent public interface layer, and the function of the interface can meet the service requirement of the request end. After the interface is found, the request end can identify the interface in a service annotation mode, so that a corresponding proxy class is generated and called for the interface in the subsequent client end initialization process. In addition, since the service corresponding to the interface is at a remote end, the request end needs to send a call request to the corresponding response end in a network communication manner, and therefore, the request end needs to serialize the information related to the service before transmitting the information. In order for the responding end to recognize the information smoothly, the requesting end needs to explain the serialization manner and the service name corresponding to the service requirement in the service annotation, so that the responding end can find the corresponding service.
And step 203, the request terminal and the response terminal configure parameters of the service corresponding to the service name based on the remote service calling component.
The parameter configuration function is also implemented based on a remote service invocation component, which includes a configuration file. The request end and the response end can carry out parameter configuration on the service needing to be called through the configuration file. In step 202, the request end already determines the service name to be called, writes the service name into a service list in the configuration file, performs parameter configuration on the service in the service list, and prepares for subsequently constructing a gRPC communication connection and generating a gRPC client. The response end can perform parameter configuration on the called service in the configuration file.
Step 204, starting a client and a server of the gPC based on the service system, and automatically completing initialization of the client and the server based on the parameter configuration; the client generates an interface proxy class corresponding to the interface in an initialization process.
After the request end completes the parameter configuration, the gRPC client is started, and program initialization is started. In the process of program initialization, a request end loads a corresponding automatic assembly class in a remote service calling component, the automatic assembly class completes initialization of a client according to parameter configuration, and the initialization comprises generation of gPC bottom layer connection, scanning of the annotated interface in the step 202 and generation of a corresponding interface proxy class. And the response end starts the gPC service end and starts program initialization after parameter configuration is finished. In the process of program initialization, the response end can also load the corresponding automatic assembly class in the remote service calling component, and the automatic assembly class completes the initialization of the service end according to the parameter configuration of the response end. After the initialization of the client and the server is completed, the gRPC communication connection is established, and the remote service calling process can be started.
Step 205, the client performs remote service invocation based on the interface proxy class, the server responds to the remote service invocation and executes the service, and transmits the corresponding execution result to the client.
The client sends the service information to be called to the server through the established gPC communication connection based on the generated interface agent class, after receiving the service information, the server finds the corresponding service according to the service information and executes the service, and returns the execution result to the client through the gPC communication connection, thereby completing a remote service calling process.
Through the above steps S201 to S205, in the remote service invocation method provided in this embodiment, the remote service invocation components are respectively introduced into the public interface layer, the request end and the response end, so that the request end and the response end have the functions of performing service annotation and parameter configuration in the public interface layer; a request end and a response end annotate an interface which is used for meeting service requirements in a common interface layer, and perform parameter configuration on the service corresponding to the interface through an external configuration file, thereby shielding code compiling of parameter configuration and initialization of a gPC bottom layer; through common dependence and service annotation, a request end and a response end can be decoupled, and a call relation between the request end and the response end is maintained through a common interface layer; the request end and the response end start and initialize the client and the server based on the parameter configuration, and establish gPC communication connection between the request end and the server; the client terminal automatically generates an interface proxy class corresponding to the interface in the initialization process, the remote service calling is completed by calling the interface proxy class, the proxy class automatically sends the calling request and obtains the execution result of the server terminal, and a user does not need to pay attention to the bottom execution process of the remote service calling sending request and the obtained result. The remote service calling method provided in the embodiment encapsulates the remote calling process of the gPC, and a developer can realize the remote service calling of the gPC only by annotating and configuring the service interface and without compiling a calling code, so that the problem of low process efficiency of remote service calling based on the gPC is solved, and the development efficiency of the remote service calling of the gPC is improved.
In some embodiments, after the gRPC communication connection is established, the client performs a remote service call based on the interface proxy class, and the server responds to the remote service call and executes a corresponding service, and transmits a corresponding execution result to the client. Fig. 3 is a flowchart of a remote service invoking method between a client and a server according to this embodiment. As shown in fig. 3, the process includes the steps of:
s301, a client initiates a remote calling request through calling an interface proxy class; the remote call request comprises a serialization mode of the service annotation statement and request information.
The interface proxy classes are automatically generated during client initialization and correspond to the annotated interfaces one-to-one. The client terminal calls the interface proxy class to initiate the remote call request. The underlying logic of the invocation request is transparent to the client during the entire invocation process. The interface proxy class contains proxy methods, which initiate remote calls by executing the proxy methods. By executing the proxy method, the service information to be called is obtained, and the information is serialized into request information in a serialization mode of the service annotation statement, wherein the request information can be binary data. And putting the serialization mode and the request information into a remote call request and sending the remote call request to a server.
S302, the server receives the remote call request through gRPC communication connection, obtains a serialization mode and deserializes request information.
The server receives the remote calling request through gRPC communication connection, obtains a serialization mode, and obtains service information to be called by the client according to the request information deserialized by the serialization mode. Serialization and deserialization herein refer to the process of compiling and interpreting the various parameters in the requested message through a pre-agreed format. For example, if the client specifies a json serialization mode, the request information is a string of character strings arranged in a json format, and after receiving the character strings, the server interprets the request information in the json format to obtain various parameter names and parameter values in the service information, and then executes corresponding services according to the information. The serialization method in this embodiment may be hessian, protostuff, or json.
S303, the server side obtains an execution result based on the request information.
S304, the server serializes the execution result based on the serialization mode, transmits the serialized execution result to the client based on the gRPC communication connection, and the client receives and deserializes the execution result to obtain the execution result.
The execution result of the called service of the server also comprises information such as various parameter names and parameter values, and the execution result is also required to be serialized when being returned to the client. The client receives the serialized execution result through the gRPC communication connection, and then carries out deserialization to obtain the execution result.
Through the steps S301 to S304, in the remote service invocation method between the client and the server provided in this embodiment, the client only needs to initiate a remote invocation request through the invocation interface proxy class, and does not need to pay attention to the bottom layer implementation logic of the gRPC, thereby shielding the implementation code of the remote service invocation; and the client side and the server side can acquire the remote call request and the execution result based on the same format to finish the transmission of the call parameters.
In some embodiments, the remote invocation request is a general request file defined by the remote service invocation component, the general request file includes a data header and a first message body, the data header is used for storing the serialization mode, the first message body is used for storing request information, and the request information includes the interface name, the method name and the method execution parameter after serialization.
In a gRPC communication system, a common request format may be used to define remote invocation requests. This common request format is provided by a remote service invocation component that the client and server can utilize to generate the remote invocation request. The universal request format comprises two fields of a data head and a first message body, wherein the data head field is used for storing a serialization mode, the first message body field is of a byte type and is used for storing request information, and the request information is an interface name, a method name and a method execution parameter which are already serialized. And sending the request information to the server according to the general request format, wherein the server can complete deserialization and obtain information required by executing the service. The generic request format applies to all remote invocation requests and may replace the definition of the proto file completion interface.
The universal request file provided in the embodiment provides a universal request format to encapsulate the remote call request, so that the compiling and compiling of the proto file when a new service is defined are avoided, and the development efficiency is improved.
In some embodiments, the present invention relates to a method for a request side and a response side to perform parameter configuration on a service corresponding to a service name based on a remote service invocation component, where the method includes:
the request terminal generates a request terminal configuration file based on the remote service calling component, and configures an IP port or a DNS domain name corresponding to the service name; and generating a response end configuration file by the response end based on the remote service calling component, and configuring the service port and the starting switch.
The request end and the response end configure the service to be called, and prepare for establishing the gRPC communication connection. The method comprises the steps that a request terminal configures an IP port or a DNS domain name corresponding to a service to be called so as to confirm an address and a communication port of the service; the response end configures the service start switch and the start port, and the port configurations of the same service at the request end and the response end should be consistent. After the service starting switch is turned on, the response end can start service calling for the calling request of the request end.
The method for configuring the parameters of the service corresponding to the service name by the request terminal and the response terminal based on the remote service calling component, which are provided in the embodiment, provides the necessary conditions for the client and the server to establish the gRPC connection, and prepares for the start and initialization of the client and the server in the subsequent steps.
In some embodiments, starting a client and a server of the gRPC based on the service system, and automatically completing initialization of the client and the server based on parameter configuration includes:
the request end generates a client of the gPC based on the configuration file of the request end, and registers an agent class instance corresponding to the interface into a Spring container; and the response end starts the gPC service of the corresponding port based on the configuration file of the response end, generates a service end and registers the implementation class instance corresponding to the interface into a Spring container.
In the process of starting the client and the server of the gPC, the client and the server finish initialization of respective programs through automatic assembly, including generation of gPC bottom layer connection, and the automatic assembly of the client scans annotated interfaces to generate corresponding interface agent classes. In the initialization process, the client side further registers the proxy class instance corresponding to the interface into the Spring container, and the server side registers the implementation class instance corresponding to the interface into the Spring container, so that the corresponding proxy class instance and implementation class instance can be subsequently obtained from the Spring container when the call request is processed, the execution of the method is completed, and the execution result is obtained.
In the method for starting and initializing the client and the server of the gRPC provided in this embodiment, a generation and starting manner of the client and the server is provided, the proxy class instance and the implementation class instance corresponding to the call interface are registered in the Spring container for subsequent call, and an executable manner of the service running at a remote end is provided.
In some embodiments, the specific process of the server side obtaining the execution result based on the request information is involved. The specific method comprises the following steps:
the server deserializes the request information to obtain the name of the interface to be executed, the name of the method and the execution parameters of the method; the server side obtains a corresponding implementation class instance in a Spring container through the interface name, calls a method corresponding to the method name in the implementation class, transmits method execution parameters, and obtains an execution result.
The client sends a remote call request to the server, the remote call request comprises a request serialization mode and specific request information, the request information is deserialized after being transmitted to the server, and real information of the client needing to call the service is obtained, wherein the real information comprises a corresponding interface name, a method name needing to be executed in the interface and an execution parameter needing to be used in the method executing process. And the server side obtains a corresponding implementation class instance in the Spring container according to the interface name, wherein the implementation class instance is a set of executable methods corresponding to the interface. The server side calls a method corresponding to the name of the method to be executed from the implementation class instance, transmits the method execution parameter to the method, and runs the method to obtain the execution result.
In the method for obtaining the execution result by the server based on the request information in this embodiment, the interface to be executed, the method name, and the parameter information are obtained through deserialization, so that the operation of the service is completed and the execution result is obtained, a specific implementation step is provided for the operation of the service called by the server, and the key execution result information is obtained.
In some of these embodiments, it also relates to the transmission format of the response information. The server transmits the serialized execution result to the client based on the gRPC communication connection, and the method comprises the following steps:
and the server generates response information from the serialized execution result, wherein the response information is a general response file defined by the remote service calling component, and the general response file comprises a second message body used for storing the response information.
Similar to the generic request format of the remote invocation request, the response information may also be communicated using a generic response format. The common response format is also provided by the remote service invocation component, which the client and the server can utilize to generate the response information. The generic response format includes only one field of the second message body and need not include a serialization manner field. The second message body is byte type and is used for storing response information, and the response information is the execution result of the serialization, and can be the parameter name and the parameter value output after the method is executed.
The general response file provided in this embodiment provides a general response format to encapsulate the response information, thereby avoiding the compiling and compiling of the proto file and improving the development efficiency.
The present embodiment is described and illustrated below by means of preferred embodiments.
Fig. 4 is a flow chart of the remote service invocation method of the preferred embodiment. As shown in fig. 4, the method includes the steps of:
step S401, a public interface layer, a request end and a response end respectively introduce a remote service calling component; the remote service calling component comprises service annotation and parameter configuration;
in the preferred embodiment, the manner of introducing the remote service calling component by the common interface layer, the request end and the response end is maven dependency.
Step S402, the request terminal acquires an interface corresponding to the service requirement in the public interface layer based on the service requirement; declaring a service annotation on the interface through a remote service calling component, wherein the service annotation comprises a service name corresponding to a service requirement and a serialization mode of request information;
step S403, the request end generates a request end configuration file based on the remote service calling component, and configures an IP port or a DNS domain name corresponding to the service name; the response end generates a response end configuration file based on the remote service calling component, and configures the service port and the starting switch;
the remote service calling component in the preferred embodiment has the DNS domain name load balancing function of the gRPC, and dynamic load balancing can be realized without a registration center.
Step S404, a request end generates a client of the gPC based on a configuration file of the request end, and the client generates an interface proxy class corresponding to an interface in an initialization process; registering the proxy class instance corresponding to the interface into a Spring container; the response end starts gPC service of a corresponding port based on the response end configuration file, generates a service end, and registers an implementation class instance corresponding to the interface into a Spring container;
the Spring container is a component of the Spring open source framework and is specially used for storing JavaBean instances. During the container starting process, the designated beans are instantiated and put into the container, the Spring container is used for managing the life cycle and the subsequent use of the beans, and IOC (control inversion) and dependency injection are realized on the basis, so that the coupling problem between Java classes is solved. The automatic assembly of the spring boot is one of important characteristics of a spring boot framework, a special SPI mechanism is utilized, some preset Bean instances are scanned and automatically registered when a container is started, and based on the idea that the arrangement is superior to the configuration, the development amount of software developers and complicated configuration items are reduced.
In the preferred embodiment, both the server and the client are Spring applications, and initialization is completed based on the automatic assembly characteristic of Spring boot. Loading the automatic assembly class GrpcAutoconfiguration configured by the springs during the starting period of the Spring application, and finishing the initialization work of the server and the client according to the corresponding configuration parameters in the step S403.
Step S405, the client initiates a remote calling request through calling the interface proxy class; the remote call request comprises a serialization mode of a service annotation statement and request information; the remote calling request is a universal request file defined by a remote service calling component;
the interface proxy class in the preferred embodiment executes the underlying remote call logic, and initiates the request using the GrpcClient.
Step S406, the server receives the remote call request based on the gRPC communication connection, obtains the serialization mode and deserializes the request information, and obtains the interface name, the method name and the method execution parameter to be executed;
step S407, the server side obtains a corresponding implementation class instance in a Spring container through an interface name, calls a method corresponding to the method name in the implementation class and transmits method execution parameters to obtain an execution result;
step S408, the server serializes the execution result based on the serialization mode, generates response information and transmits the response information to the client, wherein the response information is a general response file defined by the remote service calling component;
step S409, the client receives and deserializes the data to obtain an execution result.
Through the above steps S401 to S409, in the remote service invoking method provided in the preferred embodiment, by introducing the remote service invoking components into the common interface layer, the request end, and the response end, respectively, the request end and the response end are enabled to have the functions of performing service annotation and parameter configuration in the common interface layer, and defining invoking request and response information through the general request file and the general response file; the request end and the response end annotate the interface, perform parameter configuration on the service, and shield the code compiling of the bottom layer parameter configuration and initialization of the gPC; the client automatically generates an interface proxy class based on the remote service calling component to complete the remote service calling, and a user does not need to pay attention to the bottom-layer execution process of sending a request and obtaining a result of the remote service calling. The remote service calling method provided in the embodiment encapsulates the remote calling process of the gPC, and a developer can realize the remote service calling of the gPC only by annotating and configuring the service interface and without compiling a calling code, so that the problem of low process efficiency of remote service calling based on the gPC is solved, and the development efficiency of the remote service calling of the gPC is improved.
It should be noted that the steps illustrated in the above-described flow diagrams or in the flow diagrams of the figures may be performed in a computer system, such as a set of computer-executable instructions, and that, although a logical order is illustrated in the flow diagrams, in some cases, the steps illustrated or described may be performed in an order different than here.
In some embodiments, the present application further provides a remote service invoking system, which is used to implement the foregoing embodiments and preferred embodiments, and the description of which has been already made is omitted. The terms "module," "unit," "subunit," and the like as used below may implement a combination of software and/or hardware for a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
Fig. 5 is a block diagram of the remote service invocation system of the present embodiment, and as shown in fig. 5, the system includes: a common interface layer 51, a request side 52, a response side 53, a client side 54 and a service side 55. Wherein, the request end 52 and the client end 54 belong to one device physically; the responder 53 and the server 55 physically belong to the same device.
A common interface layer 51 for introducing remote service invocation components.
The request terminal 52 is configured to introduce a remote service invocation component, and obtain an interface corresponding to a service requirement in the common interface layer based on the service requirement; declaring a service annotation on the interface through a remote service calling component, wherein the service annotation comprises a service name corresponding to a service requirement and a serialization mode of request information; and performing parameter configuration on the service corresponding to the service name based on the remote service calling component, and starting a client of the gPC based on the service system.
And the response terminal 53 is used for introducing a remote service calling component, performing parameter configuration on the service corresponding to the service name based on the remote service calling component, and starting the service terminal of the gRPC based on the service system.
The client 54 is configured to automatically complete initialization of the client based on parameter configuration, generate an interface proxy class corresponding to the interface in the initialization process, and perform remote service invocation based on the interface proxy class.
And the server 55 is used for automatically completing initialization of the server based on parameter configuration, responding to remote service call and executing service, and transmitting a corresponding execution result to the client.
In the remote service calling system in the embodiment, the remote service calling components are respectively introduced into the public interface layer, the request end and the response end, so that the request end and the response end have the functions of performing service annotation and parameter configuration in the public interface layer; a request end and a response end annotate an interface which is used for meeting service requirements in a common interface layer, and perform parameter configuration on the service corresponding to the interface through an external configuration file, thereby shielding code compiling of parameter configuration and initialization of a gPC bottom layer; the request end and the response end start and initialize the client and the server based on the parameter configuration, and establish gPC communication connection between the request end and the server; the client terminal automatically generates an interface proxy class corresponding to the interface in the initialization process, the remote service calling is completed by calling the interface proxy class, the proxy class automatically sends the calling request and obtains the execution result of the server terminal, and a user does not need to pay attention to the bottom execution process of the remote service calling sending request and the obtained result. The remote service calling method provided in the embodiment encapsulates the remote calling process of the gPC, and a developer can realize the remote service calling of the gPC only by annotating and configuring the service interface and without compiling a calling code, so that the problem of low process efficiency of remote service calling based on the gPC is solved, and the development efficiency of the remote service calling of the gPC is improved.
The above modules may be functional modules or program modules, and may be implemented by software or hardware. For a module implemented by hardware, the modules may be located in the same processor; or the modules can be respectively positioned in different processors in any combination.
There is also provided in this embodiment a computer device comprising a memory having a computer program stored therein and a processor arranged to run the computer program to perform the steps of any of the method embodiments described above.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
It should be noted that, for specific examples in this embodiment, reference may be made to the examples described in the foregoing embodiments and optional implementations, and details are not described again in this embodiment.
In addition, in combination with the remote service invoking method provided in the foregoing embodiment, a storage medium may also be provided in this embodiment to implement the method. The storage medium having stored thereon a computer program; the computer program, when executed by a processor, implements any of the remote service invocation methods of the above embodiments.
It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to be limiting. All other embodiments, which can be derived by a person skilled in the art from the examples provided herein without any inventive step, shall fall within the scope of protection of the present application.
It is obvious that the drawings are only examples or embodiments of the present application, and it is obvious to those skilled in the art that the present application can be applied to other similar cases according to the drawings without creative efforts. Moreover, it should be appreciated that in the development of any such actual implementation, as in any engineering or design project, numerous implementation-specific decisions must be made to achieve the developers' specific goals, such as compliance with system-related and business-related constraints, which may vary from one implementation to another.
The term "embodiment" is used herein to mean that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the present application. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is to be expressly or implicitly understood by one of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the patent protection. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present application shall be subject to the appended claims.

Claims (10)

1. A remote service invocation method for a service system, the service system including a common interface layer and a request side and a response side depending on the common interface layer, the method comprising:
the public interface layer, the request end and the response end respectively introduce a remote service calling component; the remote service calling component comprises service annotation and parameter configuration;
the request terminal acquires an interface corresponding to the service requirement in the public interface layer based on the service requirement; declaring a service annotation on the interface through the remote service invocation component, wherein the service annotation comprises a service name corresponding to the service requirement and a serialization mode of request information;
the request end and the response end carry out parameter configuration on the service corresponding to the service name on the basis of the remote service calling component;
starting a client and a server of the gPC based on the service system, and automatically completing initialization of the client and the server based on the parameter configuration; the client generates an interface proxy class corresponding to the interface in an initialization process;
the client terminal carries out remote service calling based on the interface proxy class, the server terminal responds to the remote service calling and executes the service, and a corresponding execution result is transmitted to the client terminal.
2. The remote service invocation method according to claim 1, wherein the client makes a remote service invocation based on the interface proxy class, the server responds to the remote service invocation and executes the service, and transmitting a corresponding execution result to the client comprises:
the client initiates a remote calling request by calling the interface proxy class; the remote call request comprises a serialization mode and request information of the service annotation statement;
the server receives the remote calling request through gRPC communication connection, obtains the serialization mode and deserializes the request information;
the server side obtains an execution result based on the request information;
the server serializes the execution result based on the serialization mode, transmits the serialized execution result to the client based on the gRPC communication connection, and the client receives and deserializes the execution result to obtain the execution result.
3. The remote service invocation method according to claim 2, wherein the remote invocation request is a general request file defined by the remote service invocation component, the general request file includes a data header and a first message body, the data header is used for storing the serialization manner, the first message body is used for storing the request information, and the request information includes the interface name, the method name and the method execution parameter after serialization.
4. The remote service calling method according to claim 1, wherein the parameter configuration of the service corresponding to the service name by the request terminal and the response terminal based on the remote service calling component comprises:
the request terminal generates a request terminal configuration file based on the remote service calling component, and configures an IP port or a DNS domain name corresponding to the service name; and the response end generates a response end configuration file based on the remote service calling component, and configures the service port and the starting switch.
5. The remote service invocation method according to claim 4, wherein the starting of the client and the server of the gRPC based on the service system, and the automatic completion of the initialization of the client and the server based on the parameter configuration comprise:
the request terminal generates a client of the gPC based on the configuration file of the request terminal and registers the proxy class instance corresponding to the interface into a Spring container;
and the response end starts the gPC service of the corresponding port based on the response end configuration file, generates a service end, and registers the implementation class instance corresponding to the interface into a Spring container.
6. The remote service invocation method according to claim 2, wherein said server side obtaining an execution result based on said request information includes:
the server deserializes the request information to obtain an interface name, a method name and a method execution parameter to be executed;
the server side obtains a corresponding implementation class instance in a Spring container through the interface name, calls a method corresponding to the method name in the implementation class, transmits the method execution parameter, and obtains an execution result.
7. The remote service invocation method according to claim 2, wherein the server side transmits the serialized execution result to the client side based on the gRPC communication connection, including:
the server side generates response information according to the serialized execution result, wherein the response information is a general response file defined by the remote service calling assembly, the general response file comprises a second message body, and the second message body is used for storing the response information.
8. A remote service invocation system, characterized by comprising:
the public interface layer is used for introducing a remote service calling component;
the request end is used for introducing a remote service calling component and acquiring an interface corresponding to the service requirement in the public interface layer based on the service requirement; declaring a service annotation on the interface through the remote service invocation component, wherein the service annotation comprises a service name corresponding to the service requirement and a serialization mode of request information; performing parameter configuration on the service corresponding to the service name based on the remote service calling component, and starting a client of a gPC (gateway GPRS controller) based on a service system;
the response end is used for introducing a remote service calling component, performing parameter configuration on the service corresponding to the service name based on the remote service calling component, and starting the service end of the gPC based on a service system;
the client is used for automatically finishing the initialization of the client based on the parameter configuration, generating an interface proxy class corresponding to the interface in the initialization process, and calling remote service based on the interface proxy class;
and the server is used for automatically finishing the initialization of the server based on the parameter configuration, responding to the remote service call and executing the service, and transmitting a corresponding execution result to the client.
9. A computer device comprising a memory and a processor, wherein the memory has stored therein a computer program, and wherein the processor is arranged to execute the computer program to perform the remote service invocation method according to any of claims 1-7.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the remote service invocation method according to any one of claims 1 to 7.
CN202111594354.XA 2021-12-23 2021-12-23 Remote service calling method, system, computer equipment and storage medium Pending CN114398191A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111594354.XA CN114398191A (en) 2021-12-23 2021-12-23 Remote service calling method, system, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111594354.XA CN114398191A (en) 2021-12-23 2021-12-23 Remote service calling method, system, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114398191A true CN114398191A (en) 2022-04-26

Family

ID=81227077

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111594354.XA Pending CN114398191A (en) 2021-12-23 2021-12-23 Remote service calling method, system, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114398191A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114756309A (en) * 2022-06-14 2022-07-15 苏州万店掌网络科技有限公司 Service calling method, framework, device and storage medium
CN115185717A (en) * 2022-09-14 2022-10-14 北京达佳互联信息技术有限公司 Interface calling method and device, electronic equipment and storage medium
CN115314536A (en) * 2022-08-03 2022-11-08 平安付科技服务有限公司 Method and device for remotely executing command, storage medium and computer equipment
CN115567504A (en) * 2022-09-23 2023-01-03 中国平安财产保险股份有限公司 Data splitting method and device for single application, electronic equipment and storage medium
CN116112479A (en) * 2022-12-08 2023-05-12 联通(浙江)产业互联网有限公司 http interface implementation method, device, equipment and storage medium
CN117555528A (en) * 2024-01-12 2024-02-13 成都索贝视频云计算有限公司 Method, device, equipment and medium for generating service code frame

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114756309A (en) * 2022-06-14 2022-07-15 苏州万店掌网络科技有限公司 Service calling method, framework, device and storage medium
CN115314536A (en) * 2022-08-03 2022-11-08 平安付科技服务有限公司 Method and device for remotely executing command, storage medium and computer equipment
CN115314536B (en) * 2022-08-03 2024-02-02 平安付科技服务有限公司 Remote command execution method and device, storage medium and computer equipment
CN115185717A (en) * 2022-09-14 2022-10-14 北京达佳互联信息技术有限公司 Interface calling method and device, electronic equipment and storage medium
CN115185717B (en) * 2022-09-14 2023-01-20 北京达佳互联信息技术有限公司 Interface calling method and device, electronic equipment and storage medium
CN115567504A (en) * 2022-09-23 2023-01-03 中国平安财产保险股份有限公司 Data splitting method and device for single application, electronic equipment and storage medium
CN116112479A (en) * 2022-12-08 2023-05-12 联通(浙江)产业互联网有限公司 http interface implementation method, device, equipment and storage medium
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

Similar Documents

Publication Publication Date Title
CN114398191A (en) Remote service calling method, system, computer equipment and storage medium
EP3213194B1 (en) Computer system
CN110365751B (en) Service processing method, device and equipment of gateway system
KR102366683B1 (en) Effecting communication events
US9183066B2 (en) Downloadable smart proxies for performing processing associated with a remote procedure call in a distributed system
AU2014386583B8 (en) Inter-process communication method based on application layer of android and basic application communication system
CN109324912B (en) Communication method of application management software oriented to software communication system structure
US20030023613A1 (en) Apparatus and method for dynamically verifying information in a distributed system
WO1999045464A2 (en) Method for distributed object communications based on dynamically acquired and assembled software components
CN111880866B (en) Cross-process callback execution method, device, equipment and storage medium
US20210329100A1 (en) System and method for use of remote procedure call with a microservices environment
CN109743396B (en) Component loading method of SCA software radio platform
CN111221630A (en) Business process processing method, device, equipment, readable storage medium and system
CN112052263A (en) Method, system, computer device and readable storage medium for requesting instruction processing
CN107273226B (en) Method and device for integrating components in android system and calling integrated components
CN114610404A (en) Component calling method and device based on application framework and computer equipment
US7802257B1 (en) Mechanism for bridging a thread-oriented computing paradigm and a job-oriented computing paradigm
US20020198895A1 (en) Apparatus and method for dynamically verifying information in a distributed system
CN112286594A (en) Object serialization and deserialization method and device, electronic device and medium
CN115658165A (en) Method and device for starting tenant plug-in and realizing in-process communication
US20150032789A1 (en) Dynamic object oriented remote instantiation
CN111651146B (en) Function generation method, device, equipment and medium
US10645196B1 (en) Multicomponent software-controllable system and a method for interaction of server-client processes and a machine-readable carrier for performing the method
CN113626001A (en) API dynamic editing method and device based on script
CN113779638A (en) Method and device for realizing interface caller authentication in dynamic proxy mode

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