MQTT offline message caching method and device and medium

By extending the MQTT plug-in, combining dynamic caching strategies and flexible authentication mechanisms, the resource waste and authentication flexibility of the MQTT protocol in offline message processing is solved, and efficient offline message management and cross-domain applicability are achieved.

CN120378394APending Publication Date: 2025-07-25XIAMEN STAR SMART TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510484388.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-17
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

The existing MQTT protocol lacks flexible caching strategies in offline message processing, and cannot configure cache Topic and TTL on demand, resulting in waste of resources and poor authentication flexibility, making it difficult to adapt to enterprise-level databases or dynamic authentication requirements.

Method used

By extending the MQTT plug-in, integrating the Internet of Things server, publishing end and subscription end, determining whether to cache based on the subscription Topic and TTL values in the ACL, creating or updating the message task queue, and client authentication and online status management are carried out through the plug-in to realize offline cache and dynamic message processing.

Benefits of technology

It realizes efficient offline message management, dynamic and flexible caching strategies, avoid resource waste, supports cross-domain applicability, and is suitable for medical monitoring, industrial automation and Internet of Vehicles and other fields.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120378394A_ABST
    Figure CN120378394A_ABST
Patent Text Reader

Abstract

The invention discloses an MQTT offline message caching method and device and a medium, and relates to the technical field of MQTT communication. The method comprises the following steps: integrating an MQTT plug-in, wherein the MQTT plug-in is respectively connected with an Internet of Things server, a publishing end and a subscription end; when the MQTT plug-in receives client authentication information sent by the Internet of Things server, whether caching is carried out or not is judged according to subscription Topic in the ACL and a corresponding TTL value, and a message task queue is created or updated when caching is needed; a client is authenticated and the online state of the client is updated through an MQTT plug-in, when the MQTT plug-in receives information that a publishing end publishes a message to a Topic, a subscription Topic matched with the published message Topic in the authentication information of the client is searched, the message is sent or offline caching is carried out according to the state of the client, and then the cached message is sent after the client is online. According to the MQTT offline message caching method, the MQTT offline message caching device and the medium provided by the invention, efficient offline message management is realized by expanding the MQTT plug-in.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of MQTT communication, and particularly relates to an MQTT offline message caching method, device, and medium. Background Art

[0002] Currently, the MQTT protocol is widely adopted as a lightweight communication standard in the IoT field, and its publish / subscribe mode is suitable for low-bandwidth and high-latency scenarios. However, the existing technologies have the following limitations:

[0003] (1) Insufficient offline message processing: The standard MQTT Broker only relies on the Persistent Session and QoS (Quality of Service) mechanisms to cache offline messages, but lacks a flexible caching strategy and cannot configure the caching Topic and TTL as needed.

[0004] (2) Some methods, such as message cache expiration monitoring, do not perform offline judgment on the receiver (subscription end), store a large number of messages, and waste storage resources.

[0005] In addition, the existing technologies may also have other limitations, such as:

[0006] (3) Poor authentication and storage flexibility: The authentication information and ACL management of most open-source MQTT Brokers (such as Mosquitto) rely on static file storage, making it difficult to adapt to enterprise-level database or dynamic authentication requirements. Summary of the Invention

[0007] The technical problem to be solved by the present invention is to provide an MQTT offline message caching method, device, and medium, which achieve efficient offline message management by extending the MQTT plugin.

[0008] In the first aspect, the present invention provides an MQTT offline message caching method, including:

[0009] Integrate an MQTT plugin, which is respectively connected to the IoT server, the publisher, and the subscriber; when the MQTT plugin receives the client authentication information sent by the IoT server, determine whether to cache according to the subscribed Topic and the corresponding TTL value in the ACL, and create or update the message task queue when caching is required; authenticate the client through the MQTT plugin and update the client online status. When the MQTT plugin receives the information that the publisher publishes a message to the Topic, find the subscribed Topic that matches this published message Topic in the client authentication information, send the message according to the client status or perform offline caching through the message task queue, and then send the cached message after the client goes online.

[0010] Further, the method specifically includes:

