Message sending method and device, electronic equipment and storage medium

By encapsulating the message to be sent as a target message of ETCD type and using the ETCD cluster for message forwarding, the problem of increased system complexity and increased time-consuming and linear increase after the introduction of Rabbitmq is solved, and better decoupling and message forwarding efficiency are achieved.

CN119996364APending Publication Date: 2025-05-13BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311501314.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-11-10
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

The introduction of Rabbitmq as message middleware in the prior art leads to an increase in system complexity. In large-scale cloud network scenarios, the Agent-by-Agent transmission of Rabbitmq will lead to a linear increase in time-consuming and prone to blocking API problems.

Method used

When the forwarding type of the message to be sent is ETCD type, the message to be sent is encapsulated as the target message of ETCD type, and the ETCD cluster is selected as the target message middleware forwarding to the target command issuance service.

Benefits of technology

This method reduces the external dependencies introduced by the system and achieves better decoupling. Even if there is an error in the ETCD cluster, it will not affect the operation of the overall service. At the same time, through ETCD cluster, message forwarding can be simultaneously sent to multiple agents, improving API response time, and alleviating the pressure of message forwarding in large clusters.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119996364A_ABST
    Figure CN119996364A_ABST
Patent Text Reader

Abstract

The invention provides a message sending method and device, electronic equipment and a storage medium, and the method comprises the steps: obtaining a to-be-sent message which needs to be sent by a target command issuing service; under the condition that the forwarding type of the to-be-sent message is an ETCD type, the to-be-sent message is packaged into a target message of the ETCD type, and the forwarding type is used for indicating the type of message middleware for forwarding the to-be-sent message; and selecting the ETCD cluster as a target message middleware to forward the target message to the target command issuing service. According to the method and the device, the problems that the complexity of a system is greatly improved after Rabbitmq is introduced in the prior art, and in a large-scale cloud network scene, Agent-by-Agent sending of Rabbitmq causes time-consuming linear increase and api blockage is easy to occur are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data exchange, and in particular to a message sending method and device, an electronic device and a storage medium. Background Art

[0002] In order to cope with large-scale high-concurrency scenarios, most of the existing message processing solutions use message middleware to process messages, forward and receive messages, such as RabbitMQ.

[0003] In cloud computing, in large-scale cloud network scenarios, messages are sent through the API side, and the Agent (i.e., the service used to send configurations and commands to the bottom layer) receives the message and processes the configuration. The implementation method in the prior art is: call the API through the console, and the API request reaches each plugin of the neutron service (i.e., the plug-in used to receive the API request) for processing (data verification, storage, writing to redis, etc.), and then sends the configuration information to the Agent. Regarding the sending of configuration information, first call the unified encapsulated plugin_driver driver component, and then the plugin_driver driver program checks which Agent service the message belongs to, and finds the corresponding notification (rpc notification component). The notification correctly sends the message to the Rabbitmq queue based on the topic and other information on the Agent side, and routes it to the specified Agent service. However, the use of Rabbitmq as a message middleware has the following technical problems:

[0004] 1. Increased project complexity: The introduction of RabbitMQ will greatly increase the complexity of the system. Previously, services could make synchronous service calls, but after the introduction of RabbitMQ, they will become asynchronous calls, and the data link will become more complicated. As the link becomes more complicated, a series of problems will arise.

[0005] 2. In large-scale cloud network scenarios, RabbitMQ's Agent-by-Agent sending will cause a linear increase in time consumption and easily cause API blocking problems.

[0006] Therefore, the related art has the technical problems as described above. Summary of the invention

[0007] The present application provides a message sending method and device, an electronic device and a storage medium to at least solve at least one technical problem existing in the related art.

[0008] According to one aspect of an embodiment of the present application, a message sending method is provided, including:

[0009] Get the pending message that needs to be sent by the target command delivery service;

[0010] In the case where the forwarding type of the message to be sent is an ETCD type, encapsulating the message to be sent as a target message of the ETCD type, wherein the forwarding type is used to indicate the type of message middleware that forwards the message to be sent;

[0011] Select the ETCD cluster as the target message middleware to forward the target message to the target command delivery service.

[0012] Optionally, as in the aforementioned method, when the forwarding type of the message to be sent is an ETCD type, encapsulating the message to be sent as a target message of the ETCD type includes:

[0013] The message body preprocessing module performs a first encapsulation operation on the message to be sent according to the ETCD type to obtain a first encapsulated message;

[0014] The notification manager processes the first encapsulated message according to the target command delivery service to obtain a first key-value pair;

[0015] The notification manager transmits the first key-value pair to a message notification module;

[0016] The message notification module performs a second encapsulation operation on the first key-value pair according to the target service type of the target command delivery service to obtain the target message.

[0017] Optionally, as in the aforementioned method, the notification manager processes the first encapsulated message according to the target command delivery service to obtain a first key-value pair, including:

[0018] The notification manager generates a first key name according to the target service name of the target command to send the service; the notification manager generates a first key value according to the first encapsulated message;

[0019] The notification manager generates the first key-value pair according to the first key name and the first key value.

[0020] Optionally, as in the aforementioned method, the message body preprocessing module performs a first encapsulation operation on the message to be sent according to the ETCD type to obtain a first encapsulated message, including:

[0021] The message body preprocessing module obtains a second key-value pair indicating the forwarding type from a preset area;

[0022] When the message body preprocessing module determines that the forwarding type is the ETCD type through the second key-value pair, the message body preprocessing module performs a first encapsulation operation on the message to be sent according to the ETCD type to obtain the first encapsulated message.

[0023] Optionally, as in the aforementioned method, the method further comprises:

[0024] The notification manager generates hot switch flag information for indicating that the target message middleware is switched to Rabbitmq when determining that the ETCD cluster is unavailable;

[0025] The second key-value pair in the preset area for indicating the forwarding type is modified according to the hot switch flag information to obtain a third key-value pair for indicating that Rabbitmq is used as the target message middleware.

[0026] Optionally, as in the aforementioned method, the method further comprises:

[0027] Get the middleware switching request;

[0028] In response to the middleware switching request, the second key-value pair in the preset area used to indicate the forwarding type is modified to obtain a fourth key-value pair used to indicate that the message middleware specified in the middleware switching request is the target message middleware, wherein the message middleware specified in the middleware switching request is Rabbitmq or ETCD cluster.

[0029] Optionally, as in the aforementioned method, when the forwarding type of the message to be sent is an ETCD type, encapsulating the message to be sent as a target message of the ETCD type includes:

[0030] Get the fourth key-value pair;

[0031] Determine whether the fourth key-value pair contains the target service name corresponding to the target command delivery service;

[0032] When it is determined that the fourth key-value pair includes the target service name and the forwarding type of the message to be sent is an ETCD type, encapsulating the message to be sent as a target message of the ETCD type;

[0033] In a case where it is determined that the fourth key-value pair does not include the target service name, encapsulating the message to be sent as a target message of the ETCD type is not performed.

[0034] According to another aspect of an embodiment of the present application, a message sending device is also provided, including:

[0035] The acquisition module is used to obtain the message to be sent by the target command delivery service;

[0036] An encapsulation module, used for encapsulating the message to be sent into a target message of the ETCD type when the forwarding type of the message to be sent is the ETCD type, wherein the forwarding type is used to indicate the type of the message middleware that forwards the message to be sent;

[0037] The forwarding module is used to select the ETCD cluster as the target message middleware to forward the target message to the target command issuing service.

[0038] According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein the memory is used to store a computer program; and the processor is used to execute the method steps in any of the above embodiments by running the computer program stored in the memory.

[0039] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the method steps in any of the above embodiments when executed.

[0040] In an embodiment of the present application, when the forwarding type of the message to be sent is the ETCD type, the message to be sent is encapsulated as the first message target message of the ETCD type; the ETCD cluster is selected as the target message middleware to forward the first message target message to the target command issuing service. Thus, a message forwarding method different from Rabbitmq as the message middleware is provided, and the message forwarding through the ETCD cluster in this embodiment can reduce the external dependencies introduced by the system, so that better decoupling can be achieved, and even if the ETCD cluster has an error, it will not affect the operation of the overall service; in addition, the message forwarding using the ETCD cluster can achieve simultaneous sending to multiple agents, thereby improving the API response time; and the introduction of the ETCD cluster for message forwarding can improve the message sending and receiving capabilities to a certain extent, and can effectively alleviate the pressure of message forwarding under the current large cluster; therefore, through the method of this embodiment, the complexity of the system will be greatly improved after the introduction of Rabbitmq in the related technology, and in the large-scale cloud network scenario, the Agent-by-Agent sending of Rabbitmq will cause a linear increase in time consumption, and it is easy to block the API. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0042] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0043] Figure 1 is a schematic diagram of a hardware environment of an optional message sending method according to an embodiment of the present application;

