Disclosure of Invention
The embodiment of the invention aims to provide a remote procedure calling method, a remote procedure calling device and a remote procedure calling system, so that when a service is changed, the service does not need to be interrupted, and the normal operation of the service is ensured.
In order to solve the above technical problem, an embodiment of the present invention provides a remote procedure call method, which is applied to a server, and includes: uniformly receiving a calling request sent by a client through a preset interface; routing the calling request to a target micro-service process corresponding to the calling request according to the calling request; and processing the calling request through the target micro-service process to obtain a calling result, and sending the calling result to the client through a preset interface.
The embodiment of the invention also provides a remote procedure call method, which is applied to the client and comprises the following steps: defining a calling request; wherein, the calling request at least comprises: business data and service names; sending the calling request to a preset interface of the server, so that the server can receive the calling request through the preset interface in a unified manner and process the calling request; and when the server returns the calling result, receiving the calling result.
The embodiment of the invention also provides a remote procedure call device, which comprises: the system comprises a first receiving module, a routing module, a processing module and a first sending module; the first receiving module is used for uniformly receiving a calling request sent by a client through a preset interface; the routing module is used for routing the calling request to a target micro-service process corresponding to the calling request according to the calling request; the processing module is used for processing the calling request through the target micro-service process to obtain a calling result; and the first sending module is used for sending the calling result to the routing module and sending the calling result to the client through a preset interface.
The embodiment of the invention also provides a remote procedure call device, which comprises: the definition module, the second sending module and the second receiving module; the definition module is used for defining a calling request; wherein, the calling request at least comprises: business data and service names; the second sending module is used for sending the calling request to a preset interface of the server so that the server can receive the calling request uniformly through the preset interface and process the calling request; the second receiving module is used for receiving the calling result when the server returns the calling result.
An embodiment of the present invention further provides a server, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the remote procedure call method.
An embodiment of the present invention further provides a client, including: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the remote procedure call method.
The embodiment of the invention also provides a remote procedure call system, which comprises the server and the client.
Compared with the prior art, the interface calling is transparent, the server receives the calling request sent by the client side through the fixed interface in a unified mode, the received calling request is routed to the target micro-service process for processing the calling request, the target micro-service process processes and replies the calling request, the obtained calling result is returned to the client side, and the interface for returning the calling result is the same as the interface for receiving the calling request sent by the client side. By the method, the interface can be definitely called, and the client directly sends the calling request to the fixed calling interface, so that the sending object of the calling request is more definite. On the other hand, the receiving and processing of the call request correspond to different processes respectively, and when the micro service process is used for service change, the receiving of the call request is not influenced, and the normal work of other micro service processes is not influenced, so that the service does not need to be interrupted, and the normal response of the call request is ensured.
In addition, after receiving the call request sent by the client, the method further comprises: judging the type of the session requested by the client according to the calling request; the session type specifically includes: a short connection request type or a long connection request type; and when the service type requested by the client is judged to be the long connection request type, establishing a bidirectional channel with the client. When the types of the sessions called by the calling requests are different, the calling requests are processed in different ways.
In addition, routing the invocation request to a target microservice process corresponding to the invocation request according to the invocation request specifically includes: and determining a target micro-service process corresponding to the calling request according to the service name and calling method name contained in the calling request, and routing the calling request to the determined target micro-service process. And determining a target micro-service process for processing the call request according to the service name and the call method name defined in the call request, and selecting the micro-service process most suitable for processing the call request at present according to the service condition of the micro-service process, so that the call request is processed more efficiently.
In addition, the call request is specifically defined by a ProtoBuf serialization protocol and is transmitted based on an HTTP/2 protocol. The method for calling the request and the return type of the calling result are defined by the ProtoBuf serialization protocol, the speed of the content exchange format is improved, and the programming efficiency is improved. The calling request is transmitted based on the HTTP/2 protocol, and header information of the protocol can be compressed, so that the header information of the protocol is smaller, the consumption of flow is reduced, and safe and stable calling service is provided for the client.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention more apparent, embodiments of the present invention will be described in detail below with reference to the accompanying drawings. However, it will be appreciated by those of ordinary skill in the art that numerous technical details are set forth in order to provide a better understanding of the present application in various embodiments of the present invention. However, the technical solution claimed in the present application can be implemented without these technical details and various changes and modifications based on the following embodiments.
The following embodiments are divided for convenience of description, and should not constitute any limitation to the specific implementation manner of the present invention, and the embodiments may be mutually incorporated and referred to without contradiction.
The first embodiment of the invention relates to a remote procedure call method, which is applied to a server and comprises the following steps: uniformly receiving a calling request sent by a client through a preset interface; routing the calling request to a target micro-service process corresponding to the calling request according to the calling request; and processing the calling request through the target micro-service process to obtain a calling result, and sending the calling result to the client through a preset interface. And receiving the call request sent by the client through a uniform call interface, and routing the call request to the corresponding micro-service process, so that the sending object of the call request is more definite. The implementation details of the remote procedure call method according to this embodiment are described in detail below, and the following description is only provided for the convenience of understanding, and is not necessary for implementing this embodiment. The specific flow is shown in figure 1.
Step 101, uniformly receiving a call request sent by a client through a preset interface. Specifically, a functional interface of the server is optimized, and a fixed interface is set to uniformly receive a call request of the client. For example, calling requests sent by a first terminal, a second terminal, a third terminal and the like of a client are all received by a preset interface of a server, the server manages the calling requests received by the preset interface, a module capable of managing the calling requests by the server is named as a connector module in practical application, and the calling requests received by the server are all received by the connector module.
And 102, routing the calling request to a target micro-service process corresponding to the calling request according to the calling request. Specifically, the service end receives the call request including the service name, the calling method name, and the session type. The service name is used for determining the micro-service module corresponding to the calling request; the calling method names correspond to the calling interfaces and are used for determining functions which can be realized in the micro-service module; the session type includes a short connection request type and a long connection request type, and is used for distinguishing the session type of the call request.
The following describes a call request of the short connection request type and a call request of the long connection request type.
When the session type of the call request is a short connection request type, the short connection request is a request for list data, a request for attendance rules and the like, the connector module routes the call request to the micro-service module corresponding to the call request according to the service name and the calling method name in the call request, and if more than one micro-service module meeting the calling conditions of the call request, one micro-service module with the lowest utilization rate is selected from the calling conditions meeting the call request to process the call request, so that the call result is obtained more efficiently. And when the micro-service module processes the call request, the micro-service module analyzes the message in the call request, and returns the service data called by the client to the connector module according to the analyzed call request to complete the processing of the call request. When the connector module sends a call request to a target microservice process, if the sending fails due to conditions such as overtime, network disconnection and the like, the call request is added into a queue with failed sending, and the call request is automatically retransmitted by a background, so that the call request is ensured to be replied.
When the session type of the call request is a long connection request type, the long connection request is a request such as login, logout, automatic login and the like, the connector module establishes a bidirectional channel between the server and the client, and transmits the long connection request and a call result aiming at the request through the bidirectional channel. After the bidirectional channel is established, whether the connection of the channel is normal or not needs to be detected, and a heartbeat mechanism can be adopted to detect the connection condition of the channel. In addition, when the call request is transmitted by using the bidirectional channel, the user permission of the call request needs to be judged by using the token, and if the terminal user sending the call request does not have the use permission of the bidirectional channel, the call request is refused to pass through the bidirectional channel. And refreshing the token after the token fails, so that the problem that the token fails to cause interface error report is avoided.
And 103, processing the calling request through the target micro-service process to obtain a calling result.
Andstep 104, sending the calling result to the client through a preset interface. Specifically, after the micro service module obtains the call result, the micro service module may be returned to the connector module, and the connector module sends the call result to the client.
Compared with the prior art, the interface calling is transparent, the server receives the calling request sent by the client side through the fixed interface in a unified mode, the received calling request is routed to the target micro-service process for processing the calling request, the target micro-service process processes and replies the calling request, the obtained calling result is returned to the client side, and the interface for returning the calling result is the same as the interface for receiving the calling request sent by the client side. By the method, the interface can be definitely called, and the client directly sends the calling request to the fixed calling interface, so that the sending object of the calling request is more definite. On the other hand, the receiving and processing of the call request correspond to different processes respectively, and when the micro service process is used for service change, the receiving of the call request is not influenced, and the normal work of other micro service processes is not influenced, so that the service does not need to be interrupted, and the normal response of the call request is ensured.
The second embodiment of the invention relates to a remote procedure call method, which is applied to a client and comprises the following steps: defining a calling request; wherein, the calling request at least comprises: business data and service names; sending the calling request to a preset interface of the server, so that the server can receive the calling request through the preset interface in a unified manner and process the calling request; and when the server returns the calling result, receiving the calling result. The implementation details of the remote procedure call method according to this embodiment are described in detail below, and the following description is only provided for the convenience of understanding, and is not necessary for implementing this embodiment. The specific flow is shown in fig. 2.
Step 201, defining a call request. Specifically, the call request is defined through a ProtoBuf serialization protocol, for example, when the defined session type of the call request is a short connection request type, a service data parameter included in the call request is set to a corresponding ProtoBuf object, and binary data is generated. And setting the service name, the calling method name and the generated binary data in the calling request into a corresponding ProtoBuf request object to realize remote calling, wherein if the request object is set as a connector module of the server, the client sends the calling request to the connector module of the server. When the defined session type of the call request is a long connection request type, defining an identifier for distinguishing the long connection request from the short connection request; in addition, the invocation request may include information of the terminal device, such as an identification number (IMEI) of the mobile device, a type or a version number of the terminal device, and the like, which is used for identifying the authority of the user after the bidirectional channel is established. The performance can be improved to a large extent by utilizing the deserialization and serialization of the ProtoBuf protocol, and both sides of the protocol only need to care about protocol definition and do not need to consider the compatibility problem.
Step 202, sending the call request to a preset interface of the server. Specifically, the call request defined above is transmitted by using a standardized HTTP/2 protocol, and the call request is sent to the connector module of the server. The standardized HTTP/2 protocol has the advantages of the SPDY protocol, and simultaneously, the protocol header information is smaller through an HPACK algorithm specially designed for compressing the header information, so that the time and the data volume for transmitting data are reduced, and the calling efficiency of a client is improved.
Step 203, when the server returns the calling result, the calling result is received. Specifically, when the client receives a call result returned by the server, the client analyzes the data type of the data in the call result, and performs deserialization processing on the service data binary stream in the call result by using the ProtoBuf to obtain call data required by the client, wherein the data required to be called by the client can be a received single chat group chat message in an instant messaging system or a contact message in an enterprise address book system. And completing the remote calling.
In the embodiment, the client defines the call request, and sends the defined call request to the unified call interface of the server, so that the sending object of the call request is clarified. The ProtoBuf protocol is utilized when the call request is defined, the performance of data serialization is improved, when the call request is sent to a preset interface of a server side, transmission is carried out based on the HTTP/2 protocol, header information of transmission data can be compressed, and the header information of the protocol is smaller, so that the time and the data volume of the transmission data are reduced, and the call efficiency of a client side is improved.
The steps of the above methods are divided for clarity, and the implementation may be combined into one step or split some steps, and the steps are divided into multiple steps, so long as the same logical relationship is included, which are all within the protection scope of the present patent; it is within the scope of the patent to add insignificant modifications to the algorithms or processes or to introduce insignificant design changes to the core design without changing the algorithms or processes.
A third embodiment of the present invention relates to a remote procedure call apparatus, as shown in fig. 3, including: afirst receiving module 301, arouting module 302, aprocessing module 303, afirst sending module 304; thefirst receiving module 301 is configured to receive a call request sent by a client through a preset interface in a unified manner; therouting module 302 is configured to route the invocation request to a target microservice process corresponding to the invocation request according to the invocation request; theprocessing module 303 is configured to process the call request through the target micro service process to obtain a call result; thefirst sending module 304 is configured to send the call result to the routing module, and send the call result to the client through a preset interface.
It should be understood that this embodiment is a system example corresponding to the first embodiment, and may be implemented in cooperation with the first embodiment. The related technical details mentioned in the first embodiment are still valid in this embodiment, and are not described herein again in order to reduce repetition. Accordingly, the related-art details mentioned in the present embodiment can also be applied to the first embodiment.
It should be noted that each module referred to in this embodiment is a logical module, and in practical applications, one logical unit may be one physical unit, may be a part of one physical unit, and may be implemented by a combination of multiple physical units. In addition, in order to highlight the innovative part of the present invention, elements that are not so closely related to solving the technical problems proposed by the present invention are not introduced in the present embodiment, but this does not indicate that other elements are not present in the present embodiment.
A fourth embodiment of the present invention relates to a remote procedure call apparatus, as shown in fig. 4, including: a definingmodule 401, asecond sending module 402, asecond receiving module 403; thedefinition module 401 is used for defining a call request; wherein, the calling request at least comprises: business data and service names; thesecond sending module 402 is configured to send the call request to a preset interface of the server, so that the server uniformly receives the call request through the preset interface and processes the call request; thesecond receiving module 403 is configured to receive the call result when the server returns the call result.
Since the second embodiment corresponds to the present embodiment, the present embodiment can be implemented in cooperation with the second embodiment. The related technical details mentioned in the second embodiment are still valid in this embodiment, and the technical effects that can be achieved in the second embodiment can also be achieved in this embodiment, and are not described herein again in order to reduce the repetition. Accordingly, the related-art details mentioned in the present embodiment can also be applied to the second embodiment.
A fifth embodiment of the present invention is directed to a server, as shown in fig. 5, including at least oneprocessor 501; and amemory 502 communicatively coupled to the at least oneprocessor 501; wherein thememory 502 stores instructions executable by the at least oneprocessor 501, the instructions being executable by the at least oneprocessor 501 to enable the at least oneprocessor 501 to perform the remote procedure call method described above.
Thememory 502 and theprocessor 501 are coupled by a bus, which may include any number of interconnected buses and bridges that couple one or more of the various circuits of theprocessor 501 and thememory 502 together. The bus may also connect various other circuits such as peripherals, voltage regulators, power management circuits, and the like, which are well known in the art, and therefore, will not be described any further herein. A bus interface provides an interface between the bus and the transceiver. The transceiver may be one element or a plurality of elements, such as a plurality of receivers and transmitters, providing a means for communicating with various other apparatus over a transmission medium. The data processed by the processor is transmitted over the wireless medium via the antenna, which further receives the data and transmits the data to theprocessor 501.
Theprocessor 501 is responsible for managing the bus and general processing and may also provide various functions including timing, peripheral interfaces, voltage regulation, power management, and other control functions. Andmemory 502 may be used to store data used byprocessor 501 in performing operations.
A sixth embodiment of the present invention relates to a client, as shown in fig. 6, including at least oneprocessor 601; and amemory 602 communicatively coupled to the at least oneprocessor 601; thememory 602 stores instructions executable by the at least oneprocessor 601, and the instructions are executed by the at least oneprocessor 601 to enable the at least oneprocessor 601 to execute the remote procedure call method.
Where thememory 602 and theprocessor 601 are coupled by a bus, the bus may comprise any number of interconnected buses and bridges that couple one or more of the various circuits of theprocessor 601 and thememory 602 together. The bus may also connect various other circuits such as peripherals, voltage regulators, power management circuits, and the like, which are well known in the art, and therefore, will not be described any further herein. A bus interface provides an interface between the bus and the transceiver. The transceiver may be one element or a plurality of elements, such as a plurality of receivers and transmitters, providing a means for communicating with various other apparatus over a transmission medium. The data processed by the processor is transmitted over a wireless medium via an antenna, which further receives the data and transmits the data to theprocessor 601.
Theprocessor 601 is responsible for managing the bus and general processing and may also provide various functions including timing, peripheral interfaces, voltage regulation, power management, and other control functions. Whilememory 602 may be used to store data used byprocessor 601 in performing operations.
A seventh embodiment of the present invention relates to a remote procedure call system, as shown in fig. 7, including the above-mentioned server 72 and the above-mentioned client 71, where the client 71 includes at least one terminal, and the first terminal 711, the second terminal 712, and thethird terminal 713 constitute the client 71 in fig. 7.
An eighth embodiment of the present invention relates to a computer-readable storage medium storing a computer program. The computer program realizes the above-described method embodiments when executed by a processor.
That is, as can be understood by those skilled in the art, all or part of the steps in the method for implementing the embodiments described above may be implemented by a program instructing related hardware, where the program is stored in a storage medium and includes several instructions to enable a device (which may be a single chip, a chip, or the like) or a processor (processor) to execute all or part of the steps of the method described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
It will be understood by those of ordinary skill in the art that the foregoing embodiments are specific examples for carrying out the invention, and that various changes in form and details may be made therein without departing from the spirit and scope of the invention in practice.