[0011] Plugin extension stage: Extend an MQTT plugin, which is respectively connected to the Internet of Things server, the publisher, and the subscriber, and is used to handle device connection, subscription, and message publishing, and send data to the data storage module for saving;

[0012] Registration and authentication stage: When the MQTT plugin receives the client authentication information sent by the Internet of Things server, it judges whether the TTL of the subscribed Topic in the ACL of the client authentication information is 0. If it is not 0, it creates or updates the message task queue according to the client ID and Topic and updates the data in the data storage module;

[0013] Message subscription stage: When the MQTT plugin receives the basic authentication callback event notification of the subscriber connection, it authenticates the client. After the authentication passes, it updates the client status to online; when the MQTT plugin receives the information of the subscriber subscribing to the Topic, after passing the verification, it updates the subscribed Topic information and publishes the subscription event notification; when the MQTT plugin receives the offline callback event notification of the subscriber, it updates the client status to offline;

[0014] Message publishing stage: When the MQTT plugin receives the basic authentication callback event notification of the publisher connection, it authenticates the client. After the authentication passes, it updates the client online status cache; when the MQTT plugin receives the information that the publisher publishes a message to the Topic, it searches for the subscribed Topic that matches this published message Topic in the client authentication information, and sends the message according to the client status or performs offline caching through the message task queue;

[0015] Offline cached message processing stage: When the message task queue receives the subscription event notification, it starts to process the offline cached message task. Each client ID + subscribed Topic forms a message task queue. The message task queue waits when the subscriber is offline and starts the processing process after the subscriber goes online. Expired messages are discarded, and unexpired messages are published.

[0016] Furthermore, when the MQTT plugin receives the updated client authentication information sent by the Internet of Things server, it updates the client authentication information in the data storage module according to the client ID; when the MQTT plugin authenticates the client, it obtains the latest client authentication information from the data storage module for verification.

[0017] Furthermore, the method further includes: setting priorities according to the Topic or the client ID + subscribed Topic; when publishing the unexpired messages in the message task queue, sending messages according to the set priorities.

[0018] Second aspect, the present invention provides an MQTT offline message caching device, including:

[0019] An integrated plugin module for integrating an MQTT plugin, which is respectively connected to an Internet of Things server, a publishing end, and a subscribing end; when the MQTT plugin receives the client authentication information sent by the Internet of Things server, it determines whether to cache according to the subscribed Topic and the corresponding TTL value in the ACL, and creates or updates a message task queue when caching is required; authenticates the client through the MQTT plugin and updates the client online status. When the MQTT plugin receives the information that the publishing end publishes a message to a Topic, it searches for the subscribed Topic that matches this published message Topic in the client authentication information, sends the message according to the client status or performs offline caching through the message task queue, and then sends the cached message after the client goes online.

[0020] Further, the integrated plugin module specifically includes:

[0021] A plugin extension module for extending an MQTT plugin, which is respectively connected to an Internet of Things server, a publishing end, and a subscribing end, and is used to handle device connection, subscription, and message publishing, and send the data to the data storage module for storage;

[0022] A registration authentication module for determining whether the TTL of the subscribed Topic in the ACL of the client authentication information is 0 when the MQTT plugin receives the client authentication information sent by the Internet of Things server. If it is not 0, it creates or updates a message task queue according to the client ID and Topic and updates the data in the data storage module;

[0023] A message subscription module for authenticating the client when the MQTT plugin receives the basic authentication callback event notification of the subscribing end connection, and updating the client status to online after successful authentication; when the MQTT plugin receives the information that the subscribing end subscribes to a Topic, it updates the subscribed Topic information and publishes a subscription event notification after passing the verification; when the MQTT plugin receives the offline callback event notification of the subscribing end, it updates the client status to offline;

[0024] A message publishing module for authenticating the client when the MQTT plugin receives the basic authentication callback event notification of the publishing end connection, and updating the client online status cache after successful authentication; when the MQTT plugin receives the information that the publishing end publishes a message to a Topic, it searches for the subscribed Topic that matches this published message Topic in the client authentication information, and sends the message according to the client status or performs offline caching through the message task queue;