[0044] Figure 2 is a flowchart of an optional message sending method according to an embodiment of the present application;

[0045] Figure 3 is a flowchart of another optional message sending method according to an embodiment of the present application;

[0046] Figure 4 It is a flowchart of an optional message sending method according to an application example of the present application;

[0047] Figure 5 is a flowchart of another optional message sending method according to an application example of the present application;

[0048] Figure 6 is a flowchart of another optional message sending method according to an application example of the present application;

[0049] Figure 7 is a flowchart of another optional message sending method according to an application example of the present application;

[0050] Figure 8 is a structural block diagram of an optional message sending device according to an embodiment of the present application;

[0051] Fig. 9 It is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0052] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0053] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0054] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following interpretation:

[0055] 1. Plugin: A module used to receive API requests.

[0056] 2. Plugin_driver: A module used to encapsulate the message body and process and forward it. (Plugin and plugin driver belong to the server side)

[0057] 3. ETCD cluster: a distributed cluster for shared configuration and service discovery, a consistent KV (key-value) storage system. ETCD cluster is an open source project licensed under Apache. ETCD uses the Raft protocol to maintain the consistency of the states of each node in the cluster. In other words, the ETCD cluster is a distributed system consisting of multiple nodes communicating with each other to form an overall external service. Each node stores complete data, and the Raft protocol is used to ensure that the data maintained by each node is consistent.

[0058] 4. Rabbitmq: Rabbitmq is built on AMQP (Advanced Message Queuing Protocol), which provides reliable message delivery and a message queue that ensures that messages are not lost or processed repeatedly. When Rabbitmq implements message delivery, it can route and filter on demand and can have an unlimited number of receivers.

[0059] 5. Agent: A service that sends configurations and commands to the underlying layer.

[0060] According to one aspect of an embodiment of the present application, a message sending method is provided. Optionally, in this embodiment, the message sending method can be applied to Figure 1 In the hardware environment composed of terminal 1402 and server 1404 shown in FIG. Figure 1 As shown, server 1404 is connected to terminal 1402 via a network, and can be used to provide services (such as game services, application services, etc.) for the terminal or a client installed on the terminal. A database can be set up on the server or independently of the server to provide data storage services for server 1404.

[0061] The above network may include but is not limited to at least one of the following: wired network, wireless network. The above wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the above wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal may not be limited to a PC, a mobile phone, a tablet computer, etc.

[0062] The message sending method of the embodiment of the present application can be executed by a server, a terminal, or a server and a terminal together. The terminal can also execute the message sending method of the embodiment of the present application by a client installed thereon.

[0063] Taking the message sending method in this embodiment executed by the server as an example, Figure 2 A message sending method provided in an embodiment of the present application includes the following steps:

[0064] Step S101, obtaining a message to be sent that needs to be sent by a target command issuing service.

[0065] The message sending method in this embodiment can be applied to the scenario of sending the configuration information / configuration file obtained through the API request to the Agent (i.e., the command sending service, the Agent is used to send configurations and commands to the bottom layer to implement the bottom layer configuration according to the configuration information / configuration file).

[0066] Specifically, the API can be used to obtain the pending message that needs to be sent to the target command delivery service.

[0067] The target command delivery service may be an Agent corresponding to the message to be sent and used to deliver configurations and commands to the specified bottom layer.

[0068] Step S102: When the forwarding type of the message to be sent is an ETCD type, encapsulate the message to be sent into a target message of an ETCD type, wherein the forwarding type is used to indicate the type of the message middleware that forwards the message to be sent.

[0069] Specifically, before or during the sending of the message to be sent, it can be determined which forwarding type is used to forward the message to be sent, that is, whether it is the ETCD type forwarded by the ETCD cluster or the Rabbitmq type forwarded by Rabbitmq.

[0070] When it is determined that the forwarding type of the message to be sent is the ETCD type, the message to be sent is encapsulated into a target message of the ETCD type that satisfies the ETCD cluster for forwarding.

[0071] Generally, KV data is stored in the etcd cluster, so the target message is also KV data.

