Communication method, gateway and electronic device
By performing protocol conversion and load balancing in the gateway of the microservice architecture, the poor compatibility of the server and gateway development frameworks is solved, and communication efficiency and compatibility are improved.
Patent Information
- Application Number
- CN202110990740.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-26
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2041-08-26
AI Technical Summary
In the microservice architecture, the compatibility between the server-side development framework and the gateway development framework is poor, resulting in inefficient communication.
By implementing protocol conversion in the gateway, the request based on the first calling protocol is converted into a request based on the second calling protocol, and sent to the server, using the current protocol conversion table and load balancing strategy to improve interface call efficiency and compatibility.
The consistency of the calling protocol is achieved, and the interface calling efficiency of the microservice architecture and the compatibility between the gateway and the server are improved.
Smart Images

Figure CN113726869B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a communication method, a gateway, and an electronic device. Background Art
[0002] In the microservice architecture, different microservices can be deployed in different servers. The gateway between the client and the server contains authentication, routing configuration, current limiting and degradation, load balancing, protocol conversion and other related functions to execute the communication between the client and the server. At the same time, different servers can also communicate through the gateway to achieve collaboration between different servers to improve the computing efficiency of the server.
[0003] In order to facilitate the development and maintenance of servers and gateways that meet the requirements of the microservice architecture, a specific development framework is required. Development frameworks include development frameworks that can develop and deploy both servers and gateways, as well as development frameworks that are mainly used to develop one of the gateway and server. For example, since data processing on the server is relatively complex, developers often use development frameworks that are oriented to server-side interface calls to improve data processing efficiency.
[0004] However, the compatibility between such a server-side development framework and the gateway development framework is poor. Summary of the invention
[0005] In view of this, embodiments of the present invention provide a communication method, a gateway, and an electronic device to at least partially solve the above problems.
[0006] According to a first aspect of an embodiment of the present invention, a communication method is provided, which is applied to a gateway of a microservice architecture, including: obtaining a first request based on a first calling protocol from a client or a first server of the microservice architecture; converting the first request into a second request based on a second calling protocol, the second request being used to call a target logic of a second server of the microservice architecture; and sending the second request to the second server.
[0007] As another implementation of the present invention, obtaining a first request based on a first calling protocol from a client of the microservice architecture includes: obtaining an HTTP request from a client of the microservice architecture.
[0008] As another implementation of the present invention, obtaining a first request based on a first calling protocol from a first server end of the microservice architecture includes: obtaining a first request from a first server end of the microservice architecture, the first server end being configured with a script execution environment, and the first request being generated by the script execution environment based on the first calling protocol.
[0009] As another implementation of the present invention, obtaining the first request from the first server of the microservice architecture includes: obtaining an HTTP request from the first server of the microservice architecture, and the script running environment is Node.js.
[0010] As another implementation of the present invention, the method further includes: receiving a second response to the second request from the second server, wherein the second response is based on the second calling protocol.
[0011] As another implementation of the present invention, the method further includes: converting the second response into a first response based on the first calling protocol; and returning the first response.
[0012] As another implementation of the present invention, the method also includes: obtaining a current protocol conversion table into the gateway, the current protocol conversion table indicating the correspondence between the first calling protocol and the second calling protocol; converting the first request into a second request based on the second calling protocol includes: converting the first request into a second request based on the second calling protocol according to the current protocol conversion table.
[0013] As another implementation of the present invention, the current protocol conversion table specifically indicates the relationship between the routing parameters of the first calling protocol and the attribute parameters of the second calling protocol.
[0014] As another implementation of the present invention, the method also includes: load balancing the first request according to the routing parameters of the first calling protocol; sending the second request to the second server includes: sending the second request to the second server according to the result of the load balancing.
[0015] As another implementation of the present invention, the sending the second request to the second server includes: sending the second request to the second server configured outside the gateway through a generalized calling interface.
[0016] As another implementation of the present invention, the method further includes: initializing the generalized calling interface when initializing the gateway.
[0017] As another implementation of the present invention, the method is executed by an agent program.
[0018] According to a second aspect of an embodiment of the present invention, a gateway is provided, which is applied to a microservice architecture, including: an acquisition module, which acquires a first request based on a first calling protocol from a client or a first server of the microservice architecture; a conversion module, which converts the first request into a second request based on a second calling protocol, wherein the second request is used to call the target logic of the second server of the microservice architecture; and a sending module, which sends the second request to the second server.
[0019] According to a third aspect of an embodiment of the present invention, there is provided an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform an operation corresponding to the method described in the first aspect.
[0020] According to a fourth aspect of an embodiment of the present invention, there is provided a computer storage medium on which a computer program is stored. When the program is executed by a processor, the method described in the first aspect is implemented.
[0021] In the scheme of the embodiment of the present invention, the gateway can convert a first request based on a first calling protocol into a second request based on a second calling protocol, and send the second request to the server, thereby achieving consistency of the calling protocol, improving the interface calling efficiency of the microservice architecture, and further improving the compatibility between the gateway and the server. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0023] Figure 1 A schematic diagram of a microservice architecture gateway according to an example;
[0024] Figure 2A A flow chart of the steps of a communication method according to an embodiment of the present invention;
[0025] Figure 2B for Figure 2A A schematic block diagram of a microservice architecture gateway;
[0026] Figure 2C for Figure 2A A flow chart of sub-steps of a communication method;
[0027] Figure 3is a schematic block diagram of a communication method according to another embodiment of the present invention;
[0028] Figure 4 is a structural block diagram of a gateway according to another embodiment of the present invention; and
[0029] Figure 5 FIG. 4 is a schematic structural diagram of an electronic device according to another embodiment of the present invention. DETAILED DESCRIPTION
[0030] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in the field based on the embodiments in the embodiments of the present invention should fall within the scope of protection of the embodiments of the present invention.
[0031] The specific implementation of the embodiment of the present invention is further described below in conjunction with the accompanying drawings of the embodiment of the present invention.
[0032] When developing and deploying based on a microservice architecture, the development framework includes a development framework that can develop and deploy both the server and the gateway, such as Spring Cloud. It can also include a development framework that is mainly used to develop the server, such as Dubbo.
[0033] Specifically, Spring Cloud is an ordered collection of a series of frameworks that uses the development convenience of Spring Boot to simplify the development of distributed system infrastructure. For example, Spring Boot can be used to start and deploy service discovery registration, configuration center, message bus, load balancing, circuit breaker, data monitoring, etc., and the development mode is consistent. In other words, Spring Cloud combines the more mature and stable service frameworks developed, and repackages them through the Spring Boot development mode to shield the complex configuration and implementation principles, and ultimately provides developers with a simple, easy-to-deploy and easy-to-maintain distributed system development toolkit.
[0034] More specifically, Spring Cloud's sub-projects can be roughly divided into two categories. One is the encapsulation and abstraction of the Spring Boot framework, which is also the largest number of projects. The second category is the implementation of the infrastructure of a part of the distributed system, such as Spring Cloud Stream, Spring Cloud Gateway, etc.
[0035] Spring Cloud Gateway is a gateway project of Spring Cloud. The project is a gateway developed based on technologies such as Spring5.0, Spring Boot 2.0 and Project Reactor. It provides a simple and effective unified API (Application Programming Interface) routing management method for microservice architecture. Spring Cloud Gateway is implemented based on the WebFlux framework. The underlying layer of the WebFlux framework adopts the high-performance Reactor mode communication framework Netty. The underlying layer of Spring Cloud Gateway uses the filter chain and the (routing) Route module. The filter provides a unified routing method and provides basic gateway functions such as security, monitoring / indicators and current limiting based on the filter chain. Each filter in the filter chain can be used to receive and modify requests. A filter is an instance, and each filter can be configured differently. The Route module is defined by ID, target URI, predicate, and filter. If the predicate is true, the route matches and the target URI is accessed.
[0036] Dubbo is a distributed service framework that provides high-performance and transparent remote procedure call (RPC) solutions and service-oriented architecture solutions. Dubbo includes multiple functional nodes, such as Provider, which is used to expose service providers; Consumer, which is used to call remote service consumers; Registry, which is used as a registration center for service registration and discovery; Monitor, which is used as a monitoring center for counting service call times and call time; and Container, which is used as a service running container.
[0037] Figure 1 A schematic diagram of a microservice architecture gateway according to an example. Figure 1 The microservice architecture includes a client, a gateway, and a server. The gateway can be configured using the above-mentioned development framework for the gateway, for example, using Spring Cloud Gateway. The development framework for the gateway can only use the configuration applicable to the gateway itself, and can also be applied to the configuration of the server. The development framework for the gateway can configure each layer in the communication protocol stack, or it can be configured only based on the upper layer protocol. In one example, the development framework for the gateway may include a module for performing protocol conversion. Figure 1The gateway receives an access request from a client and returns a response to the client. Figure 1 The Dubbo server and HTTP server are shown as examples. The Dubbo server uses the Dubbo protocol for interface calls. The HTTP server uses the HTTP protocol for interface calls. The gateway receives the request sent by the client, and generates an access request to the HTTP server through the Pre Filter in the Filter chain specified by Spring CloudGateway and the NettyRoutingFilter of the communication framework Netty. The Dubbo server includes Provider and Consumer, where Consumer can be embedded in the HTTP server, so that the HTTP server can call the logic of the Provider through Consumer and obtain the return response of the Provider. Then, the return response of the Provider is processed by the filter chain including NettyRoutingFilter and Post Filter to perform the call protocol, and then the response returned to the client is generated through the communication framework Netty.
[0038] Figure 2A This is a flow chart of the steps of a communication method according to another embodiment of the present invention. The communication method is applied to a gateway of a microservice architecture, and includes:
[0039] Step S210: Obtain a first request based on a first calling protocol from a client or a first server of the microservice architecture.
[0040] It should be understood that the gateway in the text can be configured through Spring CloudGateway. The microservice architecture includes a client, a first server, and a second server. The client can communicate with the first server or the second server through the gateway. In other words, the client can send a request based on the first calling protocol to call the calling interface in the first server or the second server.
[0041] In addition, the first server can communicate with the second server through the gateway. For example, the first server can send a request based on the first calling protocol to the second server through the gateway to call the interface of the second server.
[0042] Step S220: converting the first request into a second request based on a second calling protocol, where the second request is used to call the target logic of the second server of the microservice architecture.
[0043] It should be understood that the second server can be configured using the above-mentioned development framework for the server. The development framework for the server can include an application programming interface (API) or a generalized invoker interface (Invoker) of the target logic.
[0044] For example, the development framework used for the server may be Dubbo, and accordingly, the second server may be a Dubbo server (e.g., Dubbo Provider). The second calling protocol may be the Dubbo protocol, hsf protocol, or webservice protocol, etc., adopted by the Dubbo server. The second request may be an API interface or an Invoker interface of the target logic. In other words, the second calling protocol may be used for interface calls, including API interface calls or generalized calls. Among them, the API interface may be a calling interface between the Consumer and the Provider, and the generalized calling interface may be a call to the logic in the Provider through a request (an example of a second request) including generalized interface parameters.
[0045] Step S230: Send a second request to the second server.
[0046] It should be understood that the gateway sends a second request to a second server configured outside the gateway to obtain the target logic through an API or a generalized call interface.
[0047] In the solution of the embodiment of the present invention, the gateway can convert a first request based on a first calling protocol into a second request based on a second calling protocol, and send the second request to the server, thereby achieving consistency of the calling protocol and improving the interface calling efficiency of the microservice architecture.
[0048] Figure 2B for Figure 2A A schematic block diagram of a communication method. Figure 2B The microservice architecture gateway is Figure 1 Java Agent Block and Rout definition locator can be understood as Figure 1 Java Agent Block can be used to implement Figure 2A The JavaAgent Block corresponds to a JavaAgent program, which can be implemented as an agent program, where the JavaAgent Block does not change. Figure 1The corresponding functions are implemented in the case of the code of the gateway program. For example, the gateway program can be installed in an underlying operating environment such as a Java Virtual Machine (JVM), and the JavaAgent program calls the logic in the gateway program by changing the program of the underlying operating environment.
[0049] exist Figure 2B In the example, the Java Agent Block receives the first request from the Pre Filter and passes through Figure 2A The Dubbo server directly returns a response to the Java Agent Block, and generates a response to the client or the first server via subsequent filters in the filter chain. Figure 1 As in the example, the Dubbo server generates a response returned to the client or the first server through the HTTP server's relay.
[0050] In addition, Figure 2B In the example, the HTTP server can still interact with the gateway through the NettyRoutingFilter of the communication framework Netty, which is conducive to the compatibility of multiple calling protocols on the server side. The embodiment of the present invention can support Dubbo protocol conversion in Spring CloudGateway.
[0051] Specifically, step S220 can be implemented by using the configured first preset filter (HTTP2DubboRoutingFilter) and the generalized call interface (Invoker). For example, in Java Agent, Invoker and HTTP2DubboRoutingFilter can be configured as different modules. Invoker can be started when HTTP2DubboRoutingFilter is started.
[0052] Figure 2C for Figure 2A Flow chart of sub-steps of step S220 of the communication method.
[0053] Step S220 may include the following sub-steps:
[0054] Step S221: HTTP2DubboRoutingFilter obtains the first request in HTTP protocol format from Pre Filter.
[0055] Step S222: HTTP2DubboRoutingFilter processes the first request to obtain a second request in the Dubbo protocol format. Specifically, the URL may be processed to obtain a Dubbo protocol message including a specific triplet parameter.
[0056] Step S223: HTTP2DubboRoutingFilter sends a second request to Invoker so that Invoker obtains the target logic of the Dubbo server according to the second request.
[0057] Step S224: Return the return value of the target logic to the Invoker, and the return value has the Dubbo protocol format. Specifically, the Invoker can receive the Dubbo protocol message from the HTTP2DubboRoutingFilter, and parse the triplet parameter from the Dubbo protocol message to obtain the target logic of the Dubbo server (eg, provider).
[0058] Step S225: Invoker returns the return value to HTTP2DubboRoutingFilter. Specifically, the return value is encapsulated into Dubbo protocol format via the second preset filter (DubboWriteResponseFilter), converted from Dubbo protocol format to HTTP protocol format via HTTP2DubboRoutingFilter, and sent to PostFilter for subsequent processing.
[0059] In another implementation of the present invention, obtaining a first request based on a first calling protocol from a client of a microservice architecture includes: obtaining an HTTP request from the client of the microservice architecture.
[0060] In another implementation of the present invention, obtaining a first request based on a first calling protocol from a first server of a microservice architecture includes: obtaining the first request from the first server of the microservice architecture, the first server being configured with a script running environment, and the first request being generated by the script running environment based on the first calling protocol. The first server may be a non-Dubbo server, and the second server may be a Dubbo server. Thus, the embodiment of the present invention supports protocol conversion between HTTP and Dubbo, and also supports non-Dubbo servers sending requests based on the Dubbo calling protocol through a script running environment, thereby improving the calling efficiency of north-south traffic and east-west traffic.
[0061] In another implementation of the present invention, obtaining a first request from a first server of a microservice architecture includes: obtaining an HTTP request from the first server of the microservice architecture, and the script running environment is Node.js.
[0062] Specifically, the access traffic through the gateway can be divided into east-west traffic and north-south traffic. East-west traffic refers to the communication access between different servers, and north-south traffic refers to the communication access between the client and the server. For east-west traffic, non-Dubbo servers can use an interface based on Dubbo-proxy to send requests based on the Dubbo call protocol. For example, Node.js is used to send requests based on the Dubbo call protocol, realizing cross-language Dubbo service calls. For north-south traffic, the security of north-south traffic can be ensured by configuring Uniform Resource Identifier (URI) requests based on HTTP.
[0063] In another implementation of the present invention, the method further includes: receiving a second response to the second request from the second server, the second response being based on a second calling protocol.
[0064] In another implementation of the present invention, the method further includes: converting the second response into a first response based on the first calling protocol; and returning the first response.
[0065] In another implementation of the present invention, the method further includes: acquiring a current protocol conversion table into a gateway, the current protocol conversion table indicating a correspondence between the first calling protocol and the second calling protocol. Converting the first request into a second request based on the second calling protocol includes: converting the first request into the second request based on the second calling protocol according to the current protocol conversion table.
[0066] In another implementation of the present invention, the current protocol conversion table specifically indicates the relationship between the routing parameters of the first calling protocol and the attribute parameters of the second calling protocol.
[0067] In another implementation of the present invention, the method further includes: performing load balancing on the first request according to the routing parameters of the first calling protocol. Sending the second request to the second server includes: sending the second request to the second server according to the result of the load balancing.
[0068] In addition, a global level load balancing strategy is also configured in the gateway program. For example, the global level load balancing strategy can perform allocation on communication access. According to the routing parameters of the first call protocol, the first request is load balanced to implement the interface level load balancing strategy. Among them, the priority of the interface level load balancing strategy can be set to be greater than the global level load balancing strategy, thereby improving the efficiency of load balancing.
[0069] In another implementation of the present invention, sending the second request to the second server includes: sending the second request to the second server configured outside the gateway through a generalized calling interface.
[0070] In another implementation of the present invention, the method further includes: starting the target process and executing the gateway program in the gateway; in the target process, initializing the generalized call interface. In other words, the generalized call interface is initialized in the target process, and a hot start is performed on the generalized call interface, thereby improving the response speed of the generalized call interface.
[0071] In addition, the generalized call parameters of the second calling protocol can be exposed to the client or the first server. For example, the triple parameter specified by the Dubbo protocol, namely, service name, version number, and group, can be exposed to the HTTP client or non-Dubbo server.
[0072] In another implementation of the present invention, the method is implemented by calling the gateway program of the gateway through the proxy program, and the method further includes: changing the underlying operating environment of the gateway program through the proxy program. For example, in the solution of this example, the Dubbo protocol conversion function in the gateway program can be executed non-invasively through Java Agent technology.
[0073] Figure 3 is a schematic block diagram of a communication method according to another embodiment of the present invention. Figure 3 The method may correspond to the method of Figure 2. HTTP2DubboRoutingFilter may obtain the first request in HTTP protocol format through Pre Filter. HTTP2DubboRoutingFilter processes the first request to obtain the second request in Dubbo protocol format.
[0074] Specifically, the URL may be processed to obtain a Dubbo protocol message including a specific triplet parameter.
[0075] Then, HTTP2DubboRoutingFilter sends a second request to Invoker. Invoker obtains the target logic of the Dubbo server according to the second request and returns the return value of the target logic to Invoker. The return value has the Dubbo protocol format.
[0076] Specifically, in Java Agent, Invoker and HTTP2DubboRoutingFilter can be configured as different modules. Invoker can be started when HTTP2DubboRoutingFilter is started. Invoker can receive Dubbo protocol messages from HTTP2DubboRoutingFilter, and parse the triplet parameters from the Dubbo protocol messages to obtain the target logic of the Dubbo server (e.g., provider).
[0077] Then, Invoker returns the return value to HTTP2DubboRoutingFilter. HTTP2DubboRoutingFilter converts the return value from Dubbo protocol format to HTTP protocol format and sends it to Post Filter for subsequent processing.
[0078] Specifically, the Dubbo protocol conversion filter can be inserted into the Filter chain through the Java Agent. Then, the Java Agent program can pull routing information (for example, routing information processed by adding, modifying or deleting) from the routing configuration server and provide timely feedback on routing strategies and Dubbo call interface processing.
[0079] The Dubbo protocol conversion filter can be loaded in the process of the gateway program, and the generalized call interface (Invoker) can be hot-started. In other words, the generalized call interface can be configured in the process of loading the Dubbo protocol conversion filter.
[0080] Figure 4 FIG. 4 is a structural block diagram of a gateway according to another embodiment of the present invention. Figure 4The gateway is applied to the microservice architecture. The gateway can be configured using Spring Cloud Gateway. The gateway receives access requests from the client and returns responses to the client. The server can include Dubbo servers and non-Dubbo servers such as HTTP servers. Dubbo servers use the Dubbo protocol for interface calls. HTTP servers use the HTTP protocol for interface calls. The gateway receives the request sent by the client and generates access requests to the HTTP server through the Pre Filter in the Filter chain specified by Spring Cloud Gateway and the NettyRoutingFilter of the communication framework Netty. The Dubbo server includes Provider and Consumer. Among them, Consumer can be embedded in the HTTP server, so that the HTTP server can call the logic of Provider through Consumer and obtain the return response of Provider. Then, the return response of Provider is processed by the filter chain such as NettyRoutingFilter and Post Filter to perform the call protocol, and then the response returned to the client is generated through the communication framework Netty.
[0081] Figure 4 The gateways include:
[0082] The acquisition module 410 acquires a first request based on a first calling protocol from a client or a first server of the microservice architecture.
[0083] It should be understood that the gateway in the text can be configured through Spring CloudGateway. The microservice architecture includes a client, a first server, and a second server. The client can communicate with the first server or the second server through the gateway. In other words, the client can send a request based on the first calling protocol to call the calling interface in the first server or the second server.
[0084] In addition, the first server can communicate with the second server through the gateway. For example, the first server can send a request based on the first calling protocol to the second server through the gateway to call the interface of the second server.
[0085] The conversion module 420 converts the first request into a second request based on a second calling protocol, where the second request is used to call the target logic of the second server of the microservice architecture.
[0086] It should be understood that the second server can be a Dubbo server, for example, a Dubbo provider. The second calling protocol can be a Dubbo protocol, an hsf protocol, or a Webservice protocol, etc. The second request can be an application programming interface (API) of the target logic or a generalized calling interface (Invoker) of the target logic.
[0087] The sending module 430 sends a second request to the second server.
[0088] It should be understood that the gateway sends a second request to a second server configured outside the gateway to obtain the target logic through an API or a generalized call interface.
[0089] In the solution of the embodiment of the present invention, the gateway can convert a first request based on a first calling protocol into a second request based on a second calling protocol, and send the second request to the server, thereby achieving consistency of the calling protocol and improving the interface calling efficiency of the microservice architecture.
[0090] In other examples, the acquisition module is specifically used to obtain an HTTP request from a client of a microservice architecture.
[0091] In other examples, the acquisition module is specifically used to: obtain a first request from a first server of a microservice architecture, the first server is configured with a script execution environment, and the first request is generated by the script execution environment based on a first calling protocol.
[0092] In other examples, the acquisition module is specifically used to: obtain an HTTP request from a first server of a microservice architecture, and the script running environment is Node.js.
[0093] In some other examples, the gateway further includes: a receiving module, receiving a second response to the second request from the second server, wherein the second response is based on a second calling protocol.
[0094] In some other examples, the conversion module is further used to: convert the second response into a first response based on the first calling protocol; and return the first response.
[0095] In some other examples, the acquisition module is further used to: acquire the current protocol conversion table to the gateway, the current protocol conversion table indicating the correspondence between the first calling protocol and the second calling protocol. The conversion module is specifically used to: convert the first request into a second request based on the second calling protocol according to the current protocol conversion table.
[0096] In other examples, the current protocol conversion table specifically indicates the relationship between the routing parameters of the first calling protocol and the attribute parameters of the second calling protocol.
[0097] In some other examples, the gateway further includes: a load balancing module, which performs load balancing on the first request according to the routing parameters of the first calling protocol. The sending module is specifically used to: send the second request to the second server according to the result of the load balancing.
[0098] In some other examples, the sending module is specifically used to send a second request to a second server configured outside the gateway through a generalized calling interface.
[0099] In some other examples, the gateway further includes: starting a target process and executing a gateway program in the gateway; and initializing the generalized call interface in the target process.
[0100] The device of this embodiment is used to implement the corresponding methods in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here. In addition, the functional implementation of each module in the device of this embodiment can refer to the description of the corresponding parts in the aforementioned method embodiments, which will not be repeated here.
[0101] Reference Figure 5 , shows a schematic structural diagram of an electronic device according to another embodiment of the present invention. The specific embodiment of the present invention does not limit the specific implementation of the electronic device.
[0102] like Figure 5 As shown, the electronic device may include: a processor (processor) 502 , a communication interface (Communications Interface) 504 , a memory (memory) 506 , and a communication bus 508 .
[0103] in:
[0104] The processor 502 , the communication interface 504 , and the memory 506 communicate with each other via a communication bus 508 .
[0105] The communication interface 504 is used to communicate with other electronic devices or servers.
[0106] The processor 502 is used to execute the program 510, and specifically can execute the relevant steps in the above method embodiment.
[0107] Specifically, the program 510 may include program codes, which include computer operation instructions.
[0108] The processor 502 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention. The one or more processors included in the smart device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0109] The memory 506 is used to store the program 510. The memory 506 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0110] Program 510 can be specifically used to enable the processor 502 to perform the following operations: obtain a first request based on a first calling protocol from a client or a first server of the microservice architecture; convert the first request into a second request based on a second calling protocol, wherein the second request is used to call the target logic of the second server of the microservice architecture; and send the second request to the second server.
[0111] In addition, the specific implementation of each step in program 510 can refer to the corresponding description of the corresponding steps and units in the above method embodiment, which will not be repeated here. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described devices and modules can refer to the corresponding process description in the above method embodiment, which will not be repeated here.
[0112] It should be pointed out that, according to the needs of implementation, the various components / steps described in the embodiments of the present invention can be split into more components / steps, or two or more components / steps or partial operations of components / steps can be combined into new components / steps to achieve the purpose of the embodiments of the present invention.
[0113] The above-described method according to an embodiment of the present invention may be implemented in hardware, firmware, or as software or computer code that may be stored in a recording medium (such as a CD ROM, RAM, floppy disk, hard disk, or magneto-optical disk), or as computer code that is originally stored in a remote recording medium or a non-temporary machine-readable medium downloaded over a network and will be stored in a local recording medium, so that the method described herein may be stored in such software processing on a recording medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware (such as an ASIC or FPGA). It is understood that a computer, processor, microprocessor controller, or programmable hardware includes a storage component (e.g., RAM, ROM, flash memory, etc.) that can store or receive software or computer code, and when the software or computer code is accessed and executed by a computer, processor, or hardware, the method described herein is implemented. In addition, when a general-purpose computer accesses the code for implementing the method shown herein, the execution of the code converts the general-purpose computer into a dedicated computer for executing the method shown herein.
[0114] Those of ordinary skill in the art will appreciate that the units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present invention.
[0115] The above implementation methods are only used to illustrate the embodiments of the present invention, and are not limitations of the embodiments of the present invention. Ordinary technicians in the relevant technical field may make various changes and modifications without departing from the spirit and scope of the embodiments of the present invention. Therefore, all equivalent technical solutions also belong to the scope of the embodiments of the present invention. The patent protection scope of the embodiments of the present invention should be defined by the claims.
Claims
1. A communication method, applied to a gateway of a microservice architecture, include: Acquire a current protocol conversion table into the gateway, wherein the current protocol conversion table indicates a correspondence between a first calling protocol and a second calling protocol; A first request based on a first calling protocol is obtained from a client or a first server of the microservice architecture, where the first server is a non-Dubbo server; the first request is an HTTP request obtained from a client of the microservice architecture, or the first request is obtained by obtaining an HTTP request from a first server of the microservice architecture, and is generated based on the first calling protocol by a script running environment configured by the first server, where the script running environment is Node.js, wherein when the access traffic of the gateway is east-west traffic, the first calling protocol is a Dubbo calling protocol; when the access traffic of the gateway is north-south traffic, a URI request is configured based on HTTP; According to the current protocol conversion table, the first request is converted into a second request based on a second calling protocol, the second request is used to call the target logic of the second server of the microservice architecture, the second server is the Dubbo server; the second calling protocol is the protocol adopted by the Dubbo server; the second request is the application program interface or generalized calling interface of the target logic; the application program interface is the calling interface between Consumer and Provider; the Provider is the service provider for exposing services in the Dubbo server; the Consumer is the service consumer for calling remote services in the Dubbo server; the generalized calling interface is to call the logic in the Provider through a request including generalized interface parameters; Sending the second request to the second server; The method is implemented by calling the gateway program of the gateway through an agent program, and the method further comprises: Changing the underlying operating environment of the gateway program through the proxy program; The method further comprises: Start the target process and execute the gateway program in the gateway; In the target process, the generalized calling interface is initialized.
2. The method according to claim 1, in, The method further comprises: A second response to the second request is received from the second server, where the second response is based on the second calling protocol.
3. The method according to claim 2, in, The method further comprises: converting the second response into a first response based on the first calling protocol; The first response is returned.
4. The method according to claim 1, in, The current protocol conversion table specifically indicates the relationship between the routing parameters of the first calling protocol and the attribute parameters of the second calling protocol.
5. The method according to claim 4, in, The method further comprises: load balancing the first request according to the routing parameters of the first calling protocol; The sending the second request to the second server includes: According to the result of the load balancing, the second request is sent to the second server.
6. The method according to claim 1, in, The sending the second request to the second server includes: The second request is sent to the second server configured outside the gateway through a generalized calling interface.
7. A gateway, applied to microservice architecture, include: An acquisition module is provided to acquire a current protocol conversion table into the gateway, wherein the current protocol conversion table indicates a correspondence between a first calling protocol and a second calling protocol, and acquire a first request based on the first calling protocol from a client or a first server of the microservice architecture, wherein the first server is a non-Dubbo server; the first request is an HTTP request acquired from a client of the microservice architecture, or the first request is generated based on the first calling protocol by a script running environment configured on the first server after acquiring an HTTP request from the first server of the microservice architecture, wherein the script running environment is Node.js, wherein when the access traffic of the gateway is east-west traffic, the first calling protocol is a Dubbo calling protocol; when the access traffic of the gateway is north-south traffic, a URI request is configured based on HTTP; A conversion module, according to the current protocol conversion table, converts the first request into a second request based on a second calling protocol, wherein the second request is used to call the target logic of the second server of the microservice architecture, and the second server is a Dubbo server; the second calling protocol is the protocol adopted by the Dubbo server; the second request is an application program interface or a generalized calling interface of the target logic; the application program interface is a calling interface between Consumer and Provider; the Provider is a service provider for exposing services in the Dubbo server; the Consumer is a service consumer for calling remote services in the Dubbo server; the generalized calling interface is to call the logic in the Provider through a request including generalized interface parameters; A sending module, sending the second request to the second server; An agent program calls a gateway program of the gateway and changes the underlying operating environment of the gateway program; The gateway further includes: starting a target process and executing a gateway program in the gateway; and initializing the generalized calling interface in the target process.
8. An electronic device, include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform an operation corresponding to the method according to any one of claims 1 to 6.