[0025] The offline cache message processing module is used to start processing the offline cache message task when the message task queue receives the subscription event notification. Each client ID + subscription Topic forms a message task queue. The message task queue waits when the subscription end is offline and starts the processing flow after the subscription end goes online. Expired messages are discarded, and unexpired messages are published.

[0026] Further, in the registration and authentication module, when the MQTT plugin receives the updated client authentication information sent by the IoT server, it updates the client authentication information in the data storage module according to the client ID; in the registration and authentication module and the message publishing module, when the MQTT plugin authenticates the client, it obtains the latest client authentication information from the data storage module for verification.

[0027] Further, in the registration and authentication module, the priority is set according to the Topic or client ID + subscription Topic; in the offline cache message processing module, when publishing the unexpired messages in the message task queue, the messages are sent according to the set priority.

[0028] In a third aspect, the present invention provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the method described in the first aspect.

[0029] The technical solutions provided in the embodiments of the present invention have at least the following technical effects:

[0030] (1) Dynamic and flexible caching strategy: Through TTL configuration, precise offline message lifecycle management is achieved, with the client and Topic as the smallest granularity, avoiding resource waste caused by message accumulation in traditional solutions.

[0031] (2) Cross-domain applicability: The solution of the present invention can be applied to the medical monitoring field and can also be extended to fields such as industrial automation (such as PLC instruction caching) and vehicle networking (V2X communication). Only by adjusting the TTL and Topic configurations can different scenario requirements be adapted.

[0032] The above description is only an overview of the technical solutions of the present invention. In order to be able to understand the technical means of the present invention more clearly, it can be implemented according to the content of the description. And in order to make the above and other purposes, features and advantages of the present invention more obvious and understandable, the following specific embodiments of the present invention are specifically given. Description of the Drawings

[0033] The present invention will be further described below with reference to the drawings in conjunction with the embodiments.

[0034] Figure 1 It is a framework schematic diagram of the system of the present invention;

[0035] Figure 2 Schematic flowchart of the method in Embodiment 1 of the present invention;

[0036] Figure 3 Schematic flowchart of the authentication information registration and storage process in Embodiment 1 of the present invention;

[0037] Figure 4 Schematic flowchart of the online / offline status and subscribed Topic process of the subscriber end in Embodiment 1 of the present invention;

[0038] Figure 5 Schematic flowchart of the online / offline status and message publishing process of the publisher end in Embodiment 1 of the present invention;

[0039] Figure 6 Schematic flowchart of the offline cached message processing process in Embodiment 1 of the present invention;

[0040] Figure 7 Schematic structural diagram of the device in Embodiment 2 of the present invention. Detailed implementation manners

[0041] Embodiments of the present invention provide an MQTT offline message caching method, device and medium, which realize efficient offline message management by extending the MQTT plugin and combining a dynamic caching strategy with a flexible authentication mechanism.

[0042] The technical solutions in the embodiments of the present invention are generally as follows:

[0043] Integrate an MQTT plugin, which is respectively connected to the Internet of Things server, the publisher end and the subscriber end; when the MQTT plugin receives the client authentication information sent by the Internet of Things server, it judges whether to cache according to the subscribed Topic and the corresponding TTL value in the ACL, and creates or updates the message task queue when caching is required; authenticate the client through the MQTT plugin and update the client online status. When the MQTT plugin receives the information that the publisher end publishes a message to the Topic, it searches for the subscribed Topic that matches this published message Topic in the client authentication information, and sends the message according to the client status or performs offline caching through the message task queue, and then sends the cached message after the client goes online.

[0044] Before introducing the specific embodiments, first introduce the system framework corresponding to the method of the embodiments of the present invention, as Figure 1 shown, the system is roughly divided into five parts:

[0045] (1) Internet of Things server (business side)

[0046] Responsible for registering and distributing client authentication information through the HTTP interface, interacting with the MQTT Broker, and managing the connections and permissions of devices.

[0047] (2) MQTT Broker (Integrated Plugin)

[0048] The core message transfer module is responsible for handling device connections, subscriptions, and message publications. In this invention, Mosquitto is used as the Broker.

[0049] The plugin supports saving client authentication information to a database or cache, completing client authentication and offline message caching. This is the main implementation part of the invention.