[0072] Step S103, select the ETCD cluster as the target message middleware to forward the target message to the target command delivery service.

[0073] Specifically, after determining that the forwarding type is the ETCD type and encapsulating the message to be sent to obtain a target message of the ETCD type, the ETCD cluster can be used as the target message middleware, and the target message can be forwarded to the target command delivery service.

[0074] The method of this embodiment, by adopting the case that the forwarding type of the message to be sent is the ETCD type, encapsulates the message to be sent as the first message target message of the ETCD type; selects the ETCD cluster as the target message middleware to forward the first message target message to the target command issuing service. Thus, a message forwarding method different from Rabbitmq as the message middleware is provided, and the message forwarding through the ETCD cluster in this embodiment can reduce the external dependencies introduced by the system, so that better decoupling can be achieved, and even if the ETCD cluster has an error, it will not affect the operation of the overall service; in addition, the message forwarding using the ETCD cluster can achieve simultaneous sending to multiple agents, thereby improving the API response time; and the introduction of the ETCD cluster for message forwarding can improve the message sending and receiving capabilities to a certain extent, and can effectively alleviate the pressure of message forwarding under the current large cluster; therefore, through the method of this embodiment, the complexity of the system will be greatly improved after the introduction of Rabbitmq in the related technology, and in the large-scale cloud network scenario, the Agent-by-Agent sending of Rabbitmq will cause a linear increase in time consumption, and it is easy to block the API.

[0075] like Figure 3 As shown, as an optional embodiment, as in the aforementioned method, in the case where the forwarding type of the message to be sent is the ETCD type, step S102 encapsulates the message to be sent as a target message of the ETCD type, including the following steps:

[0076] Step S201: The message body preprocessing module performs a first encapsulation operation on the message to be sent according to the ETCD type to obtain a first encapsulated message.

[0077] Specifically, when the plugin processes the message to be sent that needs to be sent to the target command service synchronization, the plugin_driver can be called as the message body preprocessing module to perform the first encapsulation operation on the message to be sent according to the ETCD type before entering the notification module, that is, perform the first encapsulation to obtain the first encapsulated message that meets the requirements of the ETCD cluster.

[0078] Step S202: The notification manager processes the first encapsulated message according to the target command delivery service to obtain a first key-value pair.

[0079] Specifically, since the data in the ETCD cluster is KV data, the first encapsulated message needs to be further processed to obtain the corresponding first key-value pair.

[0080] As an optional embodiment, as in the aforementioned method, the notification manager processes the first encapsulated message according to the target command delivery service to obtain the first key-value pair, including the following steps:

[0081] The notification manager generates a first key name according to the target service name of the target command delivery service; the notification manager generates a first key value according to the first encapsulated message; the notification manager generates a first key-value pair according to the first key name and the first key value.

[0082] Specifically, the notification manager (ie, notification manager) may obtain the target service name of the target command issuing service to which the information to be sent is to be sent, and then generate a corresponding first key name based on the target service name.

[0083] For example, when the target command delivery service is a service named "L3_Agent", the notificationmanager generates a corresponding key (ie, the first key name) according to the "L3_Agent".

[0084] Furthermore, the notification manager may generate the first encapsulated message as a value corresponding to the key (ie, a first key value), and then obtain a first key-value pair based on the determined first key name and the first key value.

[0085] Step S203: The notification manager transmits the first key-value pair to the message notification module.

[0086] Specifically, after generating the first key-value pair, the notification manager may transmit the first key-value pair to the message notification module, for example, transmit the first key-value pair to the notification module.

[0087] Step S204: the message notification module performs a second encapsulation operation on the first key-value pair according to the target service type of the target command-delivered service to obtain a target message.

[0088] Specifically, after the message notification module obtains the first key-value pair, since the first key-value pair ultimately needs to be forwarded to the target command delivery service through the ETCD cluster, the message notification module can perform a second encapsulation operation on the first key-value pair according to the target service type of the target command delivery service (different Agents provide different services, and the corresponding commands are also different, which are used to execute different software operation commands) to obtain the target message. Furthermore, the second encapsulation operation can only encapsulate the first key value in the first key-value pair.

[0089] As an optional embodiment, as in the aforementioned method, the message body preprocessing module in step S201 performs a first encapsulation operation on the message to be sent according to the ETCD type to obtain a first encapsulated message, including the following steps:

