Communication method and apparatus of client, electronic device and storage medium
Patent Information
- Application Number
- CN202310144184.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-09
- Publication Date
- 2026-09-11
- Estimated Expiration
- 2043-02-09
AI Technical Summary
[0003]对于大型的微服务架构项目而言,通常具有负载均衡的优化逻辑,导致每个访问微服务的客户端无法预计所连接的是微服务架构中的哪个服务端,使得微服务架构中客户端之间的通信存在技术壁垒
[0011]The aforementioned client communication method, device, electronic device, and storage medium are applied to a microservice architecture, which includes at least one server and at least two microservice clients. The method comprises: any server in the microservice architecture responding to a communication instruction from a first microservice client to a second microservice client; constructing a first microservice message channel and a second microservice message channel between the first microservice client and the second microservice client based on a preset remote procedure call protocol; the first microservice message channel receiving messages sent from the first microservice client to the second microservice client; and the second microservice message channel receiving messages sent from the second microservice client to the first microservice client; monitoring the first and second microservice message channels; and when the first microservice message channel detects a message, sending the detected message to the second microservice client; and when the second microservice message channel detects a message, sending the detected message to the first microservice client. In this approach, any server in the microservice architecture can respond to communication commands from any microservice client to another microservice client. Based on a predefined remote procedure call protocol, a first microservice message channel and a second microservice message channel are constructed in the microservice architecture. These channels are used for one microservice client to send messages to another microservice client and to receive messages from another microservice client. By having any server in the microservice architecture listen to the first and second microservice message channels, message synchronization between the two microservice clients can be achieved. This reduces the difficulty of communication between microservice clients by requiring only the definition of a protocol and the construction of message channels.
Smart Images