[0050] (3) Data Storage

[0051] It is used to store client authentication information and connection status. It supports multiple data sources (such as MySQL, Redis), can include both cache and database at the same time, and using cache can improve efficiency.

[0052] (4) Publisher, taking the Internet of Things terminal device as an example for illustration

[0053] After obtaining the authentication information through the HTTP interface, it connects to the Broker using the MQTT protocol. Publishes messages to the specified Topic.

[0054] (5) Subscriber, taking the mobile phone App as an example for illustration

[0055] Connects to the Broker through the MQTT protocol, subscribes to relevant Topics. Receives and displays messages from the terminal device.

[0056] To facilitate understanding of the solution of this invention, the relevant background technology is described as follows:

[0057] IoT (Internet of Things): A network that interconnects physical devices (such as sensors, household appliances, vehicles, etc.) through the Internet, enabling data collection, transmission, and automated control between devices.

[0058] MQTT (Message Queuing Telemetry Transport): A lightweight publish / subscribe mode messaging protocol, designed specifically for the Internet of Things environment with high latency and low bandwidth.

[0059] MQTT Broker (MQTT Intermediary / Agent): The core component of the MQTT system, responsible for receiving messages, managing subscription relationships, and routing messages to subscribers.

[0060] ACL (Access Control List): Defines the read / write permission rules for clients to MQTT topics (Topics), preventing unauthorized operations.

[0061] Topic: The classification identifier of messages in MQTT, adopting a hierarchical structure (separated by / ), used for routing messages.

[0062] MQTT Client: The terminal that communicates with the Broker using the MQTT protocol, including the Publisher and the Subscriber.

[0063] TTL (Time to Live): Represents the maximum time (or number of hops) that data, messages, or network packets are allowed to exist or be transmitted in the system. They will automatically become invalid or be discarded after timeout.

[0064] HTTP (HyperText Transfer Protocol): An application layer protocol based on the request-response model, used for communication between Web browsers and servers.

[0065] Embodiment 1

[0066] This embodiment provides an MQTT offline message caching method, as Figure 2 shown, including:

[0067] Plugin extension stage: Extend an MQTT plugin. The MQTT plugin is respectively connected to the Internet of Things server, the publishing end, and the subscribing end, used to handle device connection, subscription, and message publishing, and send data to the data storage module for storage;

[0068] Registration and authentication stage: When the MQTT plugin receives the client authentication information sent by the Internet of Things server, judge whether the TTL of the subscribed Topic in the ACL of the client authentication information is 0. If it is not 0, create or update the message task queue according to the client ID and Topic and update the data in the data storage module;

[0069] Message subscription stage: When the MQTT plugin receives the basic authentication callback event notification of the subscribing end connection, authenticate the client. After successful authentication, update the client status to online; when the MQTT plugin receives the information of the subscribing end subscribing to the Topic, after passing the verification, update the subscribed Topic information and publish the subscription event notification; when the MQTT plugin receives the offline callback event notification of the subscribing end, update the client status to offline;

[0070] Message Publishing Phase: When the MQTT plugin receives the notification of the basic authentication callback event for the connection of the publishing end, it authenticates the client. After successful authentication, it updates the online status cache of the client. When the MQTT plugin receives the information that the publishing end publishes a message to a Topic, it searches for the subscribed Topic in the client authentication information that matches this published message Topic, and sends the message according to the client status or caches it offline through the message task queue.

[0071] Offline Cached Message Processing Phase: When the message task queue receives the subscription event notification, it starts to process the offline cached message task. Each client ID + subscribed Topic forms a message task queue. The message task queue waits when the subscribing end is offline and starts the processing flow after the subscribing end goes online. Expired messages are discarded, and unexpired messages are published.

[0072] In a preferred implementation, when the MQTT plugin receives the updated client authentication information sent by the Internet of Things server, it updates the client authentication information in the data storage module according to the client ID. When the MQTT plugin authenticates the client, it obtains the latest client authentication information from the data storage module for verification. The system is more robust, supports dynamic update of the TTL policy, and does not require reloading.