[0090] The message body preprocessing module obtains a second key-value pair for indicating the forwarding type from a preset area; when the message body preprocessing module determines that the forwarding type is an ETCD type through the second key-value pair, the message body preprocessing module performs a first encapsulation operation on the message to be sent according to the ETCD type to obtain a first encapsulated message.

[0091] Specifically, in order to determine the currently used message middleware, in this embodiment, the relevant information of the currently used message middleware may be stored in a preset area, for example, cached in Redis.

[0092] The message body preprocessing module can obtain a second key-value pair for indicating a forwarding type from a preset area.

[0093] For example, notification manage can read the second key-value pair in the Redis cache, and then, based on the second key-value pair, if it is determined that the current corresponding forwarding type is ETCD, it performs a first encapsulation operation on the message to be sent according to the ETCD type to obtain a first encapsulated message, and continues to execute subsequent steps.

[0094] As an optional embodiment, as the aforementioned method, the method further includes the following steps:

[0095] Step S301: When the notification manager determines that the ETCD cluster is unavailable, it generates hot switch flag information for indicating that the target message middleware is switched to Rabbitmq.

[0096] Specifically, when Notification Manage detects that the ETCD cluster is unavailable, it can generate hot switch flag information for indicating that the target message middleware should be switched from the currently used ETCD cluster to Rabbitmq.

[0097] Step S302: modify the second key-value pair in the preset area for indicating the forwarding type according to the hot switch flag information to obtain a third key-value pair for indicating that Rabbitmq is used as the target message middleware.

[0098] After the hot switch flag information is determined, the second key-value pair in the preset area for indicating the forwarding type may be modified so that the third key-value pair obtained after the modification indicates that Rabbitmq is used as the target message middleware.

[0099] The key name in the second key-value pair can be a flag for representing hot switching, and the key value in the second key-value pair can be a message middleware used after the hot switching. For example, when the second key name (i.e., the key of the second key-value pair) is enable_message_driver_auto_switch. When the key is True, the ETCD cluster is used to send and process messages, and the key is False, which means Rabbitmq is used to send messages. When the program senses that the ETCD cluster is unavailable, it automatically switches to Rabbitmq. After switching to Rabbitmq, Rabbitmq messages are mainly sent and received through the topic of the target command service.

[0100] As an optional embodiment, as the aforementioned method, the method further includes the following steps:

[0101] When the target message middleware currently in use is Rabbitmq, and the notification manager determines that Rabbitmq is unavailable, a first hot switch flag information is generated to indicate that the target message middleware is switched to the ETCD cluster. The key-value pair in the preset area for indicating the forwarding type is modified according to the first hot switch flag information to obtain a key-value pair for indicating that the ETCD cluster is used as the target message middleware.

[0102] That is to say, when the currently used Rabbitmq is unavailable, switch to the ETCD cluster as the target message middleware through the above method.

[0103] Through the method of this embodiment, it is possible to support the simultaneous operation of the ETCD cluster and Rabbitmq. When an exception occurs in a component (i.e., one of the ETCD cluster and Rabbitmq), the plugin driver can be used to send an API request to replace the sending and consumption of messages to another component to continue running. For example, when an exception occurs in the sending and consumption of messages by Rabbitmq, it can be switched to the ETCD cluster in time to continue the message sending and consumption functions, thereby ensuring the normal operation of the service.

[0104] As an optional embodiment, as the aforementioned method, the method further includes the following steps:

[0105] Step S401: obtaining a middleware switching request.

[0106] Specifically, whether the target message middleware uses Rabbitmq or ETCD cluster can be controlled by manual switching.

[0107] The user can send a middleware switching request to the device implementing the method of this embodiment through a designated API for implementing message middleware switching on the server side (ie, the service side).

[0108] Step S402, in response to the middleware switching request, modify the second key-value pair in the preset area for indicating the forwarding type, and obtain a fourth key-value pair for indicating that the message middleware specified in the middleware switching request is used as the target message middleware, wherein the message middleware specified in the middleware switching request is Rabbitmq or ETCD cluster.

[0109] Specifically, after obtaining the middleware switching request, the second key-value pair in the preset area (i.e., the redis cache) used to indicate the forwarding type can be modified to obtain a fourth key-value pair located in the preset area, indicating that the message middleware specified in the middleware switching request is used as the target message middleware.

