A general microservice request protocol conversion method
By designing a microservice request protocol conversion method, the conversion between the HTTP protocol and the RPC protocol is realized, which solves the problem of inconsistent communication protocols between different services in the microservice architecture, and improves system performance and scalability.
Patent Information
- Application Number
- CN202411926610.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-04-04
AI Technical Summary
In microservice architecture, the communication protocols between different services may vary, resulting in seamless conversion between the HTTP protocol and the RPC protocol becoming an important issue to improve the overall performance and scalability of the system.
By designing a common microservice request protocol conversion method, including protocol identification module, protocol conversion module and RPC forwarding module, the HTTP GET request protocol is recognized, converted to RPC protocol, and PRC interaction is carried out between services, and finally the response is converted to the original protocol type and returned to the client.
This method can realize seamless conversion between HTTP protocol and RPC protocol in the microservice architecture, improve system efficiency and response speed, and reduce inter-service communication complexity and maintenance costs.
Smart Images

Figure CN119766898A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technologies, and in particular to a general microservice request protocol conversion method. Background Art
[0002] HTTP protocol: Hypertext Transfer Protocol (HTTP) is a simple request-response protocol that usually runs on top of TCP. It specifies what kind of messages a client may send to a server and what kind of responses it may get.
[0003] RPC protocol: Remote Procedure Call Protocol (RPC) is a communication protocol that allows a computer program to execute functions or procedures in another address space, just like executing local code, without having to understand the underlying network communication details.
[0004] Service Registry: used to save the registration information of the RPC Server. When the RPC Server node changes, the Registry will change synchronously. After the RPC Client perceives it, it will refresh the service node list cached in the local memory.
[0005] In the current cloud computing and big data environment, microservice architecture is widely used due to its high cohesion and low coupling characteristics. However, in actual applications, the communication protocols between different services may be different. For example, the front-end usually uses the HTTP protocol for communication, while the back-end services tend to use the efficient and feature-rich RPC protocol. Therefore, how to achieve seamless conversion between the HTTP protocol and the RPC protocol has become an important issue to improve the overall performance and scalability of the system. To this end, a general microservice request protocol conversion method is proposed. Summary of the invention
[0006] In view of this, the embodiments of the present invention hope to provide a universal microservice request protocol conversion method to solve or alleviate the technical problems existing in the prior art and at least provide a beneficial option.
[0007] The technical solution of the embodiment of the present invention is implemented as follows: a general microservice request protocol conversion method comprises the following steps:
[0008] S1. The protocol identification module receives the HTTP GET request protocol sent by the client, and the protocol identification module determines the request protocol type through the request header information of the HTTP GET request protocol;
[0009] S2, the protocol conversion module is used to convert the identified request protocol type into the RPC protocol. The module includes a predefined RPC protocol template, fills the template according to the information in the request protocol type, and generates the corresponding RPC request protocol;
[0010] S3, the RPC forwarding module is used to send the converted RPC request protocol to the inter-service RPC interaction;
[0011] S4, the inter-service RPC interaction constructs the corresponding RPC response according to the received RPC request protocol response;
[0012] S5. The inter-service RPC interaction will receive the RPC response, construct the corresponding protocol type response, and return it to the client response through the RPC forwarding module, protocol conversion module and protocol identification module in sequence.
[0013] In some embodiments, in the S1, the URL of the HTTP GET request protocol is " / api / user", the header contains "Accept: application / json", and the body is empty.
[0014] In some embodiments, in the S1, the protocol types are protocol HTTP1, protocol HTTP2 and protocol N.
[0015] In some embodiments, in S2, the protocol identification module parses the request protocol of HTTP GET, the request method is GET, the URL is " / api / user", the header is "Accept: application / json", and the body is empty.
[0016] In some embodiments, in S4, a corresponding RPC request is constructed, the requested method is "GetUser", and the parameters are empty.
[0017] In some embodiments, in the S5, the corresponding protocol type response has a response status code of 200, a header of "Content-Type:application / json", and a body of "{\"id\":1,\"name\":\"John Doe\"}".
[0018] In some embodiments, in S2, the protocol conversion module finds the address of the target service based on the information of the service registration center, and then sends the RPC request to the target service.
[0019] A universal microservice request protocol conversion system, the system comprising a processor and a register coupled to the processor, wherein the register stores program instructions, and when the program instructions are executed by the processor, the processor executes the universal microservice request protocol conversion method.
[0020] The embodiment of the present invention has the following advantages due to the adoption of the above technical solution:
[0021] 1. The present invention can be widely applied to various scenarios requiring conversion between HTTP protocol and RPC protocol through this method. In a microservice architecture, communication between services may need to be converted between HTTP protocol and RPC protocol. By using the method of the present invention, such conversion can be achieved, thereby improving the efficiency and response speed of the system and reducing the complexity and maintenance cost of communication between services.
[0022] 2. The present invention is also applied to scenarios such as API gateways through this method. API gateway is a server that processes API calls. It acts as a proxy between microservices and the clients that call them, and can realize the conversion from HTTP protocol to RPC protocol, thereby improving the performance and efficiency of API gateways.
[0023] The above summary is for illustrative purposes only and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments and features described above, further aspects, embodiments and features of the present invention will be readily apparent by reference to the accompanying drawings and the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0025] Figure 1 is a flow chart of the present invention;
[0026] Figure 2 It is a system block diagram of the present invention. DETAILED DESCRIPTION
[0027] In the following, only some exemplary embodiments are briefly described. As those skilled in the art will appreciate, the described embodiments may be modified in various ways without departing from the spirit or scope of the present invention. Therefore, the drawings and descriptions are considered to be exemplary and non-restrictive in nature.
[0028] It should be noted that the terms "first", "second", "symmetrical", "array", etc. are only used to distinguish between description and position description purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the definition of "first", "symmetrical", etc. can explicitly or implicitly include one or more of these features; similarly, when the quantity of certain features is not limited in the form of words such as "two" or "three", it should be noted that this feature also explicitly or implicitly includes one or more feature quantities;
[0029] In the present invention, unless otherwise clearly specified and limited, the terms such as "installation", "connection", "fixation" and the like should be understood in a broad sense; for example, it can be a fixed connection, a detachable connection, or an integral molding; it can be a mechanical connection, a direct connection, welding, or an indirect connection through an intermediate medium, or it can be the internal connection of two elements or the interaction relationship between two elements. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood based on the description and drawings combined with specific circumstances.
[0030] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0031] Embodiment 1
[0032] like Figure 1 As shown, an embodiment of the present invention provides a general microservice request protocol conversion method, comprising the following steps:
[0033] S1. The protocol identification module receives the HTTP GET request protocol sent by the client, and the protocol identification module determines the request protocol type through the request header information of the HTTP GET request protocol;
[0034] S2, the protocol conversion module is used to convert the identified request protocol type into the RPC protocol. The module includes a predefined RPC protocol template, fills the template according to the information in the request protocol type, and generates the corresponding RPC request protocol;
[0035] S3, the RPC forwarding module is used to send the converted RPC request protocol to the inter-service RPC interaction;
[0036] S4, the inter-service RPC interaction constructs the corresponding RPC response according to the received RPC request protocol response;
[0037] S5. The inter-service RPC interaction will receive the RPC response, construct the corresponding protocol type response, and return it to the client response through the RPC forwarding module, protocol conversion module and protocol identification module in sequence.
[0038] In this embodiment, specifically, in S1, the URL of the HTTP GET request protocol is " / api / user", the header includes "Accept: application / json", and the body is empty.
[0039] In this embodiment, specifically, in S1, the protocol types are protocol HTTP1, protocol HTTP2 and protocol N.
[0040] A universal microservice request protocol conversion system includes a processor and a register coupled to the processor. The register stores program instructions. When the program instructions are executed by the processor, the processor executes a universal microservice request protocol conversion method.
[0041] In this embodiment, specifically, inter-service RPC (Remote Procedure Call) interaction is a common communication method in distributed systems, allowing one service (client) to request another service (server) to perform a remote operation, just like calling a local service.
[0042] In this embodiment, specifically, the HTTP GET request is a commonly used HTTP method in Web development, which is used to retrieve data from a server. The following are the basic components and descriptions of the HTTP GET request:
[0043] URL(Uniform Resource Locator):
[0044] It specifies the location of the resource being requested on the server;
[0045] Usually includes domain name, path and query parameters;
[0046] HTTP Method:
[0047] GET is a method defined by the HTTP protocol, which is used to request the server to send a specified resource;
[0048] Protocol Version:
[0049] For example, HTTP / 1.1 is the HTTP protocol version used in the request;
[0050] Request headers:
[0051] Contains information about the client environment and the request itself, such as the user agent, the type of data accepted, authentication information (such as cookies), etc.
[0052] Blank lines:
[0053] There must be a blank line between the request header and the request body to separate the header and the body;
[0054] Request body:
[0055] For GET requests, the request body is usually empty because it is mainly used to request data rather than send data. However, in some cases, such as when sending data through the GET method using POST parameters, the request body may be used.
[0056] Embodiment 2
[0057] like Figure 1 As shown, an embodiment of the present invention provides a general microservice request protocol conversion method, comprising the following steps:
[0058] S1. The protocol identification module receives the HTTP GET request protocol sent by the client, and the protocol identification module determines the request protocol type through the request header information of the HTTP GET request protocol;
[0059] S2, the protocol conversion module is used to convert the identified request protocol type into the RPC protocol. The module includes a predefined RPC protocol template, fills the template according to the information in the request protocol type, and generates the corresponding RPC request protocol;
[0060] S3, the RPC forwarding module is used to send the converted RPC request protocol to the inter-service RPC interaction;
[0061] S4, the inter-service RPC interaction constructs the corresponding RPC response according to the received RPC request protocol response;
[0062] S5. The inter-service RPC interaction will receive the RPC response, construct the corresponding protocol type response, and return it to the client response through the RPC forwarding module, protocol conversion module and protocol identification module in sequence.
[0063] In this embodiment, specifically, in S2, the protocol identification module parses the HTTP GET request protocol, the request method is GET, the URL is " / api / user", the header is "Accept: application / json", and the body is empty.
[0064] In this embodiment, specifically, in S2, the protocol conversion module finds the address of the target service according to the information of the service registration center, and then sends the RPC request to the target service.
[0065] A universal microservice request protocol conversion system includes a processor and a register coupled to the processor. The register stores program instructions. When the program instructions are executed by the processor, the processor executes a universal microservice request protocol conversion method.
[0066] In this embodiment, specifically, inter-service RPC (Remote Procedure Call) interaction is a common communication method in distributed systems, allowing one service (client) to request another service (server) to perform a remote operation, just like calling a local service.
[0067] In this embodiment, specifically, the HTTP GET request is a commonly used HTTP method in Web development, which is used to retrieve data from a server. The following are the basic components and descriptions of the HTTP GET request:
[0068] URL(Uniform Resource Locator):
[0069] It specifies the location of the resource being requested on the server;
[0070] Usually includes domain name, path and query parameters;
[0071] HTTP Method:
[0072] GET is a method defined by the HTTP protocol, which is used to request the server to send a specified resource;
[0073] Protocol Version:
[0074] For example, HTTP / 1.1 is the HTTP protocol version used in the request;
[0075] Request headers:
[0076] Contains information about the client environment and the request itself, such as the user agent, the type of data accepted, authentication information (such as cookies), etc.
[0077] Blank lines:
[0078] There must be a blank line between the request header and the request body to separate the header and the body;
[0079] Request body:
[0080] For GET requests, the request body is usually empty because it is mainly used to request data rather than send data. However, in some cases, such as when sending data through the GET method using POST parameters, the request body may be used.
[0081] Embodiment 3
[0082] like Figure 1 As shown, an embodiment of the present invention provides a general microservice request protocol conversion method, comprising the following steps:
[0083] S1. The protocol identification module receives the HTTP GET request protocol sent by the client, and the protocol identification module determines the request protocol type through the request header information of the HTTP GET request protocol;
[0084] S2, the protocol conversion module is used to convert the identified request protocol type into the RPC protocol. The module includes a predefined RPC protocol template, fills the template according to the information in the request protocol type, and generates the corresponding RPC request protocol;
[0085] S3, the RPC forwarding module is used to send the converted RPC request protocol to the inter-service RPC interaction;
[0086] S4, the inter-service RPC interaction constructs the corresponding RPC response according to the received RPC request protocol response;
[0087] S5. The inter-service RPC interaction will receive the RPC response, construct the corresponding protocol type response, and return it to the client response through the RPC forwarding module, protocol conversion module and protocol identification module in sequence.
[0088] In this embodiment, specifically, in S4, a corresponding RPC request is constructed, the request method is "GetUser", and the parameter is empty.
[0089] In this embodiment, specifically, in S5, the corresponding protocol type response has a response status code of 200, a header of "Content-Type:application / json", and a body of "{\"id\":1,\"name\":\"John Doe\"}".
[0090] A universal microservice request protocol conversion system includes a processor and a register coupled to the processor. The register stores program instructions. When the program instructions are executed by the processor, the processor executes a universal microservice request protocol conversion method.
[0091] In this embodiment, specifically, inter-service RPC (Remote Procedure Call) interaction is a common communication method in distributed systems, allowing one service (client) to request another service (server) to perform a remote operation, just like calling a local service.
[0092] In this embodiment, specifically, the HTTP GET request is a commonly used HTTP method in Web development, which is used to retrieve data from a server. The following are the basic components and descriptions of the HTTP GET request:
[0093] URL(Uniform Resource Locator):
[0094] It specifies the location of the resource being requested on the server;
[0095] Usually includes domain name, path and query parameters;
[0096] HTTP Method:
[0097] GET is a method defined by the HTTP protocol, which is used to request the server to send a specified resource;
[0098] Protocol Version:
[0099] For example, HTTP / 1.1 is the HTTP protocol version used in the request;
[0100] Request headers:
[0101] Contains information about the client environment and the request itself, such as the user agent, the type of data accepted, authentication information (such as cookies), etc.
[0102] Blank lines:
[0103] There must be a blank line between the request header and the request body to separate the header and the body;
[0104] Request body:
[0105] For GET requests, the request body is usually empty because it is mainly used to request data rather than send data. However, in some cases, such as when sending data through the GET method using POST parameters, the request body may be used.
[0106] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of various changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A general microservice request protocol conversion method, characterized in that: The following steps are involved: S1. The protocol identification module receives the HTTP GET request protocol sent by the client, and the protocol identification module determines the request protocol type through the request header information of the HTTP GET request protocol; S2, the protocol conversion module is used to convert the identified request protocol type into the RPC protocol. The module includes a predefined RPC protocol template, fills the template according to the information in the request protocol type, and generates the corresponding RPC request protocol; S3, the RPC forwarding module is used to send the converted RPC request protocol to the inter-service RPC interaction; S4, the inter-service RPC interaction constructs the corresponding RPC response according to the received RPC request protocol response; S5. The inter-service RPC interaction will receive the RPC response, construct the corresponding protocol type response, and return it to the client response through the RPC forwarding module, protocol conversion module and protocol identification module in sequence.
2. The general microservice request protocol conversion method according to claim 1 is characterized in that: In S1, the URL of the HTTP GET request protocol is " / api / user", the header contains "Accept: application / json", and the body is empty.
3. The general microservice request protocol conversion method according to claim 1 is characterized in that: In the S1, the protocol types are protocol HTTP1, protocol HTTP2 and protocol N.
4. The general microservice request protocol conversion method according to claim 1 is characterized in that: In S2, the protocol identification module parses the HTTP GET request protocol, the request method is GET, the URL is " / api / user", the header is "Accept: application / json", and the body is empty.
5. The general microservice request protocol conversion method according to claim 1 is characterized in that: In S4, a corresponding RPC request is constructed, the request method is "GetUser", and the parameters are empty.
6. The general microservice request protocol conversion method according to claim 1 is characterized in that: In the S5, the corresponding protocol type response has a response status code of 200, a header of "Content-Type:application / json", and a body of "{\"id\":1,\"name\":\"John Doe\"}".
7. The general microservice request protocol conversion method according to claim 1 is characterized in that: In S2, the protocol conversion module finds the address of the target service according to the information of the service registration center, and then sends the RPC request to the target service.
8. A general microservice request protocol conversion system, characterized in that: The system includes a processor and a register coupled to the processor, wherein program instructions are stored in the register, and when the program instructions are executed by the processor, the processor executes the general microservice request protocol conversion method as described in any one of claims 1 to claim 7.