Figure CN116319964B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communication technology, and in particular to a client communication method, apparatus, electronic device, and storage medium. Background Technology
[0002] Microservice architecture is a variant of service-oriented architecture (SOA) that divides a single application into a set of services that coordinate and cooperate with each other. A single application consists of many loosely coupled and independently deployable components or services.
[0003] For large-scale microservice architecture projects, there is usually load balancing optimization logic, which makes it impossible for each client accessing the microservices to predict which server in the microservice architecture it is connecting to, creating a technical barrier to communication between clients in the microservice architecture.
[0004] Existing technologies typically require the introduction of additional technology stacks when implementing client communication in microservices, which increases the difficulty of implementing client communication. Summary of the Invention
[0005] In view of this, the purpose of the present invention is to provide a client communication method, apparatus, electronic device and storage medium to reduce the implementation difficulty of microservice client communication.
[0006] In a first aspect, embodiments of the present invention provide a client communication method applied to a microservice architecture, the microservice architecture including at least one server and at least two microservice clients. The method includes: any server in the microservice architecture responding to a communication instruction from a first microservice client to a second microservice client, constructing a first microservice message channel and a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture based on a preset remote procedure call protocol; the first microservice message channel being used to receive messages sent from the first microservice client to the second microservice client, and the second microservice message channel being used to receive messages sent from the second microservice client to the first microservice client; monitoring the first microservice message channel and the second microservice message channel; when the first microservice message channel detects a message, sending the detected message to the second microservice client; and when the second microservice message channel detects a message, sending the detected message to the first microservice client.
[0007] Secondly, embodiments of the present invention provide a client communication device, the device comprising: an application to a microservice architecture, the microservice architecture including at least one server and at least two microservice clients, the device comprising: a response module, configured to, in response to a communication instruction from a first microservice client to a second microservice client, construct a first microservice message channel and a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture based on a preset remote procedure call protocol, wherein the first microservice message channel is configured to receive messages sent from the first microservice client to the second microservice client, and the second microservice message channel is configured to receive messages sent from the second microservice client to the first microservice client; a listening module, configured to listen to the first microservice message channel and the second microservice message channel, and when the first microservice message channel listens to a message, send the listened-to message to the second microservice client; and a sending module, configured to, when the second microservice message channel listens to a message, send the listened-to message to the first microservice client.
[0008] Thirdly, embodiments of the present invention provide an electronic device, including a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the aforementioned client communication method.
[0009] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing computer-executable instructions. When the computer-executable instructions are invoked and executed by a processor, the computer-executable instructions cause the processor to implement the aforementioned client communication method.
[0010] The embodiments of the present invention bring the following beneficial effects:
[0011] The aforementioned client communication method, device, electronic device, and storage medium are applied to a microservice architecture, which includes at least one server and at least two microservice clients. The method comprises: any server in the microservice architecture responding to a communication instruction from a first microservice client to a second microservice client; constructing a first microservice message channel and a second microservice message channel between the first microservice client and the second microservice client based on a preset remote procedure call protocol; the first microservice message channel receiving messages sent from the first microservice client to the second microservice client; and the second microservice message channel receiving messages sent from the second microservice client to the first microservice client; monitoring the first and second microservice message channels; and when the first microservice message channel detects a message, sending the detected message to the second microservice client; and when the second microservice message channel detects a message, sending the detected message to the first microservice client. In this approach, any server in the microservice architecture can respond to communication commands from any microservice client to another microservice client. Based on a predefined remote procedure call protocol, a first microservice message channel and a second microservice message channel are constructed in the microservice architecture. These channels are used for one microservice client to send messages to another microservice client and to receive messages from another microservice client. By having any server in the microservice architecture listen to the first and second microservice message channels, message synchronization between the two microservice clients can be achieved. This reduces the difficulty of communication between microservice clients by requiring only the definition of a protocol and the construction of message channels.
[0012] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0013] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0014] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0015] Figure 1 This is a flowchart of one embodiment of the client communication method in this invention;
[0016] Figure 2 This is a flowchart of another embodiment of the client communication method in this invention;
[0017] Figure 3 A schematic diagram of a client communication device provided in an embodiment of the present invention;
[0018] Figure 4 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” or “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0021] For ease of understanding, the specific process of this invention embodiment is described below. In this invention embodiment, the client communication method is applied to a microservice architecture, which includes at least one server and at least two microservice clients. It should be noted that microservice architecture differs fundamentally from monolithic application architecture. In a monolithic application, all functional services are contained within a single application, and the various functional service modules are highly coupled, making them difficult to split and scale. In contrast, microservice architecture divides an application into several services, which work collaboratively, are small and autonomous, and possess technical heterogeneity, isolation, scalability, simplified deployment, and ease of optimization. Understandably, a microservice architecture can be used to provide a microservice client with multiple services corresponding to a single application, or it can be used to provide a microservice client with multiple services corresponding to multiple applications. The microservice client requests services from the microservice architecture through the target application. The microservice architecture contains at least one server of the target application and at least two microservice clients. Each microservice client can request services from one server or multiple servers. A server can contain one service or multiple services. Different servers can provide the same or different services, and there are no specific restrictions here.
[0022] Please see Figure 1 One embodiment of the client communication method in this invention includes:
[0023] Step S10: In the microservice architecture, any server responds to the communication command from the first microservice client to the second microservice client, and constructs a first microservice message channel and a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture based on a preset remote call protocol. The first microservice message channel is used to receive messages sent from the first microservice client to the second microservice client, and the second microservice message channel is used to receive messages sent from the second microservice client to the first microservice client.
[0024] It is understandable that microservice architectures are typically used in large applications, and to improve overall application performance, they also include load balancing algorithms. These load balancing algorithms determine the target server in the microservice architecture that responds to a communication command from a first microservice client to a second microservice client. In other words, when a microservice client issues a communication command, it does not determine which client it will connect to and provide services to. Therefore, it is difficult for a microservice client to directly communicate with another specified microservice client within the microservice architecture. Based on this, this invention reconstructs a communication method between microservice clients in a load-balanced microservice architecture. This step involves any server in the microservice architecture responding to a communication command from any microservice client to another microservice client (i.e., a communication command from the first microservice client to the second microservice client), and then constructing a first microservice message channel and a second microservice message channel between the first and second microservice clients in the microservice architecture based on a preset Remote Procedure Call (RPC) protocol. It should be noted that the first microservice client and the second microservice client can be any microservice client in the microservice architecture, such as communication instructions from microservice client A to microservice client B, communication instructions from microservice client B to microservice client A, or communication instructions from microservice client A to microservice client C, etc., without any specific restrictions here.
[0025] Understandably, the first microservice message channel is used to receive messages sent from the first microservice client to the second microservice client, and the second microservice message channel is used to receive messages sent from the second microservice client to the first microservice client. In other words, the first and second microservice clients communicate through two dedicated message channels. One message channel is used for one microservice client to send messages, and the other is used for the other microservice client to send messages. For example, microservice client A sends a message to message channel A1, and microservice client B sends a message to message channel B1. Subsequently, communication between the two microservice clients is achieved by listening to messages on both message channels and synchronizing the detected messages to their respective microservice clients.
[0026] It should be noted that any microservice client in a microservice architecture can send communication commands to a second microservice client through the target application it installs. Specifically, any microservice client in the microservice architecture can send these commands through any service module within the target application it installs. For example, comment service modules, message service modules, and real-time messaging service modules in the target application can all communicate between any two microservice clients; specific details are not limited here.
[0027] In one implementation, the preset remote procedure call protocol is the streaming remote procedure call protocol gRPC, including bidirectional streaming RPC. A first microservice message channel and a second microservice message channel exist between the first microservice client and the second microservice client in a microservice architecture built on bidirectional streaming RPC. Both the first and second microservice message channels are bidirectional streaming RPC channels, meaning that both the microservice client and server can send a series of messages through these read / write data streams (i.e., bidirectional streaming RPC channels). These two data stream operations are independent of each other, so the microservice client and server can read and write in any desired order. For example, the server can wait for all microservice client messages before writing an acknowledgment, or the server can read one message before writing another, or use other methods combining read and write. The order of messages within each data stream is maintained.
[0028] In one implementation, in a microservice architecture, any server responds to a communication command from a first microservice client to a second microservice client, obtains the identification information of the first and second microservice clients, and obtains first identification information corresponding to the first microservice client and second identification information corresponding to the second microservice client. Based on a preset remote procedure call protocol, a first microservice message channel and a second microservice message channel are constructed between the first and second microservice clients in the microservice architecture according to the first and second identification information. The identification information of the first and second microservice clients can be information that can be used to uniquely identify a microservice client, such as the identification information of the client device, the identification information of the client application, or the identification information of the client user; no specific limitation is made here.
[0029] It should be noted that the first microservice message channel and the second microservice message channel can be constructed by different servers at different times. For example, the first microservice message channel can be constructed when the first microservice client sends a message to the second microservice client, and the second microservice message channel can be constructed when the second microservice client sends a message to the first microservice client. Specifically, in one embodiment, step S10 includes: any server in the microservice architecture responding to a message sending instruction from the first microservice client to the second microservice client, constructing a first microservice message channel between the first microservice client and the second microservice client in the microservice architecture based on a preset remote procedure call protocol, wherein the first microservice message channel is used to receive messages sent from the first microservice client to the second microservice client; any server in the microservice architecture responding to a message sending instruction from the second microservice client to the first microservice client, constructing a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture based on a preset remote procedure call protocol, wherein the second microservice message channel is used to receive messages sent from the second microservice client to the first microservice client. The server used to respond to the message sending instruction from the first microservice client to the second microservice client and the server used to respond to the message sending instruction from the second microservice client to the first microservice client are determined according to the load balancing algorithm in the microservice architecture. They can be the same server or different servers, and no specific limitation is made here.
[0030] Step S20: Listen to the first microservice message channel and the second microservice message channel. When the first microservice message channel detects a message, send the detected message to the second microservice client.
[0031] It should be noted that since the first microservice message channel and the second microservice message channel can be constructed by different servers at different times, after step S10, the method further includes: storing the channel identification information of the first microservice message channel and the second microservice message channel in the target database; when executing step S20, reading the channel identification information of the first microservice message channel and the second microservice message channel from the target database through any server in the microservice architecture, and listening to the first microservice message channel and the second microservice message channel through the channel identification information; when the first microservice message channel listens to a message, sending the listened message to the second microservice client according to the channel identification information of the first microservice message channel; and when the second microservice message channel listens to a message, sending the listened message to the first microservice client according to the channel identification information of the second microservice message channel, which is the specific execution process of step S30 below. This implementation uses database storage for channel identification information, so that message channel listening does not depend on the server that builds the message channel. Instead, any server in the microservice architecture can listen to and send the listened messages to the microservice client, breaking the uncertainty of the load balancing algorithm's designated server and improving the stability of communication between microservice clients.
[0032] In one implementation, to determine the order in which messages are detected, when the first microservice message channel detects a message, it records the current timestamp and sends the detected message and the current timestamp to the first microservice client. This allows the first microservice client to sort the messages by time based on their corresponding timestamps, thereby improving the accuracy of communication.
[0033] Step S30: When the second microservice message channel detects a message, it sends the detected message to the first microservice client.
[0034] In one implementation, to determine the order in which messages are detected, when the second microservice message channel detects a message, it records the current timestamp and sends the detected message and the current timestamp to the second microservice client. This allows the second microservice client to sort the messages by time based on their corresponding timestamps, thereby improving the accuracy of communication.
[0035] The client communication method provided in the above implementation allows any server in the microservice architecture to respond to communication instructions from any microservice client to another microservice client. Based on a predefined remote procedure call protocol, a first microservice message channel and a second microservice message channel are constructed within the microservice architecture. These channels are used for one microservice client to send messages to another microservice client and to receive messages from another microservice client. By having any server in the microservice architecture listen to the first and second microservice message channels, message synchronization between the two microservice clients can be achieved. This reduces the difficulty of communication between microservice clients by requiring only the definition of a protocol and the construction of message channels.
[0036] Please see Figure 2 Another embodiment of the client communication method in this invention includes:
[0037] Step S201: In response to the communication instruction from the first microservice client to the second microservice client, any server in the microservice architecture determines the first identifier of the first microservice client, the second identifier of the second microservice client, and the microservice identifier. The microservice identifier is used to indicate the communicable microservices between the first microservice client and the second microservice client.
[0038] In this embodiment, to simplify the communication mechanism of microservice clients in a microservice architecture, when any server responds to a communication command from one microservice client to another, it obtains the first identifier of the first microservice client, the second identifier of the second microservice client, and the microservice identifier through a preset remote procedure call protocol. The microservice identifier indicates whether the first and second microservice clients can call the same microservice, i.e., the communicable microservices between them. For example, assuming the first identifier is the user ID of the target application in the first microservice client, and the second identifier is the user ID of the target application in the second microservice client, then the microservice identifier can be the identifier of the target application, used to indicate whether the first and second microservice clients are users in the same application; the specific meaning is not limited here.
[0039] Step S202: Determine whether the message channel between the first microservice client and the second microservice client has been monitored by using the first identifier, the second identifier, and the microservice identifier;
[0040] In this embodiment, to avoid resource waste and data corruption caused by repeated listening, it is determined whether a message channel between the first microservice client and the second microservice client already exists based on the first identifier, the second identifier, and the microservice identifier. If it exists, it means that listening has been performed; otherwise, it means that listening has not been performed. In one embodiment, the first identifier, the second identifier, and the microservice identifier are queried from a preset database to obtain the query results. Based on the query results, it is determined whether the preset database query contains listening information for the message channel between the first microservice client and the second microservice client. If it exists, it is determined that the message channel between the first microservice client and the second microservice client has been listened to; otherwise, it is determined that the message channel between the first microservice client and the second microservice client has not been listened to.
[0041] In one implementation, step S202 includes: generating a first listening identifier for the first microservice client and a second listening identifier for the second microservice client based on the first identifier, the second identifier, and the microservice identifier; querying the first listening identifier and the second listening identifier in a preset database to obtain the query result; and determining, based on the query result, whether the message channel between the first microservice client and the second microservice client has been monitored.
[0042] In this embodiment, the first identifier, the second identifier, and the microservice identifier can be combined into an ordered string as the listening identifier for the microservice client. By querying the first and second listening identifiers in a preset database, the query results can indicate whether the first and / or second listening identifiers exist in the preset database, or they can indicate the query values corresponding to the first and second listening identifiers in the preset database, with different query values indicating different listening states. For example, assuming the first identifier is A, the second identifier is B, and the microservice identifier is app1, then the first listening identifier for the first microservice client can be "app1-AB", and the second listening identifier for the second microservice client can be "app1-BA", with no specific limitation here. In one embodiment, the listening identifiers (including the first and second listening identifiers) are stored in the preset database in key-value pairs. The listening identifiers can also be used to indicate the listening state of the microservice message channels (including the first and second microservice message channels), where the listening state includes being listened to and not being listened to. For example, assuming the first listening identifier is "app1-AB", then "app1-AB:1" can indicate that the first microservice message channel between the first microservice client A and the second microservice client B of the target application app1 has been listened to, and "app1-AB:0" can indicate that the first microservice message channel between the first microservice client A and the second microservice client B of the target application app1 has not been listened to. Listening is not limited here.
[0043] Furthermore, in one embodiment, the query result is used to indicate whether a first listening identifier and / or a second listening identifier exist in a preset database; based on the query result, determining whether the message channel between the first microservice client and the second microservice client has been monitored includes: if the query result indicates that the first listening identifier and the second listening identifier do not exist in the preset database, then it is determined that the message channel between the first microservice client and the second microservice client has not been monitored; if the query result indicates that the first listening identifier does not exist in the preset database and the second listening identifier exists, then it is determined that the first microservice message channel between the first microservice client and the second microservice client has not been monitored, and the second microservice message channel has been monitored; if the query result indicates that the first listening identifier exists in the preset database and the second listening identifier does not exist, then it is determined that the first microservice message channel between the first microservice client and the second microservice client has been monitored, and the second microservice message channel has not been monitored.
[0044] In this embodiment, since the first microservice message channel and the second microservice message channel between the first microservice client and the second microservice client can be constructed and listened to by different servers at different times, when determining whether the message channel between the first microservice client and the second microservice client has been listened to, it is possible to determine whether the first microservice message channel has been listened to and whether the second microservice message channel has been listened to, respectively. Specifically, in this embodiment, the query result is used to indicate whether a first listening identifier and / or a second listening identifier exist in the preset database. If neither the first nor the second listening identifier exists in the preset database, it means that the message channel between the first microservice client and the second microservice client is not being listened to. If the first listening identifier does not exist in the preset database, but the second listening identifier exists, it means that the first microservice message channel has not been listened to, and the second microservice message channel has been listened to. If the first listening identifier exists in the preset database, but the second listening identifier does not exist, it means that the first microservice message channel has been listened to, and the second microservice message channel has not been listened to. If both the first and second listening identifiers exist in the preset database, it means that the message channel between the first and second microservice clients has been listened to, and the subsequent steps can be completed without executing "listening to the first and second microservice message channels" in steps S203 and S204.
[0045] Step S203: If the message channel between the first microservice client and the second microservice client is not being listened to, then a first microservice message channel and a second microservice message channel are constructed between the first microservice client and the second microservice client in the microservice architecture based on a preset remote call protocol. The first microservice message channel is used to receive messages sent from the first microservice client to the second microservice client, and the second microservice message channel is used to receive messages sent from the second microservice client to the first microservice client.
[0046] In this step, if neither the message channel between the first microservice client nor the second microservice client is being listened to, that is, if the query result indicates that the first listening identifier and the second listening identifier exist in the preset database, then the first microservice message channel and the second microservice message channel between the first microservice client and the second microservice client in the microservice architecture are constructed based on the preset remote call protocol.
[0047] In one implementation, if the first microservice message channel between the first microservice client and the second microservice client is not being monitored, but the second microservice message channel is being monitored, then a first microservice message channel between the first microservice client and the second microservice client in the microservice architecture is constructed based on a preset remote invocation protocol; if the first microservice message channel between the first microservice client and the second microservice client is being monitored, but the second microservice message channel is not being monitored, then a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture is constructed based on a preset remote invocation protocol.
[0048] In this embodiment, if the first microservice message channel between the first microservice client and the second microservice client is not being monitored, but the second microservice message channel is being monitored (meaning the query result indicates that the first monitoring identifier does not exist in the preset database, but the second monitoring identifier does), then the first microservice message channel between the first microservice client and the second microservice client in the microservice architecture can be constructed based on the preset remote call protocol. Specifically, the first monitoring identifier is generated and stored in the preset database. Conversely, if the first microservice message channel between the first microservice client and the second microservice client is being monitored, but the second microservice message channel is not being monitored (meaning the query result indicates that the first monitoring identifier exists in the preset database, but the second monitoring identifier does not), then the second microservice message channel between the first microservice client and the second microservice client in the microservice architecture can be constructed based on the preset remote call protocol. Specifically, the second monitoring identifier is generated and stored in the preset database.
[0049] Step S204: Listen to the first microservice message channel and the second microservice message channel. When the first microservice message channel detects a message, send the detected message to the second microservice client.
[0050] In one implementation, after listening to the first microservice message channel and the second microservice message channel, a listening lock can be configured for each of the first and second microservice message channels to avoid duplicate listening.
[0051] In one implementation, a first microservice message channel and a second microservice message channel are used to indicate message queues. The first and second microservice message channels are monitored. When the first microservice message channel detects a message, it sends the detected message to the second microservice client. This includes: blocking message retrieval from the first microservice message channel using a preset first blocking monitoring instruction, and blocking message retrieval from the second microservice message channel using a preset second blocking monitoring instruction. The first and second blocking monitoring instructions include a monitoring timeout duration. When a message is retrieved from the first microservice message channel within the monitoring timeout duration, the message retrieved from the first microservice message channel is sent to the second microservice client.
[0052] In this embodiment, the default database is a Redis relational database. Both the first and second microservice message channels are Redis message queues, which are blocking queues. During step S204, blocking message retrieval is performed on the first and second microservice message channels using Redis's "blocking" message retrieval commands (including a first blocking listener command and a second blocking listener command, such as BRPOP / BLPOP). If the blocking queue is empty, the system blocks and waits while retrieving messages. Once a new message enters the blocking queue, it is immediately sent to the corresponding microservice client. That is, once the first microservice message channel receives a new message, it immediately sends it to the second microservice client, and vice versa. If there are no new messages, the system blocks and waits for new messages according to the listener timeout duration specified in the message retrieval commands (including the first and second blocking listener commands). The listener timeout durations in the first and second blocking listener commands can be the same or different; there is no limitation on the listening duration here.
[0053] Step S205: When the second microservice message channel detects a message, it sends the detected message to the first microservice client.
[0054] In one implementation, step S205 includes: when a message is retrieved from the second microservice message channel within the listening timeout period, sending the retrieved message from the second microservice message channel to the first microservice client. In this implementation, if a message is retrieved from the second microservice message channel using a preset second blocking listening instruction, and a new message from the second microservice message channel is retrieved within the listening timeout period corresponding to the second blocking listening instruction, the retrieved new message is immediately sent to the first microservice client.
[0055] In one implementation, if no message is retrieved from the first microservice message channel within the listening timeout period, the listening lock of the first microservice message channel is released; similarly, if no message is retrieved from the second microservice message channel within the listening timeout period, the listening lock of the second microservice message channel is released. In this implementation, if no new message is retrieved from the first microservice message channel within the listening timeout period, to reduce resource consumption, the listening lock of the first microservice message channel is released, making the first microservice message channel unlistened; similarly, if no new message is retrieved from the second microservice message channel within the listening timeout period, the listening lock of the second microservice message channel is released, making the second microservice message channel unlistened. This reduces resource consumption.
[0056] In one implementation, the above-mentioned method of releasing the listening lock of the first microservice message channel if no message is retrieved from the first microservice message channel within the listening timeout period includes: if no message is retrieved from the first microservice message channel within the listening timeout period, deleting the first listening identifier of the first microservice client in the preset database, the first listening identifier being used to indicate whether the second microservice message channel is being listened to; and releasing the listening lock of the second microservice message channel if no message is retrieved from the second microservice message channel within the listening timeout period includes: if no message is retrieved from the second microservice message channel within the listening timeout period, deleting the second listening identifier of the second microservice client in the preset database, the second listening identifier being used to indicate whether the first microservice message channel is being listened to.
[0057] In this embodiment, the listening identifier (including the first listening identifier and the second listening identifier) can be used to indicate the listening lock. Specifically, the first listening identifier is used to indicate the listening lock of the first microservice message channel, and the second listening identifier is used to indicate the listening lock of the second microservice message channel. If no new message is retrieved from the first microservice message channel within the listening timeout period, the listening lock of the first microservice message channel can be released by deleting the first listening identifier from the preset database. Similarly, if no new message is retrieved from the second microservice message channel within the listening timeout period, the listening lock of the second microservice message channel can be released by deleting the second listening identifier from the preset database. This makes the listening status of the microservice message channel simpler and more controllable.
[0058] The client communication method provided in the above implementation allows any server in the microservice architecture to respond to communication instructions from any microservice client to another microservice client. Based on a predefined remote procedure call protocol, a first microservice message channel and a second microservice message channel are constructed within the microservice architecture. These channels are used for one microservice client to send messages to another microservice client and to receive messages from another microservice client. By having any server in the microservice architecture listen to the first and second microservice message channels, message synchronization between the two microservice clients can be achieved. This reduces the difficulty of communication between microservice clients by requiring only the definition of a protocol and the construction of message channels.
[0059] For the corresponding method embodiments described above, see [link to relevant documentation]. Figure 3 The diagram illustrates a client communication device applied to a microservice architecture. The microservice architecture includes at least one server and at least two microservice clients. The device includes: a response module 30, used by any server in the microservice architecture to respond to a communication command from a first microservice client to a second microservice client, and to construct a first microservice message channel and a second microservice message channel between the first microservice client and the second microservice client based on a preset remote procedure call protocol. The first microservice message channel is used to receive messages sent from the first microservice client to the second microservice client, and the second microservice message channel is used to receive messages sent from the second microservice client to the first microservice client; a listening module 32, used to listen to the first microservice message channel and the second microservice message channel, and to send the listened-upon message to the second microservice client when the first microservice message channel listens for a message; and a sending module 34, used to send the listened-upon message to the first microservice client when the second microservice message channel listens for a message.
[0060] In the aforementioned device, any server in the microservice architecture can respond to communication commands from any microservice client to another microservice client. Based on a predefined remote procedure call protocol, a first microservice message channel and a second microservice message channel are constructed in the microservice architecture. These channels are used for one microservice client to send messages to another microservice client and to receive messages sent by another microservice client. By having any server in the microservice architecture listen to the first and second microservice message channels, message synchronization between the two microservice clients can be achieved. This reduces the difficulty of communication between microservice clients by requiring only the definition of a protocol and the construction of message channels.
[0061] The response module 30 includes: a determination submodule, used by any server in the microservice architecture to determine the first identifier of the first microservice client, the second identifier of the second microservice client, and a microservice identifier in response to a communication instruction from the first microservice client to the second microservice client, wherein the microservice identifier is used to indicate the communicable microservices between the first microservice client and the second microservice client; a judgment submodule, used to determine whether the message channel between the first microservice client and the second microservice client has been monitored by using the first identifier, the second identifier, and the microservice identifier; and a construction submodule, used to construct the first microservice message channel and the second microservice message channel between the first microservice client and the second microservice client in the microservice architecture based on a preset remote procedure call protocol if the message channel between the first microservice client and the second microservice client has not been monitored.
[0062] The aforementioned judgment submodule includes: a generation unit, used to generate a first listening identifier for the first microservice client and a second listening identifier for the second microservice client based on the first identifier, the second identifier, and the microservice identifier; a query unit, used to query the first listening identifier and the second listening identifier in a preset database to obtain the query result; and a judgment unit, used to determine whether the message channel between the first microservice client and the second microservice client has been monitored based on the query result.
[0063] The above query results are used to indicate whether the first listening identifier and / or the second listening identifier exist in the preset database;
[0064] The aforementioned judgment unit is specifically used for: if the query result indicates that the first listening identifier and the second listening identifier do not exist in the preset database, then it is determined that the message channel between the first microservice client and the second microservice client is not being listened to; if the query result indicates that the first listening identifier does not exist in the preset database and the second listening identifier exists, then it is determined that the first microservice message channel between the first microservice client and the second microservice client is not being listened to, and the second microservice message channel has been listened to; if the query result indicates that the first listening identifier exists in the preset database and the second listening identifier does not exist, then it is determined that the first microservice message channel between the first microservice client and the second microservice client has been listened to, and the second microservice message channel has not been listened to.
[0065] The aforementioned apparatus further includes: a first construction module, configured to construct a first microservice message channel between the first microservice client and the second microservice client in the microservice architecture based on a preset remote invocation protocol if the first microservice message channel between the first microservice client and the second microservice client is not being monitored, and the second microservice message channel is being monitored; and a second construction module, configured to construct a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture based on a preset remote invocation protocol if the first microservice message channel between the first microservice client and the second microservice client is being monitored, and the second microservice message channel is not being monitored.
[0066] The aforementioned first microservice message channel and second microservice message channel are used to indicate message queues. The aforementioned listening module 32 is further used to: pull blocked messages from the first microservice message channel through a preset first blocking listening instruction, and pull blocked messages from the second microservice message channel through a preset second blocking listening instruction. The first blocking listening instruction and the second blocking listening instruction include a listening timeout duration. When a message is pulled from the first microservice message channel within the listening timeout duration, the message pulled from the first microservice message channel is sent to the second microservice client. The aforementioned sending module 34 is further used to: when a message is pulled from the second microservice message channel within the listening timeout duration, the message pulled from the second microservice message channel is sent to the first microservice client.
[0067] The aforementioned device further includes: a first release module, used to release the listening lock of the first microservice message channel if no message is retrieved from the first microservice message channel within the listening timeout period; and a second release module, used to release the listening lock of the second microservice message channel if no message is retrieved from the second microservice message channel within the listening timeout period.
[0068] The first release module is further configured to: if no message is retrieved from the first microservice message channel within the listening timeout period, delete the first listening identifier of the first microservice client in the preset database. The first listening identifier is used to indicate whether the second microservice message channel is being listened to. The second release module is further configured to: if no message is retrieved from the second microservice message channel within the listening timeout period, delete the second listening identifier of the second microservice client in the preset database. The second listening identifier is used to indicate whether the first microservice message channel is being listened to.
[0069] This embodiment also provides an electronic device, including a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor. The processor executes the machine-executable instructions to implement the aforementioned client communication method. This electronic device can be a server or a terminal device.
[0070] See Figure 4 As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine-executable instructions that can be executed by the processor 100. The processor 100 executes the machine-executable instructions to implement the aforementioned client communication method.
[0071] Furthermore, Figure 4 The electronic device shown also includes a bus 102 and a communication interface 103, with the processor 100, the communication interface 103 and the memory 101 connected via the bus 102.
[0072] The memory 101 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 103 (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network. The bus 102 may be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 4 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0073] Processor 100 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 100 or by instructions in software form. Processor 100 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a readily available storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 101. The processor 100 reads information from memory 101 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments, for example:
[0074] In a microservice architecture, any server responds to a communication command from a first microservice client to a second microservice client. Based on a preset remote procedure call protocol, a first microservice message channel and a second microservice message channel are established between the first and second microservice clients. The first microservice message channel is used to receive messages sent from the first microservice client to the second microservice client, and the second microservice message channel is used to receive messages sent from the second microservice client to the first microservice client. The first and second microservice message channels are monitored. When the first microservice message channel detects a message, it sends the detected message to the second microservice client; when the second microservice message channel detects a message, it sends the detected message to the first microservice client.
[0075] In this approach, any server in the microservice architecture can respond to communication commands from any microservice client to another microservice client. Based on a predefined remote procedure call protocol, a first microservice message channel and a second microservice message channel are constructed in the microservice architecture. These channels are used for one microservice client to send messages to another microservice client and to receive messages from another microservice client. By having any server in the microservice architecture listen to the first and second microservice message channels, message synchronization between the two microservice clients can be achieved. This reduces the difficulty of communication between microservice clients by requiring only the definition of a protocol and the construction of message channels.
[0076] In the aforementioned microservice architecture, any server responding to a communication command from the first microservice client to the second microservice client constructs a first microservice message channel and a second microservice message channel between the first and second microservice clients based on a preset remote invocation protocol. This includes: responding to a communication command from the first microservice client to the second microservice client, determining a first identifier of the first microservice client, a second identifier of the second microservice client, and a microservice identifier. The microservice identifier indicates the communicable microservices between the first and second microservice clients. The server then determines whether the message channel between the first and second microservice clients has been monitored using the first identifier, the second identifier, and the microservice identifier. If the message channel between the first and second microservice clients has not been monitored, the server constructs the first and second microservice message channels between the first and second microservice clients based on the preset remote invocation protocol.
[0077] The above method of determining whether the message channel between the first microservice client and the second microservice client has been monitored using the first identifier, the second identifier, and the microservice identifier includes: generating a first monitoring identifier for the first microservice client and a second monitoring identifier for the second microservice client based on the first identifier, the second identifier, and the microservice identifier; querying the first monitoring identifier and the second monitoring identifier in a preset database to obtain the query results; and determining whether the message channel between the first microservice client and the second microservice client has been monitored based on the query results.
[0078] The above query results are used to indicate whether the first listening identifier and / or the second listening identifier exist in the preset database;
[0079] The determination of whether the message channel between the first microservice client and the second microservice client has been monitored based on the query results includes: if the query results indicate that the first monitoring identifier and the second monitoring identifier do not exist in the preset database, then it is determined that the message channel between the first microservice client and the second microservice client has not been monitored; if the query results indicate that the first monitoring identifier does not exist in the preset database but the second monitoring identifier exists, then it is determined that the first microservice message channel between the first microservice client and the second microservice client has not been monitored, and the second microservice message channel has been monitored; if the query results indicate that the first monitoring identifier exists in the preset database but the second monitoring identifier does not exist, then it is determined that the first microservice message channel between the first microservice client and the second microservice client has been monitored, and the second microservice message channel has not been monitored.
[0080] The above method further includes: if the first microservice message channel between the first microservice client and the second microservice client is not being listened to, and the second microservice message channel is being listened to, then a first microservice message channel between the first microservice client and the second microservice client in the microservice architecture is constructed based on a preset remote invocation protocol; if the first microservice message channel between the first microservice client and the second microservice client is being listened to, and the second microservice message channel is not being listened to, then a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture is constructed based on a preset remote invocation protocol.
[0081] The aforementioned first and second microservice message channels are used to indicate message queues. The aforementioned monitoring of the first and second microservice message channels, whereby when the first microservice message channel detects a message, sends the detected message to the second microservice client, includes: blocking message retrieval from the first microservice message channel using a preset first blocking monitoring instruction, and blocking message retrieval from the second microservice message channel using a preset second blocking monitoring instruction. The first and second blocking monitoring instructions include a monitoring timeout period. When a message is retrieved from the first microservice message channel within the monitoring timeout period, the retrieved message is sent to the second microservice client. Similarly, when the second microservice message channel detects a message, sending the detected message to the first microservice client includes: when a message is retrieved from the second microservice message channel within the monitoring timeout period, the retrieved message is sent to the first microservice client.
[0082] The above method also includes: if no message is retrieved from the first microservice message channel within the listening timeout period, the listening lock of the first microservice message channel is released; if no message is retrieved from the second microservice message channel within the listening timeout period, the listening lock of the second microservice message channel is released.
[0083] If no message is retrieved from the first microservice message channel within the listening timeout period, the listening lock of the first microservice message channel is released. This includes: if no message is retrieved from the first microservice message channel within the listening timeout period, the first listening identifier of the first microservice client in the preset database is deleted. The first listening identifier is used to indicate whether the second microservice message channel is being listened to. If no message is retrieved from the second microservice message channel within the listening timeout period, the listening lock of the second microservice message channel is released. This includes: if no message is retrieved from the second microservice message channel within the listening timeout period, the second listening identifier of the second microservice client in the preset database is deleted. The second listening identifier is used to indicate whether the first microservice message channel is being listened to.
[0084] This embodiment also provides a computer-readable storage medium storing computer-executable instructions. When these computer-executable instructions are invoked and executed by a processor, they cause the processor to implement the aforementioned client communication method, for example:
[0085] In a microservice architecture, any server responds to a communication command from a first microservice client to a second microservice client. Based on a preset remote procedure call protocol, a first microservice message channel and a second microservice message channel are established between the first and second microservice clients. The first microservice message channel is used to receive messages sent from the first microservice client to the second microservice client, and the second microservice message channel is used to receive messages sent from the second microservice client to the first microservice client. The first and second microservice message channels are monitored. When the first microservice message channel detects a message, it sends the detected message to the second microservice client; when the second microservice message channel detects a message, it sends the detected message to the first microservice client.
[0086] In this approach, any server in the microservice architecture can respond to communication commands from any microservice client to another microservice client. Based on a predefined remote procedure call protocol, a first microservice message channel and a second microservice message channel are constructed in the microservice architecture. These channels are used for one microservice client to send messages to another microservice client and to receive messages from another microservice client. By having any server in the microservice architecture listen to the first and second microservice message channels, message synchronization between the two microservice clients can be achieved. This reduces the difficulty of communication between microservice clients by requiring only the definition of a protocol and the construction of message channels.
[0087] In the aforementioned microservice architecture, any server responding to a communication command from the first microservice client to the second microservice client constructs a first microservice message channel and a second microservice message channel between the first and second microservice clients based on a preset remote invocation protocol. This includes: responding to a communication command from the first microservice client to the second microservice client, determining a first identifier of the first microservice client, a second identifier of the second microservice client, and a microservice identifier. The microservice identifier indicates the communicable microservices between the first and second microservice clients. The server then determines whether the message channel between the first and second microservice clients has been monitored using the first identifier, the second identifier, and the microservice identifier. If the message channel between the first and second microservice clients has not been monitored, the server constructs the first and second microservice message channels between the first and second microservice clients based on the preset remote invocation protocol.
[0088] The above method of determining whether the message channel between the first microservice client and the second microservice client has been monitored using the first identifier, the second identifier, and the microservice identifier includes: generating a first monitoring identifier for the first microservice client and a second monitoring identifier for the second microservice client based on the first identifier, the second identifier, and the microservice identifier; querying the first monitoring identifier and the second monitoring identifier in a preset database to obtain the query results; and determining whether the message channel between the first microservice client and the second microservice client has been monitored based on the query results.
[0089] The above query results are used to indicate whether the first listening identifier and / or the second listening identifier exist in the preset database;
[0090] The determination of whether the message channel between the first microservice client and the second microservice client has been monitored based on the query results includes: if the query results indicate that the first monitoring identifier and the second monitoring identifier do not exist in the preset database, then it is determined that the message channel between the first microservice client and the second microservice client has not been monitored; if the query results indicate that the first monitoring identifier does not exist in the preset database but the second monitoring identifier exists, then it is determined that the first microservice message channel between the first microservice client and the second microservice client has not been monitored, and the second microservice message channel has been monitored; if the query results indicate that the first monitoring identifier exists in the preset database but the second monitoring identifier does not exist, then it is determined that the first microservice message channel between the first microservice client and the second microservice client has been monitored, and the second microservice message channel has not been monitored.
[0091] The above method further includes: if the first microservice message channel between the first microservice client and the second microservice client is not being listened to, and the second microservice message channel is being listened to, then a first microservice message channel between the first microservice client and the second microservice client in the microservice architecture is constructed based on a preset remote invocation protocol; if the first microservice message channel between the first microservice client and the second microservice client is being listened to, and the second microservice message channel is not being listened to, then a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture is constructed based on a preset remote invocation protocol.
[0092] The aforementioned first and second microservice message channels are used to indicate message queues. The aforementioned monitoring of the first and second microservice message channels, whereby when the first microservice message channel detects a message, sends the detected message to the second microservice client, includes: blocking message retrieval from the first microservice message channel using a preset first blocking monitoring instruction, and blocking message retrieval from the second microservice message channel using a preset second blocking monitoring instruction. The first and second blocking monitoring instructions include a monitoring timeout period. When a message is retrieved from the first microservice message channel within the monitoring timeout period, the retrieved message is sent to the second microservice client. Similarly, when the second microservice message channel detects a message, sending the detected message to the first microservice client includes: when a message is retrieved from the second microservice message channel within the monitoring timeout period, the retrieved message is sent to the first microservice client.
[0093] The above method also includes: if no message is retrieved from the first microservice message channel within the listening timeout period, the listening lock of the first microservice message channel is released; if no message is retrieved from the second microservice message channel within the listening timeout period, the listening lock of the second microservice message channel is released.
[0094] If no message is retrieved from the first microservice message channel within the listening timeout period, the listening lock of the first microservice message channel is released. This includes: if no message is retrieved from the first microservice message channel within the listening timeout period, the first listening identifier of the first microservice client in the preset database is deleted. The first listening identifier is used to indicate whether the second microservice message channel is being listened to. If no message is retrieved from the second microservice message channel within the listening timeout period, the listening lock of the second microservice message channel is released. This includes: if no message is retrieved from the second microservice message channel within the listening timeout period, the second listening identifier of the second microservice client in the preset database is deleted. The second listening identifier is used to indicate whether the first microservice message channel is being listened to.
[0095] The computer program product of the client communication method, device, electronic device and storage medium provided in the embodiments of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation, please refer to the method embodiments, which will not be repeated here.
[0096] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and apparatus described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0097] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.
[0098] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0099] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0100] Finally, it should be noted that the above embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A communication method of a client, applied to a microservice architecture, the microservice architecture comprising at least one server and at least two microservice clients, characterized in that, The method includes: In the microservice architecture, any server responds to the communication command from the first microservice client to the second microservice client, and constructs a first microservice message channel and a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture based on a preset remote call protocol. The first microservice message channel is used to receive messages sent from the first microservice client to the second microservice client, and the second microservice message channel is used to receive messages sent from the second microservice client to the first microservice client. The first microservice message channel and the second microservice message channel are monitored. When the first microservice message channel detects a message, the detected message is sent to the second microservice client. When the second microservice message channel detects a message, it sends the detected message to the first microservice client. In the microservice architecture, any server responds to a communication command from a first microservice client to a second microservice client, and constructs a first microservice message channel and a second microservice message channel between the first microservice client and the second microservice client based on a preset remote procedure call protocol, including: In a microservice architecture, any server responds to a communication instruction from a first microservice client to a second microservice client, and determines a first identifier of the first microservice client, a second identifier of the second microservice client, and a microservice identifier. The microservice identifier is used to indicate the communicable microservices between the first microservice client and the second microservice client. The first identifier, the second identifier, and the microservice identifier are used to determine whether the message channel between the first microservice client and the second microservice client has been monitored. If the message channel between the first microservice client and the second microservice client is not being monitored, then a first microservice message channel and a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture are constructed based on a preset remote call protocol.
2. The method according to claim 1, characterized in that, The step of determining whether the message channel between the first microservice client and the second microservice client has been monitored using the first identifier, the second identifier, and the microservice identifier includes: Based on the first identifier, the second identifier, and the microservice identifier, generate a first listening identifier for the first microservice client and a second listening identifier for the second microservice client; The first listening identifier and the second listening identifier are queried in the preset database to obtain the query results; Based on the query results, determine whether the message channel between the first microservice client and the second microservice client has been monitored.
3. The method according to claim 2, characterized in that, The query result is used to indicate whether the first listening identifier and / or the second listening identifier exist in the preset database; The step of determining whether the message channel between the first microservice client and the second microservice client has been monitored based on the query result includes: If the query result indicates that the first listening identifier and the second listening identifier do not exist in the preset database, then it is determined that the message channel between the first microservice client and the second microservice client is not being monitored. If the query result indicates that the first listening identifier does not exist in the preset database, but the second listening identifier does exist, then it is determined that the first microservice message channel between the first microservice client and the second microservice client is not being listened to, and the second microservice message channel has been listened to. If the query result indicates that the first listening identifier exists in the preset database and the second listening identifier does not exist, then it is determined that the first microservice message channel between the first microservice client and the second microservice client has been listened to, and the second microservice message channel has not been listened to.
4. The method according to claim 1, characterized in that, The method further includes: If the first microservice message channel between the first microservice client and the second microservice client is not being listened to, and the second microservice message channel has been listened to, then the first microservice message channel between the first microservice client and the second microservice client in the microservice architecture is constructed based on a preset remote call protocol. If the first microservice message channel between the first microservice client and the second microservice client has been monitored, and the second microservice message channel has not been monitored, then a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture is constructed based on a preset remote call protocol.
5. The method according to claim 1, characterized in that, The first microservice message channel and the second microservice message channel are used to indicate message queues. The step of listening to the first microservice message channel and the second microservice message channel, and when the first microservice message channel detects a message, sending the detected message to the second microservice client, includes: The first microservice message channel is blocked and messages are pulled through by a preset first blocking listening instruction, and the second microservice message channel is blocked and messages are pulled through by a preset second blocking listening instruction. The first blocking listening instruction and the second blocking listening instruction include a listening timeout duration. When a message is retrieved from the first microservice message channel within the listening timeout period, the message retrieved from the first microservice message channel will be sent to the second microservice client. When the second microservice message channel detects a message, sending the detected message to the first microservice client includes: When a message is retrieved from the second microservice message channel within the listening timeout period, the message retrieved from the second microservice message channel will be sent to the first microservice client.
6. The method according to claim 5, characterized in that, The method further includes: If no message is retrieved from the first microservice message channel within the listening timeout period, the listening lock of the first microservice message channel is released. If no message is retrieved from the second microservice message channel within the specified listening timeout period, the listening lock of the second microservice message channel is released.
7. The method according to claim 6, characterized in that, The step of releasing the listening lock of the first microservice message channel if no message is retrieved from the first microservice message channel within the listening timeout period includes: If no message is retrieved from the first microservice message channel within the listening timeout period, the first listening identifier of the first microservice client in the preset database is deleted. The first listening identifier is used to indicate whether the second microservice message channel is being listened to. The step of releasing the listening lock of the second microservice message channel if no message is retrieved from the second microservice message channel within the listening timeout period includes: If no message is retrieved from the second microservice message channel within the specified listening timeout period, the second listening identifier of the second microservice client in the preset database is deleted. The second listening identifier is used to indicate whether the first microservice message channel is being listened to.
8. A client communication device applied to a microservice architecture, the microservice architecture comprising at least one server and at least two microservice clients, characterized in that, The device includes: The response module is used for any server in the microservice architecture to respond to the communication instructions from the first microservice client to the second microservice client. Based on a preset remote invocation protocol, it constructs a first microservice message channel and a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture. The first microservice message channel is used to receive messages sent from the first microservice client to the second microservice client, and the second microservice message channel is used to receive messages sent from the second microservice client to the first microservice client. The listening module is used to listen to the first microservice message channel and the second microservice message channel. When the first microservice message channel detects a message, it sends the detected message to the second microservice client. The sending module is used to send the listened-up message to the first microservice client when the second microservice message channel listens for a message; The response module includes: The determination submodule is used in a microservice architecture to determine, in response to a communication instruction from a first microservice client to a second microservice client, a first identifier of the first microservice client, a second identifier of the second microservice client, and a microservice identifier, wherein the microservice identifier is used to indicate the communicable microservices between the first microservice client and the second microservice client. The judgment submodule is used to determine whether the message channel between the first microservice client and the second microservice client has been monitored by the first identifier, the second identifier and the microservice identifier; A submodule is constructed to construct a first microservice message channel and a second microservice message channel between the first microservice client and the second microservice client in the microservice architecture based on a preset remote call protocol if the message channel between the first microservice client and the second microservice client is not being listened to.
9. An electronic device, characterized in that, It includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the client communication method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the communication method of the client as described in any one of claims 1-7.
Citation Information
Patent Citations
Micro-service system based on message event communication
CN112596933A
Method for establishing data transmission channel, terminal system and storage medium
CN114077502A