[0110] Furthermore, when the services on the server and Agent sides are running, the server and Agent sides simultaneously obtain the value of enable_etcd_message_driver, so that the server side confirms sending messages in a manner corresponding to the message middleware indicated by the fourth key-value pair, and so that the Agent side confirms receiving messages in a manner corresponding to the message middleware indicated by the fourth key-value pair.

[0111] As an optional embodiment, as in the aforementioned method, when the forwarding type of the message to be sent is the ETCD type, encapsulating the message to be sent as a target message of the ETCD type includes the following steps:

[0112] Get the fourth key-value pair; determine whether the fourth key-value pair contains the target service name corresponding to the target command issuance service; when it is determined that the fourth key-value pair contains the target service name and the forwarding type of the message to be sent is the ETCD type, encapsulate the message to be sent as a target message of the ETCD type; when it is determined that the fourth key-value pair does not contain the target service name, do not encapsulate the message to be sent as a target message of the ETCD type.

[0113] Specifically, the fourth key-value pair may be a key-value pair pre-stored in the Redis cache, and the fourth key-value pair may be used to indicate whether the command issuing service can use the ETCD cluster to forward messages, and the service name corresponding to the command issuing service that can use the ETCD cluster to forward messages is recorded in the fourth key-value pair.

[0114] After obtaining the fourth key-value pair, it can be determined whether the target command delivery service can receive messages with a forwarding type of ETCD type by determining whether the fourth key-value pair contains the target service name.

[0115] When it is determined that the fourth key-value pair contains the target service name and the forwarding type of the message to be sent is the ETCD type, it represents that the target command issuing service can accept ETCD type messages and the forwarding type of the message to be sent is the ETCD type; the message to be sent is encapsulated as a target message of the ETCD type.

[0116] On the contrary, when it is determined that the fourth key-value pair does not include the target service name, encapsulating the message to be sent as a target message of the ETCD type is not performed.

[0117] For example, the key of the fourth key-value pair can be enable_etcd_message_driver_topics; and the key of the fourth key-value pair is in the form of a list. If the topic of an Agent is in this list, it means that the Agent and the server including the Agent can use etcd to send messages. Among them, there is only one server, which can send requests to each Agent. There are many types of Agents on the Agent side, such as L3 Agent and nat Agent. Only when enable_etcd_message_driver is enabled to True and enable_etcd_message_driver_topics contains a topic of an Agent, the server side (that is, including Plugin and Plugin_driver) will send etcd type messages to the Agent side.

[0118] As described below, an application example of applying any of the above embodiments is provided:

[0119] like Figure 4 The figure shows the message sending model after the introduction of ETCD cluster as the message middleware. When the plugin needs to synchronize the configuration message to the Agent end after processing, the first step is the same as forwarding the message through Rabbitmq as the message middleware. The plugin_driver is called to call the corresponding processing logic according to the Agent type. Before the introduction of ETCD cluster, the message goes directly to the notification module of each Agent, and then encapsulates the good news and sends it to Rabbitmq.

[0120] After introducing the ETCD cluster, before entering the notification module, it is necessary to perform differentiated processing based on the characteristics of each Agent.

[0121] Before sending a message, the plugin driver determines whether the message type is of ETCD type or Rabbitmq type on the server side (i.e., including Plugin and Plugin_driver (i.e., message body preprocessing module)), and then encapsulates the message according to its type (i.e., when it is of ETCD type, the first encapsulation operation is performed on the message to be sent to obtain the first encapsulated message), and finally chooses whether the final message is sent by the ETCD cluster or Rabbitmq; for example, for L3_Agent, Rabbitmq messages are mainly sent and received through the topic of L3_Agent, and the ETCD cluster also listens to the topic of L3_Agent as the key through the watch mechanism. These differentiated processing are mainly processed in the notification manager (i.e., notification manager). After the processing is completed, it is sent to the notification module (i.e., message notification module) to complete the encapsulation and processing of the message (i.e., for the second encapsulation operation on the first key-value pair). Finally, the message driverwrapper determines which driver (i.e., ETCD cluster or Rabbitmq) to forward according to the forwarding type.

