Method for transmitting synchronization message and related equipment
By storing the correspondence between the message ID of the synchronous message and the service thread in the administrator device and setting the service thread to a dormant state, the problem that asynchronous transmission in the satellite-ground converged network cannot meet the synchronous service processing is solved, and the continuity of synchronous message transmission and service processing is achieved.
Patent Information
- Application Number
- CN202311564376.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-22
- Publication Date
- 2025-05-23
AI Technical Summary
In the satellite-ground converged network, asynchronously transmitted data cannot meet the requirements of synchronous data transmission in scenarios such as service issuance and data subscription, resulting in discontinuous service processing.
By storing the correspondence between the message ID of the synchronization message and the business thread in the administrator device, and setting the corresponding business thread to sleep after sending the synchronization message, the business thread is ensured that the business thread waits for the return of the result message.
The synchronous transmission of messages is realized, ensuring the continuity and accuracy of service processing, especially in the multi-threaded concurrency scenario, the corresponding business threads corresponding to specific synchronous messages are effectively located and processed.
Smart Images

Figure CN120034298A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technologies, and in particular, to a method for transmitting synchronization messages and related devices. Background Art
[0002] In the current space-ground network, when transmitting space-ground integrated network management data, the data is transmitted asynchronously. However, in scenarios such as service distribution and data subscription, a synchronous data transmission method must be adopted, that is, the requesting party must receive the return result of the communication before proceeding with the distribution of the next service.
[0003] Therefore, it is necessary to propose a method for transmitting synchronization messages to ensure synchronous service processing. Summary of the Invention
[0004] The purpose of the embodiments of the present invention is to provide a method for transmitting synchronization messages and related devices to ensure the synchronous transmission of messages. The specific technical solutions are as follows:
[0005] In a first aspect, the embodiments of the present invention provide a method for transmitting synchronization messages, which is applied to a manager device. The method includes:
[0006] For a synchronization message to be sent, store the correspondence between the message ID of the synchronization message and the service thread to which the synchronization message belongs;
[0007] Send the synchronization message to an agent device, and set the service thread corresponding to the synchronization message to a dormant state after sending the synchronization message.
[0008] Optionally, it further includes:
[0009] When receiving a result message returned by the agent device, determine the service thread corresponding to the result message based on the message ID of the result message and the correspondence; wherein, the message ID of the result message is the same as the message ID of the synchronization message targeted by the result message;
[0010] Wake up the service thread so that the service thread can obtain the result message.
[0011] Optionally, the storage of the correspondence is specifically implemented based on a hash mapping between the message ID and the thread ID of the service thread.
[0012] Optionally, the synchronization message carries the manager ID of the manager device.
[0013] Optionally, it further includes:
[0014] If a result message for the synchronization message is not received within a preset duration after the synchronization message is sent, wake up the service thread corresponding to the synchronization message so that the service thread performs timeout processing on the synchronization message.
[0015] Optionally, the management device and the proxy device communicate based on the publish / subscribe mode. The sending of the synchronization message to the proxy device specifically includes:
[0016] Publish the synchronization message to the message topic pointing to the proxy device. The topic name of the message topic carries the proxy ID of the proxy device, so that the proxy device obtains the synchronization message through the subscribed message topic; the proxy device subscribes to the message topic pointing to itself.
[0017] Optionally, the management device specifically receives the result message through the message topic it subscribes to; the result message is published by the proxy device to the message topic pointing to the management device. The topic name of the message topic carries the management ID of the management device, and the management device subscribes to the message topic pointing to itself.
[0018] Optionally, multiple first message channels are defined under the message topic pointing to the proxy device. The sending of the synchronization message to the message topic pointing to the proxy device specifically includes:
[0019] Publish the synchronization message to the first message channel defined under the message topic pointing to the proxy device.
[0020] Optionally, the sending of the synchronization message to the first message channel defined under the message topic pointing to the proxy device specifically includes:
[0021] Perform a modulo operation on the message ID of the synchronization message and the total number of the first message channels, and publish the synchronization message to the first message channel indicated by the modulo operation result.
[0022] In a second aspect, an embodiment of the present invention provides a method for transmitting a synchronization message, which is applied to a proxy device. The method includes:
[0023] Receive a synchronization message sent by a management device;
[0024] Return a result message for the synchronization message to the management device, so that the management device determines and wakes up the service thread corresponding to the result message based on the message ID of the result message and the correspondence between the message ID and the service thread, so that the service thread obtains the result message; the message ID of the result message is the same as the message ID of the synchronization message targeted by the result message.
[0025] Optionally, the corresponding relationship is pre-stored by the manager device during the process of sending the synchronization message.
[0026] Optionally, the synchronization message carries an administrator ID of an administrator device that sends the synchronization message, and returning a result message for the synchronization message to the administrator device specifically includes:
[0027] A result message for the synchronization message is returned to the manager device indicated by the manager ID.
[0028] Optionally, the proxy device receives the synchronization message through a message topic to which it subscribes, the synchronization message is published by the manager device to a message topic directed to the proxy device, the message topic carries a proxy ID of the proxy device, and the proxy device subscribes to a message topic directed to itself;
[0029] The step of returning a result message of the synchronization message to the manager device specifically includes:
[0030] The result message for the synchronization message is returned to the message topic pointing to the manager device, and the topic name of the message topic carries the manager ID of the manager device, so that the manager device receives the result message through the subscribed message topic; the manager device subscribes to the message topic pointing to itself.
[0031] Optionally, a plurality of second message channels are defined under the message topic directed to the manager device, and returning the result message of the synchronization message to the message topic directed to the manager device specifically includes:
[0032] A result message for the synchronization message is published to a second message channel defined under a message topic directed to the manager device.
[0033] Optionally, publishing the result message for the synchronization message to a second message channel defined under a message topic directed to the manager device specifically includes:
[0034] A modulo operation is performed on the message ID of the result message and the total number of the second message channels, and the result message is published to the second message channel indicated by the modulo operation result.
[0035] In a third aspect, an embodiment of the present invention provides a manager device, including:
[0036] A storage module, used for storing, for a synchronization message to be sent, a correspondence between a message ID of the synchronization message and a business thread to which the synchronization message belongs;
[0037] The sending module is used to send the synchronization message to the proxy device, and put the service thread corresponding to the synchronization message into a dormant state after sending the synchronization message.
[0038] In a fourth aspect, an embodiment of the present invention provides a proxy device, including:
[0039] A receiving module, used for receiving synchronization messages sent by the manager device;
[0040] A return module is used to return the result message for the synchronization message to the manager device, so that the manager device determines and wakes up the business thread corresponding to the result message based on the message ID of the result message and the correspondence between the message ID and the business thread, so that the business thread obtains the result message; the message ID of the result message is consistent with the message ID of the synchronization message targeted by the result message.
[0041] In a fifth aspect, an embodiment of the present invention provides an electronic device, 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;
[0042] Memory, used to store computer programs;
[0043] The processor is used to implement any of the above methods for transmitting synchronization messages when executing a program stored in the memory.
[0044] In a sixth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the computer program implements any of the above-mentioned methods for transmitting synchronization messages.
[0045] An embodiment of the present invention further provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-mentioned methods for transmitting a synchronization message.
[0046] Beneficial effects of the embodiments of the present invention:
[0047] The method and related equipment for transmitting synchronous messages provided by the embodiment of the present invention store the message ID of the synchronous message and the corresponding relationship between the business thread for the synchronous message to be sent during the process of sending the synchronous message, and put the corresponding business thread into a dormant state after sending the synchronous message, so that the business thread is blocked before sending the next synchronous message, so that the result message of the synchronous message that has been sent can be waited for, thereby ensuring the synchronous transmission of the message. In addition, the embodiment of the present invention stores the corresponding relationship between the message ID and the business thread, which is convenient for the subsequent corresponding processing of the synchronous message based on the business thread, and can effectively locate the business thread corresponding to the specific synchronous message in the scenario of multi-thread concurrency.
[0048] Of course, it is not necessary to achieve all of the advantages described above at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other embodiments can also be obtained based on these drawings.
[0050] Figure 1 It is a flowchart of a method for transmitting synchronization messages provided by an embodiment of the present invention;
[0051] Figure 2 is another flowchart of a method for transmitting a synchronization message provided by an embodiment of the present invention;
[0052] Figure 3 It is a schematic diagram of the structure of a manager device and an agent device provided in an embodiment of the present invention;
[0053] Figure 4 is a schematic diagram of the timing of sending a synchronization message provided by an embodiment of the present invention;
[0054] Figure 5 is a schematic diagram of a timing sequence of receiving a result message provided by an embodiment of the present invention;
[0055] Figure 6 is a schematic diagram of the organizational structure of the coordination component provided in an embodiment of the present invention;
[0056] Figure 7 is a schematic diagram of synchronous service directional interaction provided by an embodiment of the present invention;
[0057] Figure 8 It is another flow chart of the method for transmitting synchronization messages provided by an embodiment of the present invention;
[0058] Fig. 9 is a schematic diagram of the structure of a manager device provided by an embodiment of the present invention;
[0059] Fig.10 is a schematic diagram of the structure of a proxy device provided by an embodiment of the present invention;
[0060] Fig.11 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0061] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field based on this application belong to the scope of protection of the present invention.
[0062] In the process of duplex communication, two different message transmission mechanisms are usually involved: asynchronous transmission and synchronous transmission. In the asynchronous transmission scenario, after the requester sends a message, it does not need to wait for the return message from the receiver before sending the next message. In the synchronous transmission scenario, the requester must receive the return message from the receiver before sending the next message.
[0063] In the actual communication process, according to different application requirements, it is necessary to switch between asynchronous and synchronous message transmission modes.
[0064] Taking the satellite-ground fusion network as an example, in the process of transmitting network management data, the data is transmitted asynchronously. However, in scenarios such as service delivery and data subscription, synchronous data transmission is required.
[0065] The synchronous transmission of messages in the satellite-ground fusion network specifically involves information interaction between two types of entities: managers and satellite agents. Managers and satellite agents specifically use the manager / agent communication model for information interaction, where the manager can be deployed in the ground management network, responsible for message routing between the ground and the satellite, and ensuring QoS (Quality of Service), responsible for processing the data transmitted back to the ground by the satellite, and can issue instructions to the satellite. The satellite agent is deployed on the satellite, can receive the instructions sent by the manager, perform corresponding business processing, and return the processing results to the manager.
[0066] Therefore, it is necessary to propose a synchronous message transmission method to ensure synchronous business processing.
[0067] To solve this problem, an embodiment of the present invention provides a method for transmitting a synchronization message. Figure 1 This is a flow chart of a method for transmitting synchronization messages provided by an embodiment of the present invention, which is specifically applied to a manager device. For a satellite-to-ground communication scenario, the manager device may be a manager device deployed in a ground management network, and the proxy device communicating with the manager device may be a satellite-borne proxy. Figure 1 , the method specifically comprises the following steps:
[0068] Step S101: for a synchronization message to be sent, the correspondence between the message ID of the synchronization message and the business thread to which the synchronization message belongs is stored.
[0069] The service thread is used to generate messages and process network management services. When a message needs to be sent to an agent, the manager device can send a synchronous message to the coordination component based on one or more service threads. When multiple threads are concurrent, each synchronous message needs to occupy a service thread. For example, if the manager device needs to concurrently send N synchronous messages, it needs to send these synchronous messages separately based on N service threads.
[0070] In the embodiment of the present invention, for the synchronization message to be sent, the manager device will specifically cache the correspondence between the message ID of the synchronization message and the service thread in its own component. The embodiment of the present invention does not limit the specific method of storing this correspondence. As an example, each set of message IDs and service threads with a corresponding relationship can be stored in an array, and the cache format is specifically: cache = {message ID, service thread}.
[0071] Step S102: Send a synchronization message to the proxy device, and after sending the synchronization message, put the service thread corresponding to the synchronization message into a dormant state.
[0072] In an embodiment of the present invention, after a synchronization message is sent, the manager device will put the service thread corresponding to the synchronization message into a dormant state. It should be understood that a service thread cannot send or receive messages when it is in a dormant state. When it is necessary to ensure the synchronous transmission of messages, the service thread needs to receive the corresponding result message for the sent synchronization message before it can send or receive the next synchronization message. Therefore, putting the corresponding service thread to sleep after sending a synchronization message can have the effect of blocking the thread, so that the thread waits for the corresponding result message. When a service thread is in a dormant state, the resources it occupies will also be released accordingly.
[0073] The method for transmitting synchronous messages provided by the embodiment of the present invention stores the message ID of the synchronous message and the corresponding relationship between the business thread for the synchronous message to be sent during the process of sending the synchronous message, and puts the corresponding business thread into a dormant state after sending the synchronous message, so that the business thread is blocked before sending the next synchronous message, so that the result message of the synchronous message that has been sent can be waited for, thereby ensuring the synchronous transmission of the message. In addition, the embodiment of the present invention stores the corresponding relationship between the message ID and the business thread, which is convenient for the subsequent corresponding processing of the synchronous message based on the business thread, and can effectively locate the business thread corresponding to the specific synchronous message in the scenario of multi-thread concurrency.
[0074] After the manager device sends a synchronization message, the proxy device will specifically perform corresponding business processing based on the received synchronization message, and return a response to the synchronization message to the manager device. In one or more embodiments of the present invention, this response is specifically referred to as a result message. As mentioned above, the manager device specifically sends synchronization messages based on business threads, and each business thread is specifically used to generate synchronization messages and perform corresponding business processing based on the synchronization messages. Therefore, in order to ensure the normal business processing process, the result message returned by the proxy device should be specifically returned to the business thread to which the synchronization message to which the result message belongs belongs. Therefore, the embodiments of the present invention also provide corresponding improvements to the process of receiving result messages, see. Figure 2 The method further comprises the following steps:
[0075] Step S103: when receiving the result message returned by the proxy device, determine the service thread corresponding to the result message based on the message ID and the corresponding relationship of the result message; wherein the message ID of the result message is consistent with the message ID of the synchronization message targeted by the result message.
[0076] Specifically, a complete synchronous data interaction process includes two processes: synchronous message sending and synchronous message receiving. In an embodiment of the present invention, the message ID in the same interaction is unique and unchanged. Specifically, the message ID of each result message is consistent with the message ID of the synchronous message to which the result message corresponds.
[0077] It should be understood that in a multi-threaded concurrent scenario, in order to ensure synchronous transmission of messages, for each result message returned by the proxy device, it is necessary to ensure that this result message is correctly forwarded to a corresponding business thread. Since the manager device pre-stores the correspondence between its message ID and the business thread during the synchronous message sending process, and the message ID is unique within the same interaction, for each result message returned by the proxy device, the manager device can accurately determine the business thread corresponding to this result message based on the message ID of the result message and the pre-stored correspondence.
[0078] Step S104: Wake up the service thread so that the service thread obtains the result message.
[0079] For the result message returned by the proxy device, the manager device can wake up the business thread after determining the business thread corresponding to the result message, so that the business thread can obtain the result message, and after receiving the result message, the awakened business thread can perform corresponding business processing according to the result message.
[0080] As an example, if the message ID of a synchronization message sent by the management device is 1, and the thread ID of the business thread to which the synchronization message belongs is 2, and the manager device will store the correspondence between the two. When the proxy device returns a corresponding result message for this synchronization message, the message ID of the result message is consistent with the synchronization message it is targeting, specifically 1. Based on the message ID and the correspondence, the manager device determines that the thread ID of the business thread corresponding to the result message is 2, wakes up the business thread, and performs corresponding business processing based on the business thread according to the result message, thus completing a complete synchronization message sending and receiving process.
[0081] In the method for transmitting synchronous messages provided by the embodiment of the present invention, the correspondence between the synchronous message ID and the business thread is pre-stored during the synchronous message sending process, and during the synchronous message receiving process, the message IDs of the synchronous message and the result message are consistent during the same interaction process. Therefore, for the synchronous message receiving process, the manager device can determine the business thread corresponding to the result message based on the message ID of the result message and the pre-stored correspondence, and wake up the business thread, and the business thread processes the result message accordingly, thereby realizing the synchronous transmission of the message.
[0082] Moreover, for multi-threaded concurrent message sending scenarios, since the manager device stores the correspondence between the message ID and the business thread, when there are multiple dormant business threads, it can determine the business thread corresponding to each result message based on the message ID of the result message and this correspondence, so as to ensure that the result message returned by the proxy device can be transferred to the correct business thread and ensure the business processing result.
[0083] In the case of multi-thread concurrency, for each result message returned by the proxy device, the manager device specifically needs to determine the service thread corresponding to the result message from multiple service threads in a dormant state. In one embodiment of the present invention, in order to avoid traversing these service threads, the storage of the corresponding relationship is specifically implemented based on a hash mapping between the message ID and the thread ID of the service thread.
[0084] Each set of message ID and thread ID can be understood as a set of key-value pairs. Hash mapping is a specific implementation for storing key-value pairs. It establishes the correspondence between keys and values through hash operations, and can directly locate the stored values based on the keys and hash operations.
[0085] In other words, in this embodiment, the manager device specifically stores the correspondence between the message ID and the thread ID of the business thread through a hash table. The hash table is specifically a data structure, and supports fast insertion and search of data. The hash table can specifically have multiple different storage locations. For each data that needs to be written into the hash table for storage, the key can be hashed based on its key through a preset hash function, and the hash operation result specifically corresponds to a storage location in the hash table, so that the value of the data can be written into this storage location.
[0086] As an example, in an embodiment of the present invention, the message ID of the synchronization message can be used as a key to perform a hash operation on it, and then the thread ID of the corresponding service thread is written into the storage location indicated by the hash operation result in the hash table. In this process, the specific hash function used in the hash operation can be selected based on actual needs, and the embodiment of the present invention does not limit this.
[0087] Exemplarily, if there are N different storage locations in the hash table, numbered 0 to N-1, the hash operation can be a modulo operation of the message ID and N. If the hash operation result is i, the thread ID of the corresponding business thread is written into the storage location numbered i in the hash table.
[0088] Similarly, when the manager device receives the result message returned by the proxy device, the manager device can perform a hash operation on the message ID of the result message, and the business thread recorded in the storage location indicated by the hash operation result in the hash table is the business thread corresponding to the result message.
[0089] When the corresponding relationship is stored based on a hash mapping between the message ID and the thread ID, the specific business thread recorded in the result message returned by the proxy device can be directly located by performing a hash operation on its message ID, without traversing each dormant business thread. The time complexity of querying the business thread corresponding to the result message is O(1), and the processing efficiency will not be affected by the business concurrency, thereby ensuring the processing efficiency of the coordination component in the case of large-scale concurrency.
[0090] In an actual satellite-ground fusion network, a manager device cluster including multiple manager devices may be deployed. In this case, in order to ensure that the proxy device can correctly return the result message to the manager device that sends the corresponding synchronization message, in one embodiment of the present invention, the synchronization message carries the manager ID of the manager device to identify the manager device that sends the synchronization message.
[0091] Therefore, in the embodiment of the present invention, after receiving the synchronization message, the agent device may return a result message for the synchronization message to the manager device indicated by the manager ID based on the manager ID carried in the synchronization message.
[0092] It can be seen that by carrying the manager ID in the synchronization message, when the manager device cluster includes multiple manager devices, it can be ensured that the proxy device correctly returns the result message for a specific synchronization message to the manager device that sent the synchronization message.
[0093] In one embodiment of the present invention, the method for transmitting a synchronization message further includes:
[0094] If no result message for the synchronization message is received within the preset time after the synchronization message is sent, the business thread corresponding to the synchronization message is woken up so that the business thread performs timeout processing on the synchronization message
[0095] Specifically, in order to avoid the situation that the proxy device cannot return the result message, or the result message returns an error, etc., which causes the service thread to be unable to wait for the corresponding result message and be in a dormant state for a long time, the maximum waiting time for the service thread to receive its result message, that is, the preset time, can be set. Among them, the preset time corresponding to each synchronization message can be configured separately, and the embodiment of the present invention is not limited to this.
[0096] As an example, a timer can be configured inside the administrator device to measure the response time of the proxy device to the synchronization message, or the waiting time for the result message of the synchronization message. When the response time recorded by the timer for any synchronization message exceeds the preset time, the business thread is woken up and the business thread performs timeout processing on the corresponding synchronization message.
[0097] The specific structure of the timer can be selected based on actual needs, and the embodiment of the present invention does not limit this. As an example, the timer can be a ring queue. The ring queue is specifically a data structure, which specifically stores the request time of each synchronization message. The corresponding response time of the synchronization message exceeding the preset time can be determined based on the data pointer, and the service thread corresponding to the synchronization message can be awakened. The specific content of the ring queue can refer to the content in the relevant technology, which will not be repeated here.
[0098] After determining that the response time corresponding to any synchronization message exceeds the preset time, the specific timeout processing process can be selected based on actual needs. The embodiment of the present invention is not limited to this. As an example, the timeout processing can specifically be request retransmission or request discard.
[0099] In an embodiment of the present invention, when no result message for the synchronization message is received within a preset time after the synchronization message is sent, the manager device performs a timeout process on the synchronization message by waking up the corresponding business thread, which can avoid abnormal situations causing the business thread to be in a dormant state for a long time, and helps to ensure business processing efficiency.
[0100] In one embodiment of the present invention, the manager device communicates with the proxy device based on a publish / subscribe mode, and sends the synchronization message to the proxy device, specifically including:
[0101] The synchronization message is published to the message topic pointing to the proxy device. The topic name of the message topic carries the proxy ID of the proxy device, so that the proxy device obtains the synchronization message through the subscribed message topic; the proxy device subscribes to the message topic pointing to itself.
[0102] Specifically, in the publish / subscribe mode, the message publisher and the message subscriber can specifically implement message interaction between the two parties based on the message topic. For the sending process of synchronous messages, the manager device (Manager) is the message publisher, and the agent device (Agent) is the message subscriber, and the publisher can specify its message topic when publishing the message. In an embodiment of the present invention, the manager device can publish the synchronous message to the message topic pointing to the agent device according to the agent device to which the synchronous message is directed. Specifically, in the case of deploying a cluster of agent devices, a message topic pointing to the agent device can be designed for each agent device in the cluster, and each agent device needs to subscribe to the message topic pointing to itself to ensure that the agent device can obtain the synchronous message published to itself based on this topic.
[0103] As an example, the agent device to which the message topic points can be indicated by carrying the agent ID of the agent device in the topic name of the message topic. Taking the example of the manager device and the agent device communicating based on MQTT (Message Queuing Telemetry Transport), the topic name of the message topic pointing to the agent device can be specifically agent / ${agentId} / #. Specifically, the MQTT message topic can specifically contain topics of different levels, wherein the agent in the topic name represents the message to be sent to the agent device in the topic, ${agentId} represents the agent ID of the agent device to which the message in the topic specifically points, and # is a topic wildcard, representing the first-level or multi-level sub-topics contained below ${agentId}, which is not specifically limited in the embodiments of the present invention.
[0104] In an embodiment of the present invention, when the manager device and the agent device communicate based on the publish / subscribe mode, when the manager device needs to send a synchronization message to the agent device, the manager device specifically publishes the synchronization message to the message topic pointing to the agent device, and the agent device subscribes to the message topic pointing to itself, which can ensure that the synchronization message is correctly sent to the corresponding agent device and ensure the communication efficiency between the manager device and the agent device.
[0105] Correspondingly, for the process of receiving the result message, the manager device specifically receives the result message through the message topic to which it subscribes; the result message is published by the proxy device to the message topic pointing to the manager device, and the topic name of the message topic carries the manager ID of the manager device, and the manager device subscribes to the message topic pointing to itself.
[0106] Specifically, for the result message receiving process, the proxy device is the message publisher, and the manager device is the message subscriber. As an example, when the proxy device needs to return a result message, it can determine which message topic the result message needs to be published to based on the manager ID carried in the synchronization message, and the message topic of the result message points to the message topic of the manager device corresponding to the manager ID. Specifically, when deployed in a manager device cluster, a message topic pointing to the manager device can be designed for each manager device, and each manager device needs to subscribe to the message topic pointing to itself to ensure that the manager device can obtain the result message published to itself based on this topic.
[0107] Similarly, the manager ID of the manager device can be carried in the topic name of the message topic pointing to the manager device to indicate the manager device to which the message topic specifically points. As an example, the topic name of the message topic pointing to the manager device can be manager / ${manId} / #, where manager in the topic represents the message to be sent to the manager device, and ${manId} represents the manager ID of the manager device to which the message in the topic specifically points.
[0108] The following is an explanation with a specific example. If a manager device with manager ID 1 wants to send a synchronization message to a proxy device with proxy ID 2, the synchronization message is specifically published to the message topic agent / ${agentId=2}. The proxy device with proxy ID 2 subscribes to this topic, so the proxy device can obtain the corresponding synchronization message based on this message topic. When the proxy device completes the corresponding processing and needs to return a result message to the manager device, the result message is specifically published to the message topic manager / ${manId=1}. The manager device with manager ID 1 subscribes to this topic, so the manager device can obtain the corresponding result message based on this message topic. At this point, the manager device with manager ID 1 and the proxy device with proxy ID 2 have completed a synchronization message interaction.
[0109] In addition, in the publish / subscribe mode, the manager device and the proxy device can specifically transfer messages based on the proxy server. That is, for the process of sending a synchronization message, the manager device specifically publishes the message to the proxy server, and the proxy server pushes the synchronization message to the proxy device that subscribes to the corresponding message topic based on its message topic, and the process of receiving the result message is similar. The proxy server can be configured inside the manager device, or deployed independently of the manager device and the proxy device, and the embodiment of the present invention is not limited to this.
[0110] In an embodiment of the present invention, during the process of the manager device receiving the result message, the proxy device publishes the result message to the message topic pointing to the manager device, and the manager device subscribes to the topic pointing to itself, which can ensure that the message is correctly sent to the corresponding manager device and ensure the communication efficiency between the manager device and the proxy device.
[0111] Corresponding to the contents recorded in the above embodiments, an embodiment of the present invention further provides a manager device, which is specifically used to implement the method for transmitting synchronization messages provided by one or more embodiments of the present invention. Figure 3 is a schematic diagram of the structure of the manager device provided in an embodiment of the present invention, see Figure 3 , the manager device may specifically include:
[0112] The service processing component is responsible for generating messages and handling network management services;
[0113] The sending component is responsible for sending messages to the MQTT Broker.
[0114] MQTT Broker, responsible for routing messages and ensuring QoS;
[0115] The response component is responsible for receiving the result message for the synchronization message and forwarding the result message to the coordination component;
[0116] The coordination component is responsible for storing the relationship between the message ID and the business thread, handling timeouts, and determining the corresponding business thread based on the returned result message.
[0117] The above-mentioned MQTT Broker can be understood as a proxy server under the MQTT protocol. Correspondingly, the proxy device can also include a response component, a business processing component and a sending component. After receiving the synchronization message sent by the manager device, the response component of the proxy device pushes the synchronization message to the business processing component of the proxy device, and the business processing component performs corresponding processing according to the synchronization message, and sends the result data obtained by the processing to the sending component of the proxy device, and the sending component of the proxy device returns the result message to the manager device.
[0118] exist Figure 3 In the example, the solid line is used to represent the sending process of the synchronization message, and the dotted line is used to represent the receiving process of the synchronization message. Figure 4 and Figure 5 The following are schematic diagrams of the timing of sending synchronization messages and receiving result messages provided in embodiments of the present invention, respectively. Figures 3 to 5 The synchronous message interaction process is described in detail.
[0119] See also Figure 4, the process of sending a synchronization message may specifically include the following steps:
[0120] Step S401: The service processing component sends a synchronization message to the coordination component.
[0121] As an example, the service processing component is specifically configured to send the payload of the synchronization message, the agent ID of the agent device pointed to by the synchronization message, the message ID of the synchronization message, and the sending primitive to the coordination component based on the service thread.
[0122] Step S402: Coordinating component cache service threads.
[0123] Specifically, after receiving the synchronization message sent by the service processing component, the coordination component will first build a cache, and cache the correspondence between the message ID of each synchronization message and the service thread in its own component.
[0124] Step S403: The coordinating component forwards the synchronization message to the sending component.
[0125] Step S404: The sending component forwards the synchronization message to the MQTT Broker.
[0126] In this process, the sending component and the MQTT Broker communicate specifically through MQTT messages. Therefore, when the business processing component is specifically used to send the payload of the synchronization message, the message ID of the synchronization message, the sending primitive and the proxy ID of the proxy device, the sending component is specifically used to encapsulate this information into a synchronization message in the MQTT message format for sending. In this embodiment, the sending component is specifically used to send the synchronization message containing the payload, message ID and sending primitive to the proxy device indicated by the proxy ID, or in other words, the message topic sent to the MQTT Broker pointing to the proxy device corresponding to the proxy ID pushes the synchronization message to the proxy device through the MQTT Broker. In addition, before sending the synchronization message, the sending component can also add the administrator ID to the synchronization message.
[0127] It can be seen that the payload of the synchronization message, the message ID of the synchronization message, the sending primitive and the agent ID of the agent device are sent through the business processing component, and the sending component sends the synchronization message containing the payload, message ID and sending primitive based on the agent ID, which helps to improve the processing efficiency and communication efficiency within the management device.
[0128] In addition, in order to avoid the corresponding business thread still entering the dormant state when an exception occurs during the sending process and the synchronization message cannot be sent smoothly, the MQTT Broker can provide feedback on the sending result after executing the sending of the synchronization message, and return the sending result to the business processing component to inform the business processing component that the corresponding synchronization message has been successfully sent. In this way, the business processing component can put the corresponding business thread into the dormant state while ensuring that the synchronization message is sent smoothly, so as to avoid the abnormal dormancy of the business thread that may be caused by the abnormal message sending, and ensure the processing efficiency of the business processing component and the communication effect between the manager device and the agent device. This process can specifically include the following steps:
[0129] Step S405: The MQTT Broker returns the sending result to the sending component.
[0130] Specifically, after sending the synchronization message, the MQTT Broker may return the corresponding sending result to the sending component.
[0131] Step S406: The sending component forwards the sending result to the coordinating component.
[0132] Step S407: The coordination component forwards the sending result to the service processing component.
[0133] Step S408: The business processing component puts the business thread into hibernation.
[0134] Specifically, after receiving the sending result for a specific synchronization message, the service processing component may put the service thread corresponding to the synchronization message into a dormant state, wait for the service processing result, and release resources.
[0135] After the manager device sends the synchronization message, the proxy device will specifically listen to the synchronization message through its response component, and the response component will forward the synchronization message to the business processing component of the proxy device for corresponding processing. After the processing is completed, the business processing component will forward the processing result to the sending component of the proxy device. Based on the manager ID carried in the synchronization message, the sending component will return the result message containing the response primitive, message ID and processing result payload to the corresponding manager device for synchronization message interaction.
[0136] See also Figure 5 , the process of receiving the result message may specifically include the following steps:
[0137] Step S501: The MQTT Broker sends a result message to the response component.
[0138] Specifically, when the manager device receives the result message, the MQTT Broker pushes the result message reported by the agent device to the response component.
[0139] Step S502: The response component forwards the result message to the coordination component.
[0140] Step S503: Coordinate component matching cache.
[0141] Step S504: The coordination component wakes up the service thread.
[0142] Step S505: forward the result message.
[0143] As mentioned above, the coordination component is used to cache the correspondence between the message ID and the business thread, and the message ID of the synchronization message and the message ID of the result message in the same message interaction process are consistent. Therefore, for the returned result message, the coordination component can determine the corresponding business thread in its own cache based on its message ID, wake up the business thread, and push the result message to the business thread after waking up the business thread.
[0144] Step S506: The business processing component performs business processing.
[0145] Specifically, after receiving the corresponding result message, the service thread of the service processing component may perform corresponding service processing based on the result message.
[0146] Based on this, it can be seen that for the transmission of synchronization messages, the coordination component is the core component in the manager device. Figure 6 The schematic diagram of the organizational structure of the coordination component provided in the embodiment of the present invention is shown below in conjunction with Figure 6 The organizational structure of the coordination components is described in detail.
[0147] See also Figure 6 , the attributes in the coordination component (Coordinator) specifically include: a hash table (HashTable) storing the correspondence between the message ID (MsgID) and the business thread (WorkerThread), that is, the HashTable shown in the figure<MsgID,WorkerThread> msgCache; a timer (Timer) for timing message responses, namely the Timer timeoutTimer shown in the figure.
[0148] The coordination component specifically includes four operations, namely: message cache operation cache(MsgID,WorkerThread), which is used to store the correspondence between the message ID and the business thread; business thread wake-up operation wake(MsgID,WorkerThread), which is used to wake up the business thread corresponding to the result message returned by the proxy device; message sending operation send(Msg,WorkerThread) and message receiving operation receive(Msg), which are used to realize information interaction with the business processing component, the sending component and the response component.
[0149] As mentioned above, the message publisher and the message subscriber implement information exchange based on the message topic. Therefore, the message topic is essentially the basis for the proxy server to route messages. Therefore, in the process of information exchange, the message topic defined in the publish / define mode can also be regarded as the agreed message channel between the publisher and the subscriber, or the message channel between the publisher and the subscriber can be realized through the definition of the message topic.
[0150] In addition, in one embodiment of the present invention, the manager device and the proxy device can realize data transmission of multiple message channels. In the embodiment of the present invention, when the manager device is used as the publisher, the message channel defined under the message topic pointing to the proxy device is called the first message channel. In this embodiment, multiple first message channels are defined under the message topic pointing to the proxy device. The aforementioned publishing of the synchronization message to the message topic pointing to the proxy device specifically includes:
[0151] The synchronization message is published to the first message channel defined under the message topic directed to the proxy device.
[0152] Continuing with the previous example, the first message channel is specifically the message channel containing the field agent / ${agentId} in the corresponding message subject. Correspondingly, when the agent device is used as the publisher, the message channel defined under the message subject pointing to the manager device is called the second message channel. Continuing with the previous example, the second message channel is specifically the message channel containing the field manager / ${manId} in the corresponding message subject.
[0153] Taking the communication between the manager device and the agent device based on the MQTT protocol as an example, the first message channel and the second message channel themselves are asynchronous channels based on the MQTT protocol, but overall, the embodiment of the present invention uses the first message channel and the second message channel to achieve synchronous message transmission between the manager device and the agent device. Therefore, the first message channel and the second message channel can be generally referred to as synchronous directional channels.
[0154] Therefore, in the process of sending the synchronization message, for any synchronization message to be sent, the synchronization message can be published to one of the first message channels defined under the message topic pointing to the proxy device.
[0155] Combined with the previous Figure 3 In a multi-channel interaction scenario, the sending component is responsible for managing and selecting message channels, and the MQTT Broker is responsible for maintaining these message channels. The number of first message channels in the first message channel set can be determined based on the processing capability of the manager device. Correspondingly, the number of second message channels in the second message channel set is determined based on the processing capability of the proxy device, and the proxy device can report the number of its own second message channels during the registration process with the MQTT Broker.
[0156] As an example, the message topic in the synchronous directional channel can be defined as follows:
[0157] Publisher Message Topic Subscriber illustrate Manager agent / ${agentId} / rpc / ${channelId} / sync Agent Synchronous Directional Channel Agent manager / ${manId} / rpc / ${channelId} / sync Manager Synchronous Directional Channel
[0158] Figure 7 This is a schematic diagram of the synchronous service directional interaction provided by an embodiment of the present invention. Figure 7 The specific process of synchronous message interaction is described.
[0159] During the process of sending the synchronization message, the sending component of the manager device sends the synchronization message to the MQTT Broker through the first message channel, and the first message channel is specifically carried on the topic agent / ${agentId} / rpc / ${channelId} / sync, where agent represents that the message is specifically to be sent to the agent device, ${agentId} represents the agent ID of the agent device to which the message specifically points, rpc represents the remote procedure call, ${channelId} represents the channel ID, and sync represents that the message is specifically used for synchronization message interaction. The response component of the agent device can obtain the synchronization message in the topic based on subscription. As an example, if an administrator device with an administrator ID of 1 wants to interact with an agent device with an agent ID of 2 for synchronous messages, and the total number of the first message channels is M, then the subtopic {channelId} under the message topic agent / ${agentId=2} specifically includes {channelId=0} to {channelId=M-1}. If the administrator device determines to transmit one of the synchronous messages through the first message channel with a channel ID of i, then the message topic of the synchronous message is specifically agent / ${agentId=2} / rpc / ${channelId=i} / sync.
[0160] Correspondingly, during the receiving process of the result message, the sending component of the proxy device sends the result message to the MQTT Broker through the second message channel, and the second message channel is specifically carried on the topic manager / ${manId} / rpc / ${channelId} / sync, where manager indicates that the message is specifically to be sent to the manager device, ${manId} is the manager ID of the manager device that the message specifically points to, and the response component of the manager device can obtain the synchronization message in this topic based on subscription. Continuing with the previous example, if the proxy device with proxy ID 2 needs to return a result message to the manager device with manager ID 1, and the total number of the second message channels is N, then the sub-topics {channelId} under the message topic manager / ${manId = 1} specifically include {channelId = 0} to {channelId = N - 1}. If the proxy device determines to return one of the result messages through the second message channel with channel ID j, the message topic of this result message is specifically manager / ${manId = 1} / rpc / ${channelId = j} / sync.
[0161] Based on the multi-channel data transmission model for synchronous message interaction, it is possible to achieve the concurrent response of the proxy device to synchronous messages and ensure the business processing efficiency of the entire system.
[0162] In an embodiment of the present invention, the foregoing step of publishing the synchronous message to the first message channel defined under the message topic pointing to the proxy device specifically includes:
[0163] Performing a modulo operation on the message ID of the synchronous message and the total number of the first message channels, and publishing the synchronous message to the first message channel indicated by the modulo operation result.
[0164] As mentioned in the foregoing embodiment, when the manager device sends a message, for each message, it can select a first message channel to send the message. In the embodiment of the present invention, the first message channel for sending a specific message can be specifically determined based on the following formula:
[0165] ${channelId} = ${message_id} % ${total_channel_number}
[0166] Where, ${channelId} is the channel ID of the determined first message channel, ${message_id} is the message ID of the message to be sent, and ${total_channel_number} is the total number of the first message channels.
[0167] As an example, if N first message channels are defined under a message topic directed to a proxy device, the channel IDs of these N channels may be 0 to N-1 in sequence. It can be seen that when sending a message, the specific message channel is determined by the modulo operation result between the message ID and the total number of first message channels, which helps to achieve load balancing between different message channels, thereby improving business processing efficiency.
[0168] Accordingly, the embodiment of the present invention also provides a method for transmitting synchronization messages applied to a proxy device, see Figure 8 , the method specifically comprises the following steps:
[0169] Step S801: receiving a synchronization message sent by a manager device;
[0170] Step S802: Return the result message for the synchronization message to the manager device, so that the manager device determines and wakes up the business thread corresponding to the result message based on the message ID of the result message and the correspondence between the message ID and the business thread, so that the business thread obtains the result message; the message ID of the result message is consistent with the message ID of the synchronization message targeted by the result message.
[0171] For the specific contents of the above steps, please refer to the aforementioned embodiment of the manager device, which will not be described in detail here.
[0172] In the method for transmitting synchronization messages provided by an embodiment of the present invention, the message IDs of the synchronization message and the result message are consistent during the same interaction process. Therefore, after the manager device receives the result message returned by the agent device for the synchronization message, it can determine the business thread corresponding to the result message based on the message ID of the result message and the pre-stored correspondence, and wake up the business thread, and the business thread performs corresponding processing on the result message, thereby realizing the synchronous transmission of the message.
[0173] Moreover, for the multi-threaded concurrent message sending scenario, the method for transmitting synchronous messages provided in the embodiment of the present invention stores the correspondence between the message ID and the business thread. When there are multiple dormant business threads, the business thread corresponding to each result message can be determined based on the message ID of the result message and this correspondence, so as to ensure that the result message returned by the proxy device can be transferred to the correct business thread and ensure the business processing result.
[0174] In one embodiment of the present invention, the corresponding relationship is pre-stored by the manager device during the process of sending the synchronization message.
[0175] In one embodiment of the present invention, the synchronization message carries the manager ID of the manager device that sends the synchronization message, and returns a result message for the synchronization message to the manager device, specifically including:
[0176] A result message for the synchronization message is returned to the manager device indicated by the manager ID.
[0177] In one embodiment of the present invention, the proxy device receives the synchronization message through the message topic it subscribes to. The synchronization message is published by the manager device to the message topic pointing to the proxy device. The message topic carries the proxy ID of the proxy device. The proxy device subscribes to the message topic pointing to itself.
[0178] The above-mentioned return of the result message of the synchronization message to the manager device specifically includes:
[0179] The result message of the synchronization message is returned to the message topic pointing to the manager device, and the topic name of the message topic carries the manager ID of the manager device, so that the manager device receives the result message through the subscribed message topic; the manager device subscribes to the message topic pointing to itself.
[0180] In one embodiment of the present invention, a plurality of second message channels are defined under the message subject directed to the manager device, and a result message for the synchronization message is returned to the message subject directed to the manager device, specifically including:
[0181] The result message for the synchronization message is published to the second message channel defined under the message topic directed to the manager device.
[0182] Continuing with the previous example, the second message channel is specifically the message channel carried by the topic manager / ${manId} / rpc / ${channelId} / sync.
[0183] In one embodiment of the present invention, publishing a result message for the synchronization message to a second message channel defined under a message topic directed to the administrator device specifically includes:
[0184] A modulo operation is performed on the message ID of the result message and the total number of the second message channels, and the result message is published to the second message channel indicated by the modulo operation result.
[0185] Similar to the process of the manager device determining the first message channel, when the proxy device returns a result message, it can determine the corresponding second message channel based on the message ID of the result message and based on ${channelId}=${message_id}%${total_channel_number}.
[0186] Accordingly, the embodiment of the present invention further provides a manager device, see Fig. 9 , the manager device specifically includes:
[0187] The storage module 901 is used to store the correspondence between the message ID of the synchronization message to be sent and the business thread to which the synchronization message belongs;
[0188] The sending module 902 is used to send a synchronization message to the proxy device, and put the service thread corresponding to the synchronization message into a dormant state after sending the synchronization message.
[0189] The manager device provided by the embodiment of the present invention stores the correspondence between the message ID of the synchronization message and the business thread for the synchronization message to be sent during the process of sending the synchronization message, and puts the corresponding business thread into a dormant state after sending the synchronization message, so that the business thread is blocked before sending the next synchronization message, so that the result message of the synchronization message that has been sent can be waited for, thereby ensuring the synchronous transmission of the message. In addition, the embodiment of the present invention stores the correspondence between the message ID and the business thread, which facilitates the subsequent corresponding processing of the synchronization message based on the business thread, and can effectively locate the business thread corresponding to the specific synchronization message in the scenario of multi-thread concurrency.
[0190] In one embodiment of the present invention, the manager device further includes:
[0191] A determination module, configured to determine, upon receiving a result message returned by the proxy device, a service thread corresponding to the result message based on a message ID and a corresponding relationship of the result message; wherein the message ID of the result message is consistent with the message ID of the synchronization message to which the result message is directed;
[0192] The wake-up module is used to wake up the service thread so that the service thread can obtain the result message.
[0193] In one embodiment of the present invention, the synchronization message carries the manager ID of the manager device.
[0194] In one embodiment of the present invention, the manager device further includes:
[0195] The processing module is used to wake up the service thread corresponding to the synchronization message if no result message for the synchronization message is received within a preset time after the synchronization message is sent, so that the service thread performs timeout processing on the synchronization message.
[0196] In one embodiment of the present invention, the manager device and the agent device communicate based on the publish / subscribe mode, and the sending module is specifically used for:
[0197] The synchronization message is published to the message topic pointing to the proxy device. The topic name of the message topic carries the proxy ID of the proxy device, so that the proxy device obtains the synchronization message through the subscribed message topic; the proxy device subscribes to the message topic pointing to itself.
[0198] In one embodiment of the present invention, the manager device specifically receives the result message through the message topic to which it subscribes; the result message is published by the proxy device to the message topic pointing to the manager device, the topic name of the message topic carries the manager ID of the manager device, and the manager device subscribes to the message topic pointing to itself.
[0199] In one embodiment of the present invention, a plurality of first message channels are defined under the message subject directed to the proxy device, and the sending module is specifically used to:
[0200] The synchronization message is published to the first message channel defined under the message topic directed to the proxy device.
[0201] In one embodiment of the present invention, the sending module is specifically used to:
[0202] A modulo operation is performed on the message ID of the synchronization message and the total number of the first message channels, and the synchronization message is published to the first message channel indicated by the modulo operation result.
[0203] Accordingly, the embodiment of the present invention also provides a proxy device, see Fig.10 , the proxy device specifically includes:
[0204] The receiving module 1001 is used to receive the synchronization message sent by the manager device;
[0205] Return module 1002 is used to return the result message for the synchronization message to the manager device, so that the manager device determines and wakes up the business thread corresponding to the result message based on the message ID of the result message and the correspondence between the message ID and the business thread, so that the business thread obtains the result message; the message ID of the result message is consistent with the message ID of the synchronization message targeted by the result message.
[0206] In the proxy device provided by the embodiment of the present invention, the message IDs of the synchronization message and the result message are consistent during the same interaction process. Therefore, after the manager device receives the result message returned by the proxy device for the synchronization message, it can determine the business thread corresponding to the result message based on the message ID of the result message and the pre-stored correspondence, and wake up the business thread, and the business thread performs corresponding processing on the result message, thereby realizing the synchronous transmission of the message.
[0207] In one embodiment of the present invention, the corresponding relationship is pre-stored by the manager device during the process of sending the synchronization message.
[0208] In one embodiment of the present invention, the synchronization message carries the manager ID of the manager device that sends the synchronization message, and the return module 1002 is specifically used to:
[0209] A result message for the synchronization message is returned to the manager device indicated by the manager ID.
[0210] In one embodiment of the present invention, the proxy device receives the synchronization message through the message topic it subscribes to. The synchronization message is published by the manager device to the message topic pointing to the proxy device. The message topic carries the proxy ID of the proxy device. The proxy device subscribes to the message topic pointing to itself.
[0211] Returns the module, specifically used for:
[0212] The result message of the synchronization message is returned to the message topic pointing to the manager device. The topic name of the message topic carries the manager ID of the manager device, so that the manager device receives the result message through the subscribed message topic; the manager device subscribes to the message topic pointing to itself.
[0213] In one embodiment of the present invention, a plurality of second message channels are defined under the message subject directed to the administrator device, and the return module 1002 is specifically used to:
[0214] The result message for the synchronization message is published to the second message channel defined under the message topic directed to the manager device.
[0215] In one embodiment of the present invention, the return module 1002 is specifically configured to:
[0216] A modulo operation is performed on the message ID of the result message and the total number of the second message channels, and the result message is published to the second message channel indicated by the modulo operation result.
[0217] The embodiment of the present invention further provides an electronic device, such as Fig.11 As shown, it includes a processor 1101, a communication interface 1102, a memory 1103 and a communication bus 1104, wherein the processor 1101, the communication interface 1102, and the memory 1103 communicate with each other through the communication bus 1104.
[0218] Memory 1103, used for storing computer programs;
[0219] The processor 1101 is used to implement the following steps when executing the program stored in the memory 1103:
[0220] For the synchronization message to be sent, store the correspondence between the message ID of the synchronization message and the service thread to which the synchronization message belongs;
[0221] Send the synchronization message to the proxy device, and put the service thread corresponding to the synchronization message into the sleep state after sending the synchronization message.
[0222] The communication bus mentioned in the above electronic device may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, only a thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0223] The communication interface is used for communication between the above electronic device and other devices.
[0224] The memory may include a Random Access Memory (RAM), or may also include a Non-Volatile Memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located far from the aforementioned processor.
[0225] The above-mentioned processor 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, discrete hardware components.
[0226] In another embodiment provided by the present invention, there is also provided a computer-readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the steps of any of the above methods for transmitting synchronization messages are implemented.
[0227] In another embodiment provided by the present invention, there is also provided a computer program product containing instructions, which when running on a computer, causes the computer to execute any of the methods for transmitting synchronization messages in the above embodiments.
[0228] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0229] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0230] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the manager device, agent device, electronic device, and computer-readable storage medium embodiments, since they are basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0231] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A method for transmitting a synchronization message, It is characterized in that Applied to a manager device, the method includes: For a synchronization message to be sent, storing a correspondence between a message ID of the synchronization message and a business thread to which the synchronization message belongs; The synchronization message is sent to the proxy device, and after sending the synchronization message, the service thread corresponding to the synchronization message is put into a dormant state.
2. The method according to claim 1, It is characterized in that Also includes: When receiving a result message returned by the proxy device, determining the service thread corresponding to the result message based on the message ID of the result message and the corresponding relationship; wherein the message ID of the result message is consistent with the message ID of the synchronization message targeted by the result message; The service thread is woken up so that the service thread obtains the result message.
3. The method according to claim 1, It is characterized in that The storage of the corresponding relationship is specifically implemented based on a hash mapping between the message ID and the thread ID of the business thread.
4. The method according to claim 1, It is characterized in that The synchronization message carries the manager ID of the manager device.
5. The method according to claim 1, It is characterized in that Also includes: If no result message for the synchronization message is received within a preset time after the synchronization message is sent, the service thread corresponding to the synchronization message is woken up so that the service thread performs timeout processing on the synchronization message.
6. The method according to claim 2, It is characterized in that The manager device communicates with the proxy device based on a publish / subscribe mode, and sending the synchronization message to the proxy device specifically includes: The synchronization message is published to a message topic pointing to the proxy device, the topic name of the message topic carries the proxy ID of the proxy device, so that the proxy device obtains the synchronization message through the subscribed message topic; the proxy device subscribes to the message topic pointing to itself.
7. The method according to claim 6, It is characterized in that The manager device specifically receives the result message through the message topic to which it subscribes; the result message is published by the proxy device to the message topic pointing to the manager device, the topic name of the message topic carries the manager ID of the manager device, and the manager device subscribes to the message topic pointing to itself.
8. The method according to claim 6, It is characterized in that A plurality of first message channels are defined under the message topic directed to the proxy device, and publishing the synchronization message to the message topic directed to the proxy device specifically includes: The synchronization message is published to a first message channel defined under a message topic directed to the proxy device.
9. The method according to claim 8, It is characterized in that The step of publishing the synchronization message to a first message channel defined under a message topic pointing to the proxy device specifically includes: A modulo operation is performed on the message ID of the synchronization message and the total number of the first message channels, and the synchronization message is published to the first message channel indicated by the modulo operation result.
10. A method for transmitting a synchronization message, It is characterized in that Applied to a proxy device, the method comprises: Receive synchronization messages sent by the manager's device; The result message for the synchronization message is returned to the manager device, so that the manager device determines and wakes up the business thread corresponding to the result message based on the message ID of the result message and the correspondence between the message ID and the business thread, so that the business thread obtains the result message; the message ID of the result message is consistent with the message ID of the synchronization message targeted by the result message.
11. The method according to claim 10, It is characterized in that The corresponding relationship is pre-stored by the manager device during the process of sending the synchronization message.
12. The method according to claim 10, It is characterized in that The synchronization message carries the manager ID of the manager device that sends the synchronization message, and returning the result message of the synchronization message to the manager device specifically includes: A result message for the synchronization message is returned to the manager device indicated by the manager ID.
13. The method according to claim 12, It is characterized in that The proxy device receives the synchronization message through the message topic it subscribes to. The synchronization message is published by the manager device to the message topic pointing to the proxy device. The message topic carries the proxy ID of the proxy device. The proxy device subscribes to the message topic pointing to itself. The step of returning a result message of the synchronization message to the manager device specifically includes: The result message for the synchronization message is returned to the message topic pointing to the manager device, and the topic name of the message topic carries the manager ID of the manager device, so that the manager device receives the result message through the subscribed message topic; the manager device subscribes to the message topic pointing to itself.
14. The method according to claim 13, It is characterized in that A plurality of second message channels are defined under the message topic directed to the manager device, and returning the result message of the synchronization message to the message topic directed to the manager device specifically includes: A result message for the synchronization message is published to a second message channel defined under a message topic directed to the manager device.
15. The method according to claim 14, It is characterized in that The step of publishing the result message for the synchronization message to a second message channel defined under a message topic directed to the manager device specifically includes: A modulo operation is performed on the message ID of the result message and the total number of the second message channels, and the result message is published to the second message channel indicated by the modulo operation result.
16. A manager device, It is characterized in that include: A storage module, used for storing, for a synchronization message to be sent, a correspondence between a message ID of the synchronization message and a business thread to which the synchronization message belongs; The sending module is used to send the synchronization message to the proxy device, and put the service thread corresponding to the synchronization message into a dormant state after sending the synchronization message.
17. A proxy device, It is characterized in that include: A receiving module, used for receiving synchronization messages sent by the manager device; A return module is used to return the result message for the synchronization message to the manager device, so that the manager device determines and wakes up the business thread corresponding to the result message based on the message ID of the result message and the correspondence between the message ID and the business thread, so that the business thread obtains the result message; the message ID of the result message is consistent with the message ID of the synchronization message targeted by the result message.
18. An electronic device, It is characterized in that It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1-9 or 10-15 when executing a program stored in a memory.
19. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1-9 or 10-15 are implemented.