[0073] In a preferred implementation, the method further includes: setting priorities according to the Topic or client ID + subscribed Topic; when publishing unexpired messages in the message task queue, sending messages according to the set priorities.

[0074] In an embodiment applied to the field of medical monitoring, as Figures 3 to 6 shown, the implementation process is as follows:

[0075] The first part is the registration and storage of authentication information, and the steps are as follows:

[0076] (1) The Internet of Things server sends an HTTP request to register the client authentication information to the HTTP interface implemented by the plugin.

[0077] Example of the HTTP request Payload (payload) of the authentication information, where the rw field in the acls field represents the permission of this Topic, and RW_SUBSCRIBE represents the subscription permission: {

[0078]

[0079] (2) If the TTL set for the subscribed Topic in the authentication information ACL is not 0, it means that the offline messages of this Topic need to be cached. At this time, a priority task queue for offline messages is synchronously created (or updated), and the data in the database and cache is updated. The process is asFigure 3 as shown

[0080] (3) Support dynamic real-time update of authenticated information for registration, and important information such as TTL, expiration time, and password can be updated. After the update, there is no need to reload, and it takes effect immediately. The system is more robust and supports dynamic update of the TTL policy without reloading.

[0081] The second part is the subscription client online / offline and subscription phase, and the steps are as follows:

[0082] (1) After the subscription client connects to the MQTT Broker through the client authentication information assigned by the Internet of Things server, the plugin receives a notification of the basic authentication callback event for the connection, and determines whether the authentication information used for the connection matches the stored username and password. If they do not match, the connection is refused; if they match, the connection is successful and the client online status cache is updated.

[0083] (2) When the basic authentication passes, the subscription client subscribes to the Topic. The plugin receives a notification of the publish / subscribe authentication callback event, that is, the ACL check. If the permission check fails, the connection is refused. When the check passes, the subscribed Topic cache information (including the Topic name and the list of subscribed clients) is updated. After the cache is updated, a publish / subscribe event notification is sent. After the message task queue inside the plugin asynchronously receives this notification, it starts to process the offline cache message task.

[0084] (3) After the plugin receives the notification of the offline callback event of the subscription client, it immediately updates the client online status and the subscribed Topic cache, and its process is as Figure 4 as shown

[0085] The third part is the publish client online / offline and publish message phase, and the steps are as follows:

[0086] (1) After the publish client connects to the MQTT Broker through the client authentication information assigned by the Internet of Things server, the plugin receives a notification of the basic authentication callback event for the connection, and determines whether the authentication information used for the connection matches the stored username and password. If they do not match, the connection is refused; if they match, the connection is successful and the client online status cache is updated.

[0087] (2) After the basic authentication passes, the publisher publishes a message to the Topic. The plugin receives the notification of the publish-subscribe authentication callback event, that is, the ACL verification. If the permission verification fails, the connection is refused. After the verification passes, the publisher successfully publishes the message. The plugin receives the message publish callback notification, looks up in the cache for the subscription Topic that matches this published message Topic in the client authentication information (for example: the published Topic = device2iotserver / heartbeat, there is a subscriber subscribing to this Topic = device2iotserver / heartbeat, or a Topic matching the subscription wildcard = device2iotserver / #), and the TTL setting is not 0, and the subscriber is offline at this time, then an offline cache message (which can contain multiple offline subscribers) is added to the message task queue for subsequent processing.

[0088] (3) After the plugin receives the notification of the publisher's offline callback event, it immediately updates the client online status cache, and its process is as Figure 5 shown.

[0089] The fourth part is the offline cache message processing stage, and the steps are as follows:

[0090] (1) Each subscription client ID + subscription Topic forms a message task queue. The queue waits when the subscriber is offline and starts the processing process after the subscriber goes online. Expired messages are discarded (for example, patient vital signs data (such as heart rate, blood pressure) needs to be cached when the device is disconnected from the network, but expired data is meaningless, and the TTL can be configured to 5 minutes). Un-expired messages are published. At this time, the online subscriber will receive all un-expired offline messages in sequence according to the priority configured by the Internet of Things server (business side), and its process is as Figure 6 shown.

[0091] Message task queue design: The time wheel algorithm is used to manage the message TTL, and the calculation formula is:

[0092] Texpire = Tpublish + TTL

[0093] Among them, Tpublish is the message publish time (that is, the time when it enters the message task queue), and TTL is the configured cache duration (unit: millisecond).

[0094] If the client is offline for a long time, the message task queue will also process expired tasks regularly.

[0095] Message delivery priority: It supports configuring the priority for the client ID of the subscription end and the subscribed Topic. According to the priority, the message task queue with a higher priority is processed first, and the offline cached messages are delivered to ensure that messages with strong timeliness are delivered first (such as alarm - type Topics). It is possible to only cache high - priority Topics (such as patient / alert), and dynamically adjust the caching policy through the HTTP interface, such as Figure 6 shown. Message delivery based on the priority queue supports delivering important messages first to prevent low - priority messages from blocking the consumer side.

[0096] Cross - domain applicability: This method can also be extended to fields such as industrial automation (such as PLC instruction caching) and vehicle - to - everything (V2X communication). Only the TTL and Topic configurations need to be adjusted to adapt to the requirements of different scenarios.

[0097] Based on the same inventive concept, this application also provides an apparatus corresponding to the method in Embodiment 1. For details, see Embodiment 2.

[0098] Embodiment 2

[0099] In this embodiment, an MQTT offline message caching apparatus is provided, including:

[0100] An integrated plugin module for integrating an MQTT plugin. The MQTT plugin is respectively connected to the IoT server, the publishing end, and the subscribing end. When the MQTT plugin receives the client authentication information sent by the IoT server, it determines whether to cache according to the subscribed Topic in the ACL and the corresponding TTL value. When caching is required, it creates or updates the message task queue. It authenticates the client through the MQTT plugin and updates the client online status. When the MQTT plugin receives the information that the publishing end publishes a message to the Topic, it searches for the subscribed Topic that matches this published message Topic in the client authentication information, sends the message according to the client status or performs offline caching through the message task queue, and then sends the cached message after the client goes online.

[0101] As Figure 7 shown, the integrated plugin module may include:

[0102] A plugin extension module for extending an MQTT plugin. The MQTT plugin is respectively connected to the IoT server, the publishing end, and the subscribing end, and is used to handle device connection, subscription, and message publishing, and send the data to the data storage module for storage;

[0103] A registration and authentication module, which is used to determine whether the TTL of the subscribed Topic in the ACL of the client authentication information is 0 when the MQTT plugin receives the client authentication information sent by the IoT server. If it is not 0, a message task queue is created or updated according to the client ID and Topic, and the data in the data storage module is updated.

[0104] A message subscription module, which is used to authenticate the client when the MQTT plugin receives the basic authentication callback event notification of the subscriber connection, and update the client online status after successful authentication; when the MQTT plugin receives the information of the subscriber subscribing to the Topic, update the subscribed Topic information and publish the subscription event notification after passing the verification; when the MQTT plugin receives the offline callback event notification of the subscriber, update the client online status.

[0105] A message publishing module, which is used to authenticate the client when the MQTT plugin receives the basic authentication callback event notification of the publisher connection, and update the client online status cache after successful authentication; when the MQTT plugin receives the information that the publisher publishes a message to the Topic, find the subscribed Topic that matches this published message Topic in the client authentication information.

[0106] An offline cached message processing module, which is used to start processing the offline cached message task when the message task queue receives the subscription event notification. Each client ID + subscribed Topic forms a message task queue. The message task queue waits when the subscriber is offline and starts the processing process after the subscriber goes online. Expired messages are discarded, and unexpired messages are published.

[0107] In a preferred implementation, in the registration and authentication module, when the MQTT plugin receives the updated client authentication information sent by the IoT server, the client authentication information in the data storage module is updated according to the client ID; in the registration and authentication module and the message publishing module, when the MQTT plugin authenticates the client, the latest client authentication information is obtained from the data storage module for verification.

[0108] In a preferred implementation, in the registration and authentication module, the priority is set according to the Topic or the client ID + subscribed Topic; in the offline cached message processing module, when publishing the unexpired messages in the message task queue, the messages are sent according to the set priority.

[0109] Since the device introduced in the second embodiment of the present invention is the device adopted for implementing the method of the first embodiment of the present invention, based on the method introduced in the first embodiment of the present invention, those skilled in the art can understand the specific structure and variations of the device, so it will not be elaborated here. Any device adopted for the method of the first embodiment of the present invention falls within the scope of protection of the present invention.

[0110] Based on the same inventive concept, this application provides a storage medium corresponding to the first embodiment, as detailed in the third embodiment.

[0111] Embodiment Three

[0112] This embodiment provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, any implementation manner in the first embodiment can be realized.

[0113] Since the computer-readable storage medium introduced in this embodiment is the computer-readable storage medium adopted for implementing the method in the first embodiment of this application, based on the method introduced in the first embodiment of this application, those skilled in the art can understand the specific implementation manner and various variations of the computer-readable storage medium in this embodiment. Therefore, how the computer-readable storage medium implements the method in the embodiments of this application will not be introduced in detail here. As long as the computer-readable storage medium adopted by those skilled in the art to implement the method in the embodiments of this application falls within the scope of protection of this application.

[0114] The technical solutions provided in the embodiments of the present invention have at least the following technical effects or advantages:

[0115] (1) Dynamic and flexible caching strategy: Through TTL configuration, precise management of the offline message life cycle is achieved. Taking the client and Topic as the smallest granularity, it avoids the waste of resources caused by message accumulation in the traditional scheme (compared with the expired cache message mechanism with unified configuration in current EMQ and other MQTT Brokers).

[0116] (2) The system is more robust, supports dynamic update of the TTL strategy without reloading.

[0117] (3) Optimization of resource utilization: Based on the message delivery of the priority queue, it supports the priority delivery of important messages to prevent low-priority messages from blocking the consumer side.

[0118] (4) Cross-domain applicability: This solution can be extended to fields such as industrial automation (such as PLC instruction caching) and vehicle networking (V2X communication). Only by adjusting the TTL and Topic configurations can it adapt to different scenario requirements.

[0119] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, a system, or a computer program product. Therefore, the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0120] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowchart and / or block diagram, as well as the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices produce a means for implementing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.

[0121] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufactured article including an instruction means that implements the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.

[0122] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.

[0123] Although the specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments we described are illustrative rather than used to limit the scope of the present invention. Equivalent modifications and variations made by those skilled in the art in accordance with the spirit of the present invention should be covered by the scope protected by the claims of the present invention.

Claims

1. An MQTT offline message caching method, characterized in that, Including: Integrating an MQTT plugin, which is respectively connected to the Internet of Things server, the publishing end and the subscribing end; When the MQTT plugin receives the client authentication information sent by the Internet of Things server, it determines whether to cache according to the subscribed Topic and the corresponding TTL value in the ACL. When caching is required, it creates or updates the message task queue; authenticates the client through the MQTT plugin and updates the client online status. When the MQTT plugin receives the information that the publishing end publishes a message to the Topic, it searches for the subscribed Topic that matches this published message Topic in the client authentication information, sends the message according to the client status or performs offline caching through the message task queue, and then sends the cached message after the client goes online.

2. The method according to claim 1, characterized in that, The method specifically includes: Plugin extension stage: Extending an MQTT plugin, which is respectively connected to the Internet of Things server, the publishing end and the subscribing end, and is used to handle device connection, subscription and message publishing, and send the data to the data storage module for storage; Registration and authentication stage: When the MQTT plugin receives the client authentication information sent by the Internet of Things server, it determines whether the TTL of the subscribed Topic in the ACL of the client authentication information is 0. If it is not 0, it creates or updates the message task queue according to the client ID and Topic, and updates the data in the data storage module; Message subscription stage: When the MQTT plugin receives the basic authentication callback event notification of the subscribing end connection, it authenticates the client. After the authentication passes, it updates the client status to online; when the MQTT plugin receives the information that the subscribing end subscribes to the Topic, after the verification passes, it updates the subscribed Topic information and publishes the subscription event notification; when the MQTT plugin receives the offline callback event notification of the subscribing end, it updates the client status to offline; Message publishing stage: When the MQTT plugin receives the basic authentication callback event notification of the publishing end connection, it authenticates the client. After the authentication passes, it updates the client online status cache; when the MQTT plugin receives the information that the publishing end publishes a message to the Topic, it searches for the subscribed Topic that matches this published message Topic in the client authentication information, and sends the message according to the client status or performs offline caching through the message task queue; Offline cached message processing stage: When the message task queue receives the subscription event notification, it starts to process the offline cached message task. Each client ID + subscribed Topic forms a message task queue; the message task queue waits when the subscribing end is offline, and starts the processing process after the subscribing end goes online. Expired messages are discarded, and unexpired messages are published.

3. The method according to claim 1, wherein: When the MQTT plugin receives the updated client authentication information sent by the Internet of Things server, it updates the client authentication information in the data storage module according to the client ID; when the MQTT plugin authenticates the client, it obtains the latest client authentication information from the data storage module for verification.

4. The method according to claim 1, wherein The method further includes: setting priorities according to the Topic or the client ID + subscribed Topic; when publishing the unexpired messages in the message task queue, sending messages according to the set priorities.

5. An MQTT offline message caching device, characterized in that, Including: An integrated plugin module for integrating an MQTT plugin, where the MQTT plugin is respectively connected to the Internet of Things server, the publishing end, and the subscribing end; When the MQTT plugin receives the client authentication information sent by the Internet of Things server, it determines whether to cache according to the subscribed Topic and the corresponding TTL value in the ACL, and creates or updates the message task queue when caching is required; authenticates the client through the MQTT plugin and updates the client online status. When the MQTT plugin receives the information that the publishing end publishes a message to the Topic, it searches for the subscribed Topic that matches this published message Topic in the client authentication information, sends the message according to the client status or performs offline caching through the message task queue, and then sends the cached message after the client goes online.

6. The device according to claim 5, characterized in that The integrated plugin module specifically includes: A plugin extension module for extending an MQTT plugin, where the MQTT plugin is respectively connected to the Internet of Things server, the publishing end, and the subscribing end, and is used to handle device connections, subscriptions, and message publications, and send data to the data storage module for saving; A registration authentication module for, when the MQTT plugin receives the client authentication information sent by the Internet of Things server, determining whether the TTL of the subscribed Topic in the ACL of the client authentication information is 0. If it is not 0, it creates or updates the message task queue according to the client ID and Topic and updates the data in the data storage module; A message subscription module for authenticating the client when the MQTT plugin receives the basic authentication callback event notification of the subscribing end connection, and updating the client status to online after successful authentication; when the MQTT plugin receives the information that the subscribing end subscribes to the Topic, updating the subscribed Topic information and publishing the subscription event notification after passing the verification; when the MQTT plugin receives the offline callback event notification of the subscribing end, updating the client status to offline; A message publishing module for authenticating the client when the MQTT plugin receives the basic authentication callback event notification of the publishing end connection, and updating the client online status cache after successful authentication; when the MQTT plugin receives the information that the publishing end publishes a message to the Topic, searching for the subscribed Topic that matches this published message Topic in the client authentication information, and sending the message according to the client status or performing offline caching through the message task queue; An offline cached message processing module for starting to process the offline cached message task when the message task queue receives the subscription event notification. Each client ID + subscribed Topic forms a message task queue. The message task queue waits when the subscribing end is offline and starts the processing process after the subscribing end goes online. Expired messages are discarded, and unexpired messages are published.

7. The device according to claim 5, characterized in that: In the registration and authentication module, when the MQTT plugin receives the updated client authentication information sent by the IoT server, it updates the client authentication information in the data storage module according to the client ID; in the registration and authentication module and the message publishing module, when the MQTT plugin authenticates the client, it obtains the latest client authentication information from the data storage module for verification.

8. The device according to claim 5, characterized in that: In the registration and authentication module, the priority is set according to the Topic or the client ID + subscribed Topic; in the offline cached message processing module, when publishing the unexpired messages in the message task queue, the messages are sent according to the set priority.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method described in any one of claims 1 to 4.

Citation Information

Cited By

  • Gateway information pushing method and system based on MQTT exchange protocol

    CN120896978A