[0122] 1. As Figure 5As shown, notification manage also preliminarily implements the hot switch function, switching to Rabbitmq when it is detected that the ETCD cluster is unavailable. In this embodiment, hot switching is achieved through the redis cache mechanism. The flag representing the hot switch is cached in redis as the key (that is, the key name in the second key-value pair), and the value is True (indicating the use of the ETCD cluster) or False (indicating the use of Rabbitmq). For example, the key is enable_message_driver_auto_switch. When the key is True, the ETCD cluster is used to send and process messages, and the key is False, which means that Rabbitmq is used to send messages. When the program senses that the ETCD cluster is unavailable, the second key-value pair can be modified to obtain a third key-value pair for indicating that the Rabbitmq is used as the target message middleware, thereby achieving automatic switching to Rabbitmq. In addition, it can be based on a similar method. It is used to support switching from Rabbitmq to the ETCD cluster.

[0123] 2. If Figure 6 As shown in the figure, the message middleware using Etcd cluster and Rabbitmq can also use manual api switching. By manually sending an api request (i.e., a middleware switching request) to change the value of enable_etcd_message_driver in the cache (e.g., Redis cache), the server and Agent (i.e., one end including multiple different Agents) simultaneously obtain the value of enable_etcd_message_driver. If it is True, the Etcd cluster is used to send messages, and if it is False, Rabbitmq is used to send messages. (Note that at this time, it is necessary to ensure that both the server and Agent services are running).

[0124] 3. Such as Figure 7As shown, in order to ensure the consistency of messages between the server and different Agents at startup, enable_etcd_message_driver_topics is also added as a key (i.e., the key name in the fourth key-value pair), and the key is in list form. If the topic of a target Agent (i.e., the target service name) is in this list, it means that the Agent and the server can use the ETCD cluster to send messages (there is only one server, which can send requests to each Agent, and there are multiple Agents, such as L3_Agent and nat_Agent). Only when enable_etcd_message_driver is enabled and True and enable_etcd_message_driver_topics contains the topic of the target Agent, the server will send ETCD type messages to the Agent.

[0125] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0126] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM (Read-Only Memory) / RAM (Random Access Memory), a disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0127] According to another aspect of an embodiment of the present application, a message sending device for implementing the above-mentioned message sending method is also provided. Figure 8 is a structural block diagram of an optional message sending device according to an embodiment of the present application, such as Figure 8 As shown, the device may include:

[0128] Acquisition module 1, used to acquire the to-be-sent message that needs to be sent by the target command delivery service;

[0129] Encapsulation module 2, used for encapsulating the message to be sent into a target message of ETCD type when the forwarding type of the message to be sent is ETCD type, wherein the forwarding type is used to indicate the type of message middleware that forwards the message to be sent;

[0130] Forwarding module 3 is used to select the ETCD cluster as the target message middleware to forward the target message to the target command delivery service.

[0131] It should be noted that the acquisition module 1 in this embodiment can be used to execute the above step S101, the encapsulation module 2 in this embodiment can be used to execute the above step S102, and the forwarding module 3 in this embodiment can be used to execute the above step S103.

[0132] The device in this embodiment, in addition to the above modules, may also include a module for executing any method in any of the above-mentioned message sending method embodiments.

[0133] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware, wherein the hardware environment includes a network environment.

[0134] According to another aspect of an embodiment of the present application, an electronic device for implementing the above-mentioned message sending method is also provided. The electronic device may be a server, a terminal, or a combination thereof.

[0135] According to another embodiment of the present application, there is also provided an electronic device, including: Fig. 9 As shown, the electronic device may include: a processor 1501 , a communication interface 1502 , a memory 1503 and a communication bus 1504 , wherein the processor 1501 , the communication interface 1502 , and the memory 1503 communicate with each other via the communication bus 1504 .

[0136] Memory 1503, used for storing computer programs;

[0137] The processor 1501 is used to implement the following steps when executing the program stored in the memory 1503:

[0138] Step S101, obtaining a message to be sent that needs to be sent by a target command issuing service.

[0139] Step S102: When the forwarding type of the message to be sent is an ETCD type, encapsulate the message to be sent into a target message of an ETCD type, wherein the forwarding type is used to indicate the type of the message middleware that forwards the message to be sent.

[0140] Step S103, select the ETCD cluster as the target message middleware to forward the target message to the target command delivery service.

[0141] Optionally, in this embodiment, the above-mentioned communication bus can be a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface is used for communication between the above-mentioned electronic device and other devices.

[0142] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0143] As an example, the memory 1503 may include but is not limited to the acquisition module 1, encapsulation module 2 and forwarding module 3 in the message sending device. In addition, it may also include but is not limited to other module units in the message sending device, which will not be repeated in this example.

[0144] The above-mentioned processor can be a general-purpose processor, which can include but not be limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0145] An embodiment of the present application further provides a computer-readable storage medium, the storage medium including a stored program, wherein the method steps of the above method embodiment are executed when the program is run.

[0146] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a ROM, a RAM, a mobile hard disk, a magnetic disk, or an optical disk.

[0147] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0148] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.

[0149] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0150] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0151] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution provided in this embodiment.

[0152] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0153] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A message sending method, characterized in that: include: Get the pending message that needs to be sent by the target command delivery service; In the case where the forwarding type of the message to be sent is an ETCD type, encapsulating the message to be sent as a target message of the ETCD type, wherein the forwarding type is used to indicate the type of message middleware that forwards the message to be sent; Select the ETCD cluster as the target message middleware to forward the target message to the target command delivery service.

2. The method according to claim 1, characterized in that When the forwarding type of the message to be sent is an ETCD type, encapsulating the message to be sent as a target message of the ETCD type includes: The message body preprocessing module performs a first encapsulation operation on the message to be sent according to the ETCD type to obtain a first encapsulated message; The notification manager processes the first encapsulated message according to the target command delivery service to obtain a first key-value pair; The notification manager transmits the first key-value pair to a message notification module; The message notification module performs a second encapsulation operation on the first key-value pair according to the target service type of the target command delivery service to obtain the target message.

3. The method according to claim 2, characterized in that The notification manager processes the first encapsulated message according to the target command delivery service to obtain a first key-value pair, including: The notification manager generates a first key name according to the target service name of the target command to send the service; the notification manager generates a first key value according to the first encapsulated message; The notification manager generates the first key-value pair according to the first key name and the first key value.

4. The method according to claim 3, characterized in that The message body preprocessing module performs a first encapsulation operation on the message to be sent according to the ETCD type to obtain a first encapsulated message, including: The message body preprocessing module obtains a second key-value pair indicating the forwarding type from a preset area; When the message body preprocessing module determines that the forwarding type is the ETCD type through the second key-value pair, the message body preprocessing module performs a first encapsulation operation on the message to be sent according to the ETCD type to obtain the first encapsulated message.

5. The method according to claim 1, characterized in that The method further comprises: The notification manager generates hot switch flag information for indicating that the target message middleware is switched to Rabbitmq when determining that the ETCD cluster is unavailable; The second key-value pair in the preset area for indicating the forwarding type is modified according to the hot switch flag information to obtain a third key-value pair for indicating that Rabbitmq is used as the target message middleware.

6. The method according to claim 1, characterized in that The method further comprises: Get the middleware switching request; In response to the middleware switching request, the second key-value pair in the preset area used to indicate the forwarding type is modified to obtain a fourth key-value pair used to indicate that the message middleware specified in the middleware switching request is the target message middleware, wherein the message middleware specified in the middleware switching request is Rabbitmq or ETCD cluster.

7. The method according to any one of claims 1 to 6, characterized in that When the forwarding type of the message to be sent is an ETCD type, encapsulating the message to be sent as a target message of the ETCD type includes: Get the fourth key-value pair; Determine whether the fourth key-value pair contains the target service name corresponding to the target command delivery service; When it is determined that the fourth key-value pair includes the target service name and the forwarding type of the message to be sent is an ETCD type, encapsulating the message to be sent as a target message of the ETCD type; In a case where it is determined that the fourth key-value pair does not include the target service name, encapsulating the message to be sent as a target message of the ETCD type is not performed.

8. A message sending device, characterized in that: include: The acquisition module is used to obtain the message to be sent by the target command delivery service; An encapsulation module, used for encapsulating the message to be sent into a target message of the ETCD type when the forwarding type of the message to be sent is the ETCD type, wherein the forwarding type is used to indicate the type of the message middleware that forwards the message to be sent; The forwarding module is used to select the ETCD cluster as the target message middleware to forward the target message to the target command issuing service.

9. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein: The processor, the communication interface and the memory communicate with each other via the communication bus, wherein: The memory is used to store computer programs; The processor is configured to execute the method steps of any one of claims 1 to 7 by running the computer program stored in the memory.

10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method steps described in any one of claims 1 to 7 when run.