A message processing method, device and storage medium
By storing MQTT messages in the second server, rather than the first server, and storing consumption progress in the first server, the problem of easy loss of messages and excessive storage space in the MQTT server is solved, and reliable transmission and efficient storage of messages are achieved.
Patent Information
- Application Number
- CN202011121578.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-19
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2040-10-19
AI Technical Summary
Existing MQTT servers are prone to problems such as messages being easily lost and excessive storage space when subscribing to messages.
After receiving the message subscribed by the client through the first server, the message is sent to the second server for storage, rather than stored locally on the first server. At the same time, the first server stores the consumption progress of the message and decides whether to send a message to the client based on the status and consumption progress of the client.
It effectively avoids message loss, reduces the storage space of the first server, and ensures the reliability of the message and the successful message subscription of the client.
Smart Images

Figure CN114385372B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a message processing method, device and storage medium. Background Art
[0002] Message Queuing Telemetry Transport (MQTT) is a message protocol based on the publish / subscribe paradigm. It is a publish / subscribe messaging protocol designed for remote devices with low hardware performance and environments with poor network conditions.
[0003] In the related art, subscribing to messages through an MQTT server may result in defects such as easy loss of messages and excessive storage space occupation. Therefore, how to overcome the defects in the related art, avoid message loss, and reduce the storage space occupied is a technical problem that needs to be solved. Summary of the invention
[0004] The embodiments of the present application provide a message processing method, device and storage medium, so that in the process of subscribing to a first message through a first server, the first server can overcome the defects of easy loss of messages and excessive storage space occupation, and send the first message to a first client.
[0005] The technical solution of the embodiment of the present application is implemented as follows:
[0006] In a first aspect, an embodiment of the present application provides a message processing method, the method comprising:
[0007] The first server receives a first message subscribed by the first client, the first message being sent by the second client to the first server;
[0008] The first server sends the first message to the second server; the second server is used to store the first message;
[0009] The first server stores a first consumption progress corresponding to the first message;
[0010] The first server sends the first message to the first client based on the state of the first client and / or the first consumption progress.
[0011] In the above scheme, the method further comprises:
[0012] The first server sends the associated data corresponding to the first message to the third server; the third server is used to store the associated data.
[0013] In the above scheme, the method further comprises:
[0014] When the state of the first client changes from an online state to an offline state, the first server sends a first consumption progress corresponding to the first message to a third server; the third server is used to store the first consumption progress.
[0015] In the above solution, the first server sends the first message to the first client based on the state of the first client and / or the first consumption progress, including:
[0016] In the case where the state of the first client is offline, if there is a third client connected to the first server, determining whether the third client is the first client according to the associated data corresponding to the first message stored by the third server;
[0017] When it is determined that the third client is the first client, the first message is obtained from the second server; the first consumption progress is obtained from the third server; and the first message is sent to the first client based on the first consumption progress.
[0018] In the above solution, the first server sends the first message to the first client based on the state of the first client and / or the first consumption progress, including:
[0019] When the status of the first client is online, the first server sends the first message to the first client.
[0020] In the above solution, after the first server sends the first message to the first client, the method further includes:
[0021] The first server deletes the first consumption progress; the first server stores the second consumption progress corresponding to the first message;
[0022] The first server sends the second consumption progress to a third server; the third server is used to store the second consumption progress.
[0023] In the above scheme, the method further comprises:
[0024] The first server sends the consumption progress most recently stored in the first server to the third server based on the first time period.
[0025] In the above solution, when the service quality level of the first message is a first preset level, the first server sends the first message to the first client at least once;
[0026] And / or, when the quality of service level of the first message is a second preset level, the first server sends the first message to the first client only once.
[0027] In a second aspect, an embodiment of the present application provides a message processing device, the device comprising:
[0028] A receiving unit, configured to receive a first message subscribed by a first client, wherein the first message is sent by a second client;
[0029] A storage unit, used to store a first consumption progress corresponding to the first message;
[0030] A sending unit is used to send the first message to a second server; based on the state of the first client and / or the first consumption progress, the first message is sent to the first client; the second server is used to store the first message.
[0031] In the above solution, the sending unit is also used for:
[0032] Sending the associated data corresponding to the first message to a third server; the third server is used to store the associated data;
[0033] And / or, sending the first message to a second server; the second server is used to store the first message.
[0034] In the above solution, the sending unit is also used for:
[0035] When the state of the first client changes from an online state to an offline state, the first server sends a first consumption progress corresponding to the first message to a third server; the third server is used to store the first consumption progress.
[0036] In the above scheme, the device also includes:
[0037] a determining unit, configured to determine, when the state of the first client is offline, whether a third client is connected to the device according to the associated data corresponding to the first message stored in the third server, whether the third client is the first client;
[0038] The sending unit is used to obtain the first message from the second server when it is determined that the third client is the first client; obtain the first consumption progress from the third server; and send the first message to the first client based on the first consumption progress.
[0039] In the above solution, the sending unit is also used for:
[0040] When the status of the first client is online, the first server sends the first message to the first client.
[0041] In the above solution, after the first server sends the first message to the first client, the device further includes:
[0042] A deleting unit, used to delete the first consumption progress;
[0043] The storage unit is further used to store a second consumption progress corresponding to the first message;
[0044] The sending unit is further used for the first server to send the second consumption progress to the third server.
[0045] In the above solution, the sending unit is also used for:
[0046] The first server sends the consumption progress most recently stored in the first server to the third server based on the first time period.
[0047] In the above solution, the sending unit is also used for:
[0048] When the quality of service level of the first message is a first preset level, the first server sends the first message to the first client at least once;
[0049] And / or, when the quality of service level of the first message is a second preset level, the first server sends the first message to the first client only once.
[0050] In the technical solution provided by the embodiment of the present application, after receiving the first message subscribed by the first client, the first server does not store the first message locally, but sends the first message to the second server, which stores the first message. Therefore, the storage space of the first server can be saved, and the message loss can be avoided, thereby ensuring the reliability of the message. Since the first server can store the first consumption progress of the first message locally and then send the first message to the first client, it can be sent based on the progress of the first message and the status of the first client. Therefore, the first message can be successfully sent to the first client, and the message subscription of the first client can be effectively realized. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 It is a schematic diagram of the process of a client subscribing to a message through MQTT in the related technology;
[0052] Figure 2 A schematic diagram of message transmission between a message sender and a message receiver in the related art;
[0053] Figure 3 A schematic diagram of an optional flow chart of a first server side of a message processing method provided in an embodiment of the present application;
[0054] Figure 4 A schematic diagram of an optional flow chart of a third server side of the message processing method provided in an embodiment of the present application;
[0055] Figure 5 A schematic diagram of an optional flow chart of a second server end of a message processing method provided in an embodiment of the present application;
[0056] Figure 6 A schematic diagram of an optional flow chart of a message processing method provided in an embodiment of the present application;
[0057] Figure 7 Another optional flow chart of the message processing method provided in the embodiment of the present application;
[0058] Figure 8 A schematic diagram of an optional structure of a message processing device provided in an embodiment of the present application;
[0059] Fig. 9 An optional structural diagram of RocketMQ provided in an embodiment of the present application;
[0060] Fig.10 Schematic diagram of the optional structure of Redis Sentinel provided in the embodiment of the present application;
[0061] Fig.11 Schematic diagram of an optional structure of the first server provided in the embodiment of the present application
[0062] Fig.12 An optional structural diagram of a third server provided in an embodiment of the present application;
[0063] Fig.13 A schematic diagram of an optional structure of a second server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0064] The present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0065] Before further explaining the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0066] (1)MQTT is a message protocol based on the publish / subscribe paradigm developed by the International Organization for Standardization (ISO) based on the ISO / IEC PRF 20922 standard. It is a publish / subscribe message protocol designed for remote devices with low hardware performance and poor network conditions. The MQTT protocol is lightweight, simple, open and easy to implement. These features make it very widely applicable. It has been widely used in many situations, including restricted environments, such as machine to machine (M2M) communication and the Internet of Things (IoT), such as sensors communicating via satellite links, medical devices that occasionally dial up, smart homes, and some miniaturized devices.
[0067] (2) Redis is an open source, network-enabled, memory-based, and optionally persistent key-value storage database. Redis is the most popular key-value storage database. When data dependencies are no longer required, Redis's memory-based nature makes it very efficient compared to database systems that write every change to disk when executing a transaction. There is no significant difference in write and read operation speeds.
[0068] (3) RocketMQ is a distributed messaging and streaming data platform with low latency, high performance, high reliability, trillion-level capacity and flexible scalability. RocketMQ is a pure Java, distributed, queue-based open source messaging middleware. It is a queue-based messaging middleware developed with reference to the characteristics of Kafka. However, many comparisons have been made between various messaging solutions. It is well known that when the number of topics increases dramatically, the throughput of RocketMQ decreases much less than that of Kafka. Due to its high performance, high reliability and high real-time performance, RocketMQ is increasingly combined with other protocol components in various messaging scenarios such as MQTT.
[0069] (4) The Quality of Service (QoS) of the MQTT message queue represents the service quality of message transmission. The following is a detailed description of each QoS level:
[0070] ①QoS=0 means that the message is distributed at most once. At this level, message loss or duplication may occur. Message publishing depends on the underlying Transmission Control Protocol / Internet Protocol (TCP / IP) network;
[0071] ②QoS=1 means that the message arrives at least once. This level ensures that the message arrives, but the message may be repeated;
[0072] ③QoS=2 means that the message is delivered only once. This level ensures that the message arrives only once.
[0073] Figure 1 A schematic diagram of a process of subscribing to a message in the related art is shown, and the process will be described according to each part.
[0074] Implementing the MQTT protocol requires a client and a server; a publisher, a broker, and a subscriber. Among them, the publisher and subscriber of the message are both clients, the broker can be a server, and the message publisher can be a subscriber at the same time.
[0075] Figure 2 A schematic diagram of message transmission between a message sender and a message receiver in the related art is shown and will be explained.
[0076] Figure 2 The message in can be a message with a service quality greater than zero. The message publisher (Sender) or server sends a PUBLISH package with message data to the server or the message receiver (Receiver), and the message publisher or the server stores the PUBLISH package; after the server or the message receiver receives the PUBLISH package, it sends a PUBACK package to the message publisher or the server. The PUBACK data packet has no message body (Payload), and there is a packet identifier (Packet Identifier) in the variable header (Variable header), which is consistent with the Packet Identifier in the PUBLISH package received by the server or the message receiver; after the message publisher or the server receives the PUBACK package, it finds the PUBLISH package locally stored by the message publisher or the server according to the Packet Identifier in the PUBACK package, and then discards it, thus completing the sending of a message.
[0077] From the above process, we can see that the MQTT proxy server processes messages with a service quality level greater than zero (QoS>0). When sending messages to subscribers, the PUBLISH package needs to be saved locally. When the subscriber receives the PUBLISH package from the MQTT proxy server and returns the PUBACK package to the MQTT proxy server, the MQTT proxy server will remove the saved PUBLISH package. Currently, the open source projects that support MQTT proxy servers (including message queues that support the MQTT protocol) mainly include Mosquitto, EMQ, MqttWk, etc. When these MQTT proxy servers process messages with QoS>0, they save the PUBLISH package in memory or external persistent storage. For example, Mosquitto's MQTT proxy server puts the PUBLISH package in the client's Session in memory. If the client switches nodes or the MQTT proxy server crashes, the Session will disappear, resulting in the loss of message progress. EMQ's PUBLISH package is persisted to the distributed database Mnesia (but it will also be lost if many nodes crash), and the offline message queue is memory-based, that is, if the MQTT proxy server crashes, the message will be lost. MqttWk is an open source Broker for MQTT services based on external storage Redis, which can provide complete QoS services, but the PUBLISH package of each subscribing client needs to be stored separately, which takes up a lot of storage space.
[0078] The existing MQTT proxy server's technical solution for processing messages with QoS>0 has the following disadvantages:
[0079] (1) Messages are easily lost.
[0080] For example, Mosquitto's MQTT proxy server puts the PUBLISH package into the client's Session in memory. If the client switches nodes or the MQTT proxy server crashes, the Session will disappear, resulting in the loss of message progress. EMQ's PUBLISH package is persisted to the distributed database Mnesia (but if the node crashes, the message will be lost), and the offline message queue (only messages with QoS>0 have offline messages) is memory-based, which means that the message is lost after the MQTT proxy server crashes.
[0081] (2) The storage space is too large and the performance is too poor.
[0082] For example, MqttWk is an open source broker for MQTT services based on external storage Redis. It can provide complete QoS services, but the PUBLISH package of each subscribing client needs to be stored separately, which easily causes a large amount of storage space to be occupied.
[0083] (3) When offline subscribers come back online, the existing MQTT proxy server has poor push message performance, and offline messages stored in memory are easily lost.
[0084] For example, Mosquitto uses external storage for offline messages, which will be taken out from Redis and put into memory when the subscriber comes online again, consuming a lot of memory. The more offline subscribers there are, the more memory will be consumed.
[0085] Based on the problems existing in the current method of subscribing to messages through MQTT, the present application proposes a message processing method that can solve the technical difficulties and shortcomings that cannot be solved in the existing technical solutions.
[0086] Figure 3 An optional flow chart of the first server side of the message processing method provided in an embodiment of the present application is shown, and will be explained according to each step.
[0087] Step S101: a first server receives a first message subscribed by a first client.
[0088] In some embodiments, the first message is sent by a second client to the first server.
[0089] In some embodiments, the first server receives a first message subscribed by a first client, including: the first server receives a first message sent by a second client to the first server.
[0090] In some embodiments, the first consumption progress is used to represent the progress of obtaining the first message when the first client subscribing to the first message remains online; the first consumption progress includes: the first client obtains the first message, or the first client does not obtain the first message.
[0091] In some embodiments, the method further includes: the first server sending association data corresponding to the first message to a third server. The association data includes: a correspondence between the first message and an identity identification number (Identity, ID) of a first client subscribing to the first message.
[0092] In some embodiments, the first message includes: a message whose quality of service level is a first preset level; when the quality of service level of the first message is the first preset level, the first server sends the first message to the first client at least once; or, the first message also includes a message whose quality of service level is a second preset level; when the quality of service level of the first message is the second preset level, the first server only sends the first message to the first client once, and the first client only receives the first message once.
[0093] In some embodiments, the level of the quality of service is a first preset level, including: QoS=1; the level of the quality of service is a second preset level, including: QoS=2.
[0094] In some embodiments, the functionality of the first server may be provided by Figure 8 MQTT server implementation in .
[0095] In some embodiments, the function of the third server can be provided by Figure 8 Redis server implementation in .
[0096] Step S102: The first server sends the first message to the second server.
[0097] In some embodiments, the first server sending the first message to the second server includes: the first server sending the first message to the second server, and storing the first message in the second server.
[0098] In this way, the memory usage of the first server can be reduced, and at the same time, the loss of the first message caused by the downtime of the first server can be avoided.
[0099] Step S103: The first server stores a first consumption progress corresponding to the first message.
[0100] In some embodiments, the first server stores the first consumption progress corresponding to the first message, including: during the process of the first server receiving the first message or after the first server receives the first message, the first server stores the first consumption progress corresponding to the first message.
[0101] In some embodiments, the first consumption progress is used to represent the progress of the first client subscribing to the first message. The first consumption progress includes: the first client has not obtained the first message, the first client has obtained the first message, and the first client has obtained part of the first message.
[0102] In some embodiments, the method also includes: when the state of the first client changes from an online state to an offline state, the first server sends a first consumption progress corresponding to the first message to a third server; and / or the first server deletes the first consumption progress; the third server is used to store the first consumption progress.
[0103] In some embodiments, the first client obtains part of the first message, including: when the first client receives part of the message during the process of the first server sending the first message to the first client, the state of the first client changes from an online state to an offline state. Further, the first server stores the first consumption progress to the third server. At this time, the first consumption progress includes: the progress of the first client subscribing to part of the first message.
[0104] In some embodiments, the first client not obtaining the first message includes: the first server obtaining the first message and determining that the first client is a client subscribed to the first message; before the first server sends the first message to the first client, the state of the first client changes from an online state to an offline state. Further, the first server stores the first consumption progress to the third server. At this time, the first consumption progress includes: the first client is not subscribed to the first message.
[0105] In this way, when the state of the first client changes from an online state to an offline state, the first server sends the first consumption progress to the third server and deletes the first consumption progress stored in the first server, thereby releasing the storage space of the first server.
[0106] Step S104: The first server sends the first message to the first client based on the state of the first client and / or the first consumption progress.
[0107] In some embodiments, the first server sends the first message to the first client based on the state of the first client and / or the first consumption progress, including:
[0108] When the status of the first client is online, the first server sends the first message to the first client.
[0109] Alternatively, when the first client is in an offline state, if a third client has established a connection with the first server, determine whether the third client is the first client based on the associated data corresponding to the first message stored on the third server; if it is determined that the third client is the first client, obtain the first message from the second server; obtain the first consumption progress from the third server; and send the first message to the first client based on the first consumption progress.
[0110] In some embodiments, the first server determines whether the third client is the first client based on the associated data corresponding to the first message stored by the third server, including: the first server obtains the associated data corresponding to the first message stored by the third server, and determines whether the third client is the first client based on the ID of the first client subscribing to the first message and the ID of the third client included in the associated data; when the ID of the third client is the same as the ID of the first client, the first server determines that the third client is the first client; when the ID of the third client is different from the ID of the first client, the first server determines that the third client is not the first client.
[0111] In some embodiments, the first server obtains the associated data corresponding to the first message stored by the third server, the first server sends a first request to the third server; the third server receives the first request, and based on the first request, sends the associated data corresponding to the first request to the first server. Alternatively, the first server directly reads the associated data corresponding to the first message from the third server.
[0112] In some embodiments, the method further includes: after the first server sends the first message to the first client, the first server deletes the second consumption progress corresponding to the first message; and / or the first server stores the first consumption progress.
[0113] In some embodiments, the method further includes: the first server sends the second consumption progress to a third server; the third server is used to store the second consumption progress. The second consumption progress includes: the first client has obtained the first message and / or the first client has obtained part of the first message. In some embodiments, when the state of the first client switches from online to offline, the first server sends the first consumption progress corresponding to the first message to the third server.
[0114] In some embodiments, the method further includes: the first server sending the consumption progress most recently stored in the first server to the third server based on a first time period.
[0115] In this way, when the first client is subscribing to the first message, the server crashes. After the first server is restored, the consumption progress corresponding to the first message and the association relationship corresponding to the first message can be obtained from the third server; the first message of the first client can be obtained from the second server to continue to implement the message subscription of the first client.
[0116] In some embodiments, the functionality of the second server may be provided by Figure 8 RocketMQ server implementation in .
[0117] In this way, through the message processing method provided in the embodiment of the present application, it is possible to implement message subscription through the MQTT server; by sending the associated data corresponding to the first message to the third server through the first server, it is possible to implement that when the first client is offline and a third client establishes a connection with the first server, the first server can determine whether the third client established with the first server is the first client based on the associated data, so that when the first client goes offline and then goes online again, the first server can still send the first message to the first client, thereby avoiding the loss of offline messages. At the same time, through the first client provided in the embodiment of the present application, the first client sends the first message to the second server, and the second server stores the first message. When the first client goes online again after being offline, the first server obtains the first message from the second server and sends the first message to the first client, which can not only ensure the performance of the first server in pushing messages, but also avoid excessive storage space occupation.
[0118] Figure 4 An optional flow chart of the third server side of the message processing method provided in an embodiment of the present application is shown, and will be explained according to each step.
[0119] Step S201: The third server receives associated data corresponding to the first message sent by the first server.
[0120] In some embodiments, the first server is a server external to the third server, and is configured to receive a first message sent by a second client, and / or send the first message to a first client that subscribes to the message. The second client may be a message provider.
[0121] In some embodiments, the third server receives association data corresponding to the first message sent by the first server, the association data including: data of a correspondence between the first message and an ID of a first client subscribing to the first message. The association data is used to determine whether the third client is the first client when the first client is offline and the third client establishes a connection with the first server.
[0122] In some embodiments, the method further comprises: the third server storing the associated data.
[0123] In some embodiments, the first message includes: a message whose quality of service level is a first preset level; when the quality of service level of the first message is the first preset level, the first server sends the first message to the first client at least once; or, the first message also includes a message whose quality of service level is a second preset level; when the quality of service level of the first message is the second preset level, the first server only sends the first message to the first client once, and the first client only receives the first message once.
[0124] In some embodiments, the functionality of the first server may be provided by Figure 8 MQTT server implementation in .
[0125] In some embodiments, the function of the third server can be provided by Figure 8 Redis server implementation in .
[0126] Step S202: The third server receives the first request sent by the first server.
[0127] In some embodiments, the third server receives the first request sent by the first server, including: when the first client is offline and the third client establishes a connection with the first server, the third server receives the first request sent by the first server, and the third server sends associated data corresponding to the first message to the first server based on the first request.
[0128] Step S203: the third server receives the second request sent by the first server.
[0129] In some embodiments, the third server receives the second request sent by the first server, including: when the first server determines that the third client is the first client, the third server receives the second request sent by the first server, and sends the first consumption progress stored by the third server to the first server based on the second request.
[0130] In some embodiments, the first consumption progress is used to represent the progress of a first client that subscribes to the first message obtaining the first message when the first client is offline and then online again; the first consumption progress includes: the first client obtains the first message, or the first client does not obtain the first message.
[0131] In some embodiments, the method further includes: after the first server sends the first message to the first client, the third server stores a second consumption progress corresponding to the first message; the second consumption progress includes the client obtaining the first message.
[0132] Step S204: the third server receives the most recently stored consumption progress sent by the first server based on the first time period.
[0133] In some embodiments, the third server receives the most recently stored consumption progress sent by the first server based on the first time period, including: every first time period, the third server receives the most recently stored consumption progress sent by the first server and stores the consumption progress.
[0134] Thus, through the message processing method provided by the embodiment of the present application, the third server sends the associated data corresponding to the first message to the first server based on the first request sent by the first server. Based on the associated data corresponding to the first message, it can be determined whether the third client that comes online after the first client goes offline is the first client; if the third client is the first client, the third server sends the first consumption progress to the first server based on the second request sent by the first server, so that the first server can send the first message to the first client according to the first consumption progress. This avoids the large amount of memory consumed when the first client that uses the externally stored offline message comes online again.
[0135] Figure 5 An optional flow chart of the second server side of the message processing method provided in an embodiment of the present application is shown, and will be explained according to each step.
[0136] Step S301: The second server receives a first message sent by the first server.
[0137] In some embodiments, the second server receiving the first message sent by the first server includes: after the second client sends the first message to the first server, the first server sends the first message to the second server, the second server receives the first message, and stores the first message. The second client may be a message provider.
[0138] In some embodiments, the first message includes: a message whose quality of service level is a first preset level; when the quality of service level of the first message is the first preset level, the first server sends the first message to the first client at least once; or, the first message also includes a message whose quality of service level is a second preset level; when the quality of service level of the first message is the second preset level, the first server only sends the first message to the first client once, and the first client only receives the first message once.
[0139] In some embodiments, the functionality of the first server may be provided by Figure 8 MQTT server implementation in .
[0140] In some embodiments, the functionality of the second server may be provided by Figure 8 RocketMQ server implementation in .
[0141] Step S302: The second server receives a third request sent by the first server.
[0142] In some embodiments, the second server receives the third request sent by the first server, including: when the first client is offline and the third client establishes a connection with the first server, and the first server determines that the third client is the first client, the second server receives the third request sent by the first server, and based on the third request, sends the first message stored by the second server to the first server.
[0143] Figure 6 An optional flow chart of the message processing method provided in an embodiment of the present application is shown and will be explained according to each step.
[0144] Step S401: The third server receives associated data corresponding to the first message sent by the first server.
[0145] In some embodiments, the first server is a server external to the third server, and is configured to receive a first message sent by a second client, and / or send the first message to a first client that subscribes to the message. The second client may be a message provider.
[0146] In some embodiments, the third server receives association data corresponding to the first message sent by the first server, the association data including: data of a correspondence between the first message and an ID of a first client subscribing to the first message. The association data is used to determine whether the third client is the first client when the first client is offline and the third client establishes a connection with the first server.
[0147] In some embodiments, the method further comprises: the third server storing the associated data.
[0148] In some embodiments, the first message includes: a message whose quality of service level is a first preset level; when the quality of service level of the first message is the first preset level, the first server sends the first message to the first client at least once; or, the first message also includes a message whose quality of service level is a second preset level; when the quality of service level of the first message is the second preset level, the first server only sends the first message to the first client once, and the first client only receives the first message once.
[0149] In some embodiments, the functionality of the first server may be provided by Figure 8 MQTT server implementation in .
[0150] In some embodiments, the function of the third server can be provided by Figure 8 Redis server implementation in .
[0151] Step S402: The first server stores a first consumption progress corresponding to the first message.
[0152] In some embodiments, a first server receives a first message sent by a second client to the first server. During or after the first server receives the first message, the first server stores a first consumption progress corresponding to the first message.
[0153] In some embodiments, the first consumption progress is used to represent the progress of obtaining the first message when the first client subscribing to the first message remains online; the first consumption progress includes: the first client obtains the first message, or the first client does not obtain the first message.
[0154] In some embodiments, the first server stores the first consumption progress corresponding to the first message, including: during the process of the first server receiving the first message or after the first server receives the first message, the first server stores the first consumption progress corresponding to the first message.
[0155] In some embodiments, the first consumption progress is used to represent the progress of the first client subscribing to the first message. The first consumption progress includes: the first client has not obtained the first message, the first client has obtained the first message, and the first client has obtained part of the first message.
[0156] In some embodiments, the method also includes: when the state of the first client changes from an online state to an offline state, the first server sends a first consumption progress corresponding to the first message to a third server; and / or the first server deletes the first consumption progress; the third server is used to store the first consumption progress.
[0157] In this way, when the first client is offline, the first server sends the first consumption progress to the third server and deletes the first consumption progress stored in the first server, thereby releasing the storage space of the first server.
[0158] Step S403: The second server receives the first message sent by the first server.
[0159] In some embodiments, the second server receiving the first message sent by the first server includes: after the second client sends the first message to the first server, the first server sends the first message to the second server, the second server receives the first message, and stores the first message. The second client may be a message provider.
[0160] Step S404: the first server determines whether the status of the first client is online.
[0161] In some embodiments, before the first server sends the first message to the first client, the first server determines whether the first client is online; if the first client is online, step S405 is executed; if the first client is offline, step S406 is executed.
[0162] Step S405: The first server sends the first message to the first client.
[0163] In some embodiments, when the first client is online, the first server sends the first message to the first client.
[0164] In some embodiments, after the first server sends the first message to the first client, the method further includes step S408.
[0165] Step S406: The first server determines whether the third client is the first client.
[0166] In some embodiments, when the first client is in an offline state, if a third client has established a connection with the first server, the first server determines whether the third client is the first client.
[0167] In some embodiments, the first server determines whether the third client is the first client, comprising: the first server sends a first request to the third server, the first request being used to request associated data corresponding to the first message stored in the third server. The first server determines whether the third client is the first client based on the associated data corresponding to the first message stored in the third server.
[0168] Step S407: The first server sends a second request to the third server.
[0169] In some embodiments, the second request sent by the first server to the third server includes: when the first server determines that the third client is the first server, the first server sends the second request to the third server, and the third server sends the first consumption progress stored by the third server to the first server based on the second request.
[0170] In some embodiments, after the first server sends the second request to the third server, the method further includes step S405.
[0171] In some embodiments, after the first server sends the first message to the first client, the method further includes step S408.
[0172] Step S408: The first server updates the stored first consumption progress.
[0173] In some embodiments, the first server updates the stored first consumption progress, including: after the first server sends the first message to the first client, the first server stores the second consumption progress corresponding to the first message; and / or the first server deletes the first consumption progress.
[0174] In some embodiments, the method further includes: when the state of the first client is switched from an online state to an offline state, the first server sends a second consumption progress corresponding to the first message to the third server.
[0175] In some embodiments, the second consumption progress is used to represent the progress of a first client that subscribes to the first message obtaining the first message when the first client is offline and then online again; the second consumption progress includes: the first client obtaining the first message, or the first client not obtaining the first message.
[0176] Step S409: The first server sends the consumption progress most recently stored in the first server to the third server based on the first time period.
[0177] In some embodiments, the first server sends the most recently stored consumption progress in the first server to the third server based on a first time period; the third server receives the most recently stored consumption progress sent by the first server every first time period and stores the consumption progress.
[0178] In this way, through the message processing method provided in the embodiment of the present application, it is possible to implement subscription messages through MQTT; through the embodiment of the present application, the first server sends the associated data corresponding to the first message to the third server, so that when the first client is offline and other clients establish a connection with the first server, the first server can judge whether the other clients established with the first server are the first client based on the associated relationship, so that when the first client goes online again after being offline, the first server can still send the subscription message to the first client, avoiding the loss of offline messages. At the same time, through the first client provided in the embodiment of the present application, the first client sends the first message to the second server, and the second server stores the first message. When the first client goes online again after being offline, the first server obtains the first message from the second server and sends the first message to the first client, which can not only ensure the performance of the first server in pushing messages, but also avoid excessive storage space occupation.
[0179] Figure 7 Another optional flow chart of the message processing method provided in the embodiment of the present application is shown and will be explained according to each step.
[0180] Step S501: The second client sends a message with QoS>0 to the MQTT server.
[0181] In some embodiments, the second client sends a first message with a quality of service level greater than zero to the MQTT server.
[0182] Step S502: The MQTT server sends the first message to the Broker of RocketMQ.
[0183] In some embodiments, after the MQTT receives the first message provided by the message provider, the MQTT server sends the first message to the Broker of RocketMQ.
[0184] Step S503: The MQTT sends the first message to a first client that is online.
[0185] In some embodiments, the MQTT sends the first message to a first client in an online state; the method further includes: the MQTT storing a first consumption progress corresponding to the first message.
[0186] Step S504: determine whether the first client is online.
[0187] In some embodiments, when the first client is online, step S505 is executed; when the first client is offline, step S506 is executed.
[0188] Step S505: The MQTT server sends the first message to the first client.
[0189] In some embodiments, when the first client is online, the MQTT server sends the first message to the first client.
[0190] In some embodiments, after the MQTT server sends the first message to the first client, step S508 is executed.
[0191] Step S506, when the first client is offline and the third client establishes a connection with the MQTT server, the MQTT server obtains the first consumption progress from Redis and updates the consumption progress in the local memory.
[0192] In some embodiments, when a third client establishes a connection with the first server, the MQTT server obtains associated data corresponding to the first message from the Redis server, and saves the associated data in the Session of the third client.
[0193] The MQTT server searches the Session of the third client to see whether a persistent third client with QoS=1 or QoS=2 has subscribed to the topic of the first message. If the third client has subscribed to the topic of the first message, the MQTT server sends the first message to the third client.
[0194] Step S507: The MQTT server pulls the first message from the Broker.
[0195] In some embodiments, the MQTT server searches for the first consumption progress from the Redis server and updates it to the local memory, and then pulls the offline message from the RocketMQ Broker according to the queried first consumption progress and sends it to the subscriber.
[0196] In some embodiments, the method further includes step S505.
[0197] Step S508: MQTT updates the first consumption progress in the memory.
[0198] In some embodiments, the consumption progress is updated in the local memory to facilitate subsequent consumers to know where to start pulling messages.
[0199] Step S509: When the third client is offline, the consumption progress stored in the Redis server is updated.
[0200] In some embodiments, when the third client disconnects, MQTT updates the consumption progress in memory to Redis.
[0201] In some embodiments, in addition to the main process of steps S501 to S509 described above, the embodiments of the present application also include a scheduled task in addition to updating the consumption progress stored in the Redis cluster when the client is disconnected.
[0202] Step S510: The MQTT server periodically updates the consumption progress of the first client to the Redis cluster.
[0203] Avoid the loss of message consumption progress in local memory due to MQTT server crash.
[0204] Figure 8 A schematic diagram of an optional structure of a message processing device provided in an embodiment of the present application is shown.
[0205] In some embodiments, the device includes: a Redis cluster, an MQTT server, and RocketMQ.
[0206] The Redis cluster is used to persist message consumption progress and subscription relationships; the Broker in the RocketMQ cluster is used to store messages with QoS>0, i.e., PUBLISH packets. When the MQTT server needs these messages, it pulls messages with QoS>0 from the Broker of RocketMQ.
[0207] Fig. 9 A schematic diagram of an optional structure of RocketMQ provided in an embodiment of the present application is shown.
[0208] Fig. 9In RocketMQ, a storage method that separates data from indexes is adopted. This effectively reduces the loss of file resources and memory resources. Even with massive data and high concurrency scenarios, the end-to-end delay can be effectively reduced, and it has strong horizontal expansion capabilities. From the efficiency point of view of several common storage methods, directly operating the file system is definitely the fastest, so the file system>kv storage>relational database, and RocketMQ message storage is file storage. When the MQTT server needs these messages, it sends an RPC request to pull messages to the Broker of RocketMQ. Messages can be pulled in batches. After the messages are pulled, the start offset of the next message to be pulled from the queue is recorded.
[0209] In the embodiment of the present application, the offset is stored in Redis. The Broker that stores the message in RocketMQ itself has high availability. In order to make the Redis that stores the offset of the message consumption progress also highly available, the embodiment of the present application adopts the Redis sentinel mode high-availability cluster.
[0210] Fig.10 A schematic diagram of an optional structure of Redis Sentinel provided in an embodiment of the present application is shown.
[0211] Fig.10 In , Sentinel is a tool for managing multiple Redis instances. It can achieve high availability for the following operations of Redis, including:
[0212] Monitoring: Sentinel will constantly check whether the master server and slave server are running normally
[0213] Notification: When a problem occurs on a monitored Redis server, Sentinel sends a notification to the administrator or other applications through the API script.
[0214] Automatic failover: When the master node fails to work properly, Sentinel will start an automatic failover operation. It will upgrade one of the slave nodes in the master-slave relationship with the failed master node to the new master node, and point the other slave nodes to the new master node.
[0215] Fig.11 An optional structural diagram of a first server included in the message processing device provided in an embodiment of the present application is shown, and will be explained according to each part.
[0216] The first server 600 includes: a receiving unit 601 , a storage unit 602 and a sending unit 603 .
[0217] The receiving unit 601 is configured to receive a first message subscribed by a first client, where the first message is sent by a second client;
[0218] The storage unit 602 is used to store the first consumption progress corresponding to the first message;
[0219] The sending unit 603 is configured to send the first message to the first client based on the state of the first client and / or the first consumption progress.
[0220] The sending unit 603 is further used to send the associated data corresponding to the first message to a third server; the third server is used to store the associated data; and / or send the first message to a second server; the second server is used to store the first message.
[0221] The sending unit 603 is further configured to cause the first server to send the first consumption progress corresponding to the first message to a third server when the state of the first client changes from an online state to an offline state; and the third server is configured to store the first consumption progress.
[0222] In some embodiments, the first server 600 further includes: a determination unit 604 .
[0223] The determining unit 604 is configured to determine whether the third client is the first client according to the associated data corresponding to the first message stored in the third server if a third client has established a connection with the device when the first client is in an offline state;
[0224] The sending unit 603 is used to obtain the first message from the second server when it is determined that the third client is the first client; obtain the first consumption progress from the third server; and send the first message to the first client based on the first consumption progress.
[0225] The sending unit 603 is further configured to, when the first client is in an online state, cause the first server to send the first message to the first client.
[0226] In some embodiments, after the first server sends the first message to the first client, the storage unit 602 is further used to store the second consumption progress corresponding to the first message;
[0227] In some embodiments, the first server 600 further includes: a deleting unit 605 .
[0228] The deleting unit 605 is used to delete the first consumption progress;
[0229] The sending unit 603 is further configured to enable the first server to send the second consumption progress to a third server.
[0230] The sending unit 603 is further configured to enable the first server to send the consumption progress most recently stored in the first server to the third server based on the first time period.
[0231] The sending unit 603 is also used for, when the service quality level of the first message is a first preset level, the first server sending the first message to the first client at least once; and / or, when the service quality level of the first message is a second preset level, the first server sending the first message to the first client only once.
[0232] In some embodiments, the first message includes: a message whose quality of service level is a first preset level; when the quality of service level of the first message is the first preset level, the first server sends the first message to the first client at least once; or, the first message also includes a message whose quality of service level is a second preset level; when the quality of service level of the first message is the second preset level, the first server only sends the first message to the first client once, and the first client only receives the first message once.
[0233] Fig.12 An optional structural diagram of a third server included in the message processing device provided in an embodiment of the present application is shown, and will be explained according to each part.
[0234] In some embodiments, the third server 700 includes: a receiving unit 701 and a storage unit 702 .
[0235] In some embodiments, the function of the third server can be provided by Figure 8 Redis server implementation in .
[0236] The receiving unit 701 is used to receive the associated data corresponding to the first message sent by the first server;
[0237] The storage unit 702 is used to store the associated data.
[0238] The receiving unit 701 is further configured to receive a first request sent by the first server;
[0239] The third server 700 further includes a sending unit 703, configured to send associated data corresponding to the first message to the first server based on the first request.
[0240] The receiving unit 701 is further configured to receive the first consumption progress sent by the first server when the first client is offline;
[0241] The storage unit 702 is further configured to store the first consumption progress.
[0242] The receiving unit 701 is further configured to receive a second request sent by the first server;
[0243] The sending unit 703 is further configured to send the first consumption progress stored in the third server to the first server based on the second request.
[0244] The receiving unit 701 is further configured to receive a second consumption progress corresponding to the first message sent by the first server when the state of the first client is switched from an online state to an offline state;
[0245] The storage unit 702 is further configured to store the second consumption progress.
[0246] The receiving unit 701 is further configured to receive the most recently stored consumption progress sent by the first server based on a first time period;
[0247] The storage unit 702 is also used to store the consumption progress.
[0248] Fig.13 An optional structural diagram of a second server included in the message processing device provided in an embodiment of the present application is shown, and will be explained according to each part.
[0249] In some embodiments, the second server 800 includes: a receiving unit 801 and a storage unit 802 .
[0250] In some embodiments, the functionality of the second server may be provided by Figure 8 RocketMQ server implementation in .
[0251] The receiving unit 801 is used to receive a first message sent by the first server;
[0252] The storage unit 802 is used to store the first message.
[0253] The receiving unit 801 is further configured to receive a third request sent by the first server when the state of the first client is switched from online to offline;
[0254] The storage unit 802 is further configured to send the first message stored by the second server to the first server based on the third request.
[0255] A person of ordinary skill in the art can understand that all or part of the steps of the above method embodiment can be completed by hardware related to program commands, and the aforementioned program can be stored in a storage medium. When the program is executed, when a notification message based on a second application is received during the operation of the first application, the program responds to the notification message in a first area on the screen of the electronic device; wherein the first area is smaller than the area corresponding to the input method application loaded when the second application is run alone on the screen of the electronic device. The aforementioned storage medium includes various media that can store program codes, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks or optical disks.
[0256] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several commands to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
[0257] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A message processing method, characterized in that: The method comprises: The first server receives a first message subscribed by the first client, the first message being sent by the second client to the first server; The first server sends the first message to the second server; the second server is used to store the first message; the first server does not store the first message locally; The first server stores a first consumption progress corresponding to the first message; The first server sends the first message to the first client based on the state of the first client and / or the first consumption progress; The method further comprises: The first server sends the consumption progress most recently stored in the first server to the third server based on the first time period.
2. The method according to claim 1, characterized in that The method further comprises: The first server sends the associated data corresponding to the first message to the third server; the third server is used to store the associated data.
3. The method according to claim 2, characterized in that The method further comprises: When the state of the first client changes from an online state to an offline state, the first server sends a first consumption progress corresponding to the first message to a third server; the third server is used to store the first consumption progress.
4. The method according to claim 3, characterized in that The first server sends the first message to the first client based on the state of the first client and / or the first consumption progress, including: In the case where the state of the first client is offline, if there is a third client connected to the first server, determining whether the third client is the first client according to the associated data corresponding to the first message stored by the third server; When it is determined that the third client is the first client, obtaining the first message from the second server; and obtaining the first consumption progress from the third server; Based on the first consumption progress, the first message is sent to the first client.
5. The method according to claim 1, characterized in that The first server sends the first message to the first client based on the state of the first client and / or the first consumption progress, including: When the status of the first client is online, the first server sends the first message to the first client.
6. The method according to claim 1, characterized in that After the first server sends the first message to the first client, the method further includes: The first server deletes the first consumption progress; The first server stores a second consumption progress corresponding to the first message; The first server sends the second consumption progress to a third server; the third server is used to store the second consumption progress.
7. The method according to claim 1, characterized in that When the quality of service level of the first message is a first preset level, the first server sends the first message to the first client at least once; And / or, when the quality of service level of the first message is a second preset level, the first server sends the first message to the first client only once.
8. A message processing device, applied to a first server, characterized in that: The device comprises: A receiving unit, configured to receive a first message subscribed by a first client, wherein the first message is sent by a second client; wherein the first message is not stored locally on the first server; A storage unit, used to store a first consumption progress corresponding to the first message; a sending unit, configured to send the first message to a second server; configured to send the first message to the first client based on the state of the first client and / or the first consumption progress; the second server is configured to store the first message; The sending unit is further configured to enable the first server to send the consumption progress most recently stored in the first server to a third server based on a first time period.
9. A storage medium storing an executable program, characterized in that: When the executable program is executed by a processor, the message processing method according to any one of claims 1 to 7 is implemented.
10. A message processing device, comprising a memory, a processor, and an executable program stored in the memory and capable of being run by the processor, characterized in that: When the processor runs the executable program, the steps of the message processing method according to any one of claims 1 to 7 are performed.
Citation Information
Patent Citations
Message pushing method, device and system
CN105634932A
Method and system for establishing ad-hoc session in push-to-talk over cellular network
US20060230168A1