WO2020140614A1 - Offline message distribution method, server and storage medium - Google Patents

Offline message distribution method, server and storage medium Download PDF

Info

Publication number
WO2020140614A1
WO2020140614A1 PCT/CN2019/117333 CN2019117333W WO2020140614A1 WO 2020140614 A1 WO2020140614 A1 WO 2020140614A1 CN 2019117333 W CN2019117333 W CN 2019117333W WO 2020140614 A1 WO2020140614 A1 WO 2020140614A1
Authority
WO
WIPO (PCT)
Prior art keywords
message
offline
client
messages
queue
Prior art date
Application number
PCT/CN2019/117333
Other languages
French (fr)
Chinese (zh)
Inventor
詹泽
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2020140614A1 publication Critical patent/WO2020140614A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/40Support for services or applications

Definitions

  • the present application relates to the field of data processing technology, and in particular to an offline message distribution method, server, and computer-readable storage medium based on the MQTT protocol.
  • MQTT Message Queuing Telemetry Transport
  • MQTT protocol One function of the MQTT protocol is offline message processing. Many MQTT products in the market deal with offline messages differently. Offline messages for open source MQTT server projects such as ActiveMQ, moquette, apolo, etc. are distributed for one client and one offline message list. Regardless of the time complexity or Kongjia complexity, when the number of clients is large and the number of offline messages is large, not only will the server processing performance be degraded, but also a lot of storage space will be wasted.
  • the present application provides an offline message distribution method, server, and computer-readable storage medium based on the MQTT protocol. Its main purpose is to reduce time complexity and space complexity, and improve offline message distribution efficiency.
  • the present application provides an offline message distribution method based on the MQTT protocol.
  • the method includes:
  • the present application also provides a server including: a memory and a processor, and the memory stores an offline message distribution program that can run on the processor, and the offline message distribution program is used by the processor During execution, any steps in the offline message distribution method described above can be implemented.
  • the present application also provides a computer-readable storage medium, the computer-readable storage medium includes an offline message distribution program, when the offline message distribution program is executed by the processor, the Any step in the offline message distribution method.
  • the offline message distribution method, server and computer-readable storage medium proposed in this application receive the message issued by the first client, and save it in the corresponding message queue according to the topic corresponding to the message and according to the first preset rule.
  • the offline time period of the second client and the offline message within the offline time period are determined, and the offline message is distributed to the second client according to the second preset rule.
  • Each topic corresponds to a message list.
  • all offline messages corresponding to a topic are pulled from the same message list, while reducing time and space complexity, and improving offline messages. Distribution efficiency.
  • FIG. 1 is a schematic diagram of a preferred embodiment of the application server
  • FIG. 2 is a schematic diagram of program modules of the offline message distribution program in FIG. 1;
  • FIG. 3 is a flowchart of a preferred embodiment of the offline message distribution method of the present application.
  • FIG. 1 it is a schematic diagram of a preferred embodiment of the server of the present application.
  • the server 1 is applied to a message distribution system based on the MQTT protocol (not shown in the figure).
  • the system includes: a server cluster including a plurality of the server 1 and a first client (not shown in the figure), The second client (not shown in the figure).
  • the first client is a message publishing terminal for publishing messages to the server 1;
  • the second client is a message subscribing terminal, and the second client only subscribes to the topic (topic, topic) corresponding to the first client
  • the weather can only receive the message published by the first client.
  • the first client and the second client may be terminal devices with data processing functions such as smart phones, tablet computers, portable computers, and desktop computers.
  • the message distribution system further includes: a load balancing device (not shown in the figure).
  • the load balancing device includes: a first load balancing device (not shown in the figure) and a second load balancing device (not shown in the figure). It should be noted that the first load balancing device and the second load balancing device may be the same load balancing device, or may be different load balancing devices.
  • the first load balancing device is used to receive the message issued by the first client and distribute the message to each server 1 in the server cluster for storage based on a preset load balancing rule.
  • the second load balancing device is used to receive the connection instruction issued by the second client, and distribute the connection instruction to each server 1 in the server cluster for processing based on a preset load balancing rule.
  • each server can identify all the messages corresponding to each second client and distribute them to the corresponding second client.
  • the preset load balancing rule is to distribute according to the load of each server 1 in the server cluster. For example, it is allocated to the server with the least real-time load for processing.
  • the server 1 may also be a rack server, a blade server, a tower server, or a rack server.
  • the server 1 includes a memory 11, a processor 12, and a network interface 13.
  • the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a hard disk, a multimedia card, a card-type memory (for example, SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, and the like.
  • the memory 11 may be an internal storage unit of the server 1, such as the hard disk of the server 1.
  • the memory 11 may also be an external storage device of the server 1, such as a plug-in hard disk equipped on the server 1, a smart memory card (Smart, Media, Card, SMC), and a secure digital (SD, Digital, SD) ) Card, flash card (Flash Card), etc.
  • the memory 11 may also include both the internal storage unit of the server 1 and the external storage device.
  • the memory 11 can be used not only to store application software installed on the server 1 and various types of data, such as an offline message distribution program 10, but also to temporarily store data that has been or will be output.
  • the processor 12 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip for running the program code or processing stored in the memory 11 Data, for example, offline message distribution program 10, etc.
  • CPU central processing unit
  • controller microcontroller
  • microprocessor or other data processing chip for running the program code or processing stored in the memory 11 Data, for example, offline message distribution program 10, etc.
  • the network interface 13 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface), and is generally used to establish a communication connection between the server 1 and other electronic devices. For example, data transmission with the client (not marked in the figure).
  • a standard wired interface and a wireless interface such as a WI-FI interface
  • FIG. 1 only shows a server 1 having components 11-13. Those skilled in the art can understand that the structure shown in FIG. 1 does not constitute a limitation on the server 1, and may include fewer or more than shown. Components, or some combination of components, or different component arrangements.
  • the server 1 may further include a user interface.
  • the user interface may include a display, an input unit such as a keyboard, and the optional user interface may further include a standard wired interface and a wireless interface.
  • the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an organic light-emitting diode (OLED) touch device, or the like.
  • the display may also be referred to as a display screen or a display unit, for displaying information processed in the server 1 and for displaying a visual user interface.
  • the memory 11 as a computer storage medium stores the program code of the offline message distribution program 10, and when the processor 12 executes the program code of the offline message distribution program 10, the implementation step is: A1 -A4.
  • A1 Receive the message issued by the first client, determine the message queue corresponding to the message according to the attribute information of the message, and save the message in the message queue based on the first preset rule.
  • the first client is the message publishing end.
  • the attribute information of the message includes information such as the time stamp of the message, the topic (for example, weather) corresponding to the message, and the like.
  • the MQTT protocol stipulates that when sending a message to a server, the message publisher needs to transmit the tipic corresponding to the message, so the server can directly obtain the topic information corresponding to the message.
  • each topic corresponds to a message queue.
  • the number of message queues is only related to the topic, and has nothing to do with the number of second clients (message subscribers).
  • Each message belongs to only one topic, and only clients that subscribe to the topic can receive this type of message.
  • the topic is weather
  • the first client is a client that publishes weather messages. Only the second client that subscribes to the topic "weather” can receive weather messages.
  • the server receives the weather message, determines the corresponding topic "weather” according to its attribute information, and saves the message to the message queue corresponding to "weather”.
  • the "save the message in the message queue according to the first preset rule" includes:
  • the attribute information of the message also includes a time stamp of each message.
  • the time stamp is the time when the message was published, that is, the time when the server received the message.
  • sort the messages according to the order of time and then find the message queue corresponding to the topic of "weather", and store the message to the head of the message queue in sequence, that is, the message at the head of the message queue is the publication time
  • the latest (newest) message, and the message at the end of the message queue is the oldest (oldest) message.
  • the effective time (for example, 7 days) of each message is preset, and when the time for saving the message to the message queue exceeds the preset effective time, the message is deleted from the message queue.
  • A2. Receive the connection instruction of the second client, obtain the online time and the last offline time of the second client, and determine the offline time period.
  • the second client is a message subscription end, subscribes to one or more topics through the second client, and receives messages corresponding to one or more topics.
  • the server can obtain and record the time when each second client is offline or online.
  • the online operation performed by the user through the second client is a signal that triggers the distribution of offline messages.
  • the time when the current second client issues the connection instruction is taken as the end time of the offline time period, and the latest offline time before the current second client issues the connection instruction as the offline time
  • the start time of the segment determines the offline time period of the second client according to the start time and the end time. For example, the online time this time is a, and the offline time before this time online is b, then the offline time period of the second client is b-a.
  • the offline time period may be the same or different.
  • A3. Determine one or more message queues corresponding to the second client respectively, find out the messages of the second client in the offline time period from the one or more message queues respectively, and generate the first The offline message list of the two clients.
  • the "finding messages of the second client in the offline time period from the one or more message queues respectively as offline messages of the second client" includes:
  • Obtain the first message of a message queue obtain a time stamp from the attribute information of the first message, and determine whether the time stamp is within the offline time period;
  • the messages in a message queue are sorted in the order of the release time, if the release time of the latest message is not in the offline period, then other messages in the queue must not be in the offline period. If the latest message is an offline message, then go forward in turn to determine whether the second message is within the offline time period. By first judging whether the latest message is an offline message, many redundant judgments can be reduced, thereby saving resources.
  • the number of message queues corresponding to the second client is the same as the number of TOPICs subscribed by the second client.
  • Each second client subscribes to N TOPICs, that is, corresponds to N message queues, where N is an integer greater than or equal to 0.
  • the second client P subscribes to N topics, and sequentially determines the messages of the second client P in the offline time period (ba) from the message queues corresponding to the N topics, that is, the offline messages of the second client P . There may be offline messages of the second client P in the message queue, or there may be no offline messages of the second client P.
  • A4. Distribute the messages in the offline message list to the second client based on the second preset rule.
  • the second preset rule includes:
  • the offline messages are sequentially sent to the second client.
  • the order of each offline message is: m1, m2, m3, ..., m10, where m1 is the latest offline message and m10 is the oldest
  • the latest offline message m1 is distributed first, then the offline message m2 is distributed, and so on.
  • the second preset rule in this embodiment further includes:
  • the subscription time of the topic corresponding to each offline message list is determined, and the offline messages in each offline message list are distributed in order according to the order of the subscription time from early to late.
  • the server 1 proposed in the above embodiment receives the message published by the first client, saves it to the corresponding message queue according to the topic corresponding to the message according to the first preset rule, and determines the second when the second client reconnects to the server
  • the offline time period of the client and the offline messages in the offline time period distribute the offline message to the second client according to the second preset rule.
  • Each topic corresponds to a message list.
  • the "save the message in the message queue according to the first preset rule" in step A1 includes:
  • the number of messages in the message queue is the first preset threshold, each time a new message is received, a message at the end of the message queue is removed, and the new message is placed at the head of the message queue.
  • the maximum capacity of the message queue is set in advance. If there are already 1000 messages in the message queue, the oldest message needs to be deleted every time a new message comes in, and then the new message is saved.
  • the "save the message in the message queue according to the first preset rule" also includes:
  • the second preset threshold When the number of messages in the message queue reaches the second preset threshold, generate warning information and send it to a preset terminal, receive an instruction issued by the preset terminal to update the first preset threshold, respond to the instruction and execute The first preset threshold update operation.
  • the warning value 900 of the capacity of the message queue is preset, and the second preset threshold corresponds to the first preset threshold.
  • a warning message is sent to the preset terminal (for example, "the number of messages in the message queue is about to reach the upper limit, please make adjustments in time").
  • the administrator sends an instruction to adjust the first preset threshold through the preset terminal, and the instruction includes the updated value of the first preset threshold, for example, 1200. This step ensures the integrity of the message.
  • the offline message distribution program 10 may also be divided into one or more modules, and the one or more modules are stored in the memory 11 and controlled by one or more processors (this implementation The example is executed by the processor 12) to complete this application.
  • the module referred to in this application refers to a series of computer program instruction segments capable of performing specific functions.
  • the offline message distribution program 10 may be divided into a first receiving 110, a second receiving module 120, a query module 130, and The distribution module 140, the functions or operation steps implemented by the modules 110-140 are similar to the above, and will not be described in detail here, for example, for example:
  • the first receiving module 110 is configured to receive a message published by the first client, determine the message queue corresponding to the message according to the attribute information of the message, and save the message in the message queue based on the first preset rule;
  • the second receiving module 120 is configured to receive the connection instruction of the second client, obtain the online time and the last offline time of the second client, and determine the offline time period;
  • the query module 130 is configured to determine one or more message queues corresponding to the second client respectively, and find out the messages of the second client in the offline time period from the one or more message queues, Generate an offline message list of the second client;
  • the distribution module 140 is configured to distribute the messages in the offline message list to the second client based on the second preset rule.
  • This application provides an offline message distribution method based on the MQTT protocol.
  • FIG. 3 it is a flowchart of a preferred embodiment of an offline message distribution method based on the MQTT protocol of the present application.
  • the method may be executed by a server, and the server may be implemented by software and/or hardware.
  • the offline message distribution method based on the MQTT protocol is applied to the server, and the method includes steps S1-S4.
  • the first client is the message publishing end.
  • the attribute information of the message includes information such as the time stamp of the message, the topic (for example, weather) corresponding to the message, and the like.
  • the MQTT protocol stipulates that when sending a message to a server, the message publisher needs to transmit the tipic corresponding to the message, so the server can directly obtain the topic information corresponding to the message.
  • each topic corresponds to a message queue.
  • the number of message queues is only related to the topic, and has nothing to do with the number of second clients (message subscribers).
  • Each message belongs to only one topic, and only clients that subscribe to the topic can receive this type of message.
  • the topic is weather
  • the first client is a client that publishes weather messages. Only the second client that subscribes to the topic "weather” can receive weather messages.
  • the server receives the weather message, determines the corresponding topic "weather” according to its attribute information, and saves the message to the message queue corresponding to "weather”.
  • the "save the message in the message queue according to the first preset rule" includes:
  • the attribute information of the message also includes a time stamp of each message.
  • the time stamp is the time when the message was published, that is, the time when the server received the message.
  • sort the messages according to the order of time and then find the message queue corresponding to the topic of "weather", and store the message to the head of the message queue in sequence, that is, the message at the head of the message queue is the publication time
  • the latest (newest) message, and the message at the end of the message queue is the oldest (oldest) message.
  • the effective time (for example, 7 days) of each message is preset, and when the time for saving the message to the message queue exceeds the preset effective time, the message is deleted from the message queue.
  • the second client is a message subscription end, subscribes to one or more topics through the second client, and receives messages corresponding to one or more topics.
  • the server can obtain and record the time when each second client is offline or online.
  • the online operation performed by the user through the second client is a signal that triggers the distribution of offline messages.
  • the time when the current second client issues the connection instruction is taken as the end time of the offline time period, and the latest offline time before the current second client issues the connection instruction as the offline time
  • the start time of the segment determines the offline time period of the second client according to the start time and the end time. For example, the online time this time is a, and the offline time before this time online is b, then the offline time period of the second client is b-a.
  • the offline time period may be the same or different.
  • the "finding messages of the second client in the offline time period from the one or more message queues respectively as offline messages of the second client" includes:
  • Obtain the first message of a message queue obtain a time stamp from the attribute information of the first message, and determine whether the time stamp is within the offline time period;
  • the messages in a message queue are sorted in the order of the release time, if the release time of the latest message is not in the offline period, then other messages in the queue must not be in the offline period. If the latest message is an offline message, then go forward in turn to determine whether the second message is within the offline time period. By first judging whether the latest message is an offline message, many redundant judgments can be reduced, thereby saving resources.
  • the number of message queues corresponding to the second client is the same as the number of TOPICs subscribed by the second client.
  • Each second client subscribes to N TOPICs, that is, corresponds to N message queues, where N is an integer greater than or equal to 0.
  • the second client P subscribes to N topics, and sequentially determines the messages of the second client P in the offline time period (ba) from the message queues corresponding to the N topics, that is, the offline messages of the second client P . There may be offline messages of the second client P in the message queue, or there may be no offline messages of the second client P.
  • the second preset rule includes:
  • the offline messages are sequentially sent to the second client.
  • the order of each offline message is: m1, m2, m3, ..., m10, where m1 is the latest offline message and m10 is the oldest
  • the latest offline message m1 is distributed first, then the offline message m2 is distributed, and so on.
  • the second preset rule in this embodiment further includes:
  • the subscription time of the topic corresponding to each offline message list is determined, and the offline messages in each offline message list are distributed in order according to the order of the subscription time from early to late.
  • the offline message distribution method based on the MQTT protocol proposed in the above embodiment receives the message published by the first client, saves it to the corresponding message queue according to the topic corresponding to the message according to the first preset rule, and waits for the second client to reconnect
  • the server determines the offline time period of the second client and the offline message within the offline time period, and distributes the offline message to the second client according to the second preset rule.
  • Each topic corresponds to a message list.
  • the "save the message in the message queue according to the first preset rule" in step S1 includes:
  • the number of messages in the message queue is the first preset threshold, each time a new message is received, a message at the end of the message queue is removed, and the new message is placed at the head of the message queue.
  • the maximum capacity of the message queue is set in advance. If there are already 1000 messages in the message queue, the oldest message needs to be deleted every time a new message comes in, and then the new message is saved.
  • the "save the message in the message queue according to the first preset rule" in step S1 also includes:
  • the second preset threshold When the number of messages in the message queue reaches the second preset threshold, generate warning information and send it to a preset terminal, receive an instruction issued by the preset terminal to update the first preset threshold, respond to the instruction and execute The first preset threshold update operation.
  • the warning value 900 of the capacity of the message queue is preset, and the second preset threshold corresponds to the first preset threshold.
  • a warning message is sent to the preset terminal (for example, "the number of messages in the message queue is about to reach the upper limit, please make adjustments in time").
  • the administrator sends an instruction to adjust the first preset threshold through the preset terminal, and the instruction includes the updated value of the first preset threshold, for example, 1200. This step ensures the integrity of the message.
  • the offline message distribution method based on the MQTT protocol proposed in the above embodiment manages and controls the capacity of messages in each message queue to save storage space while ensuring the integrity of offline messages.
  • an embodiment of the present application also provides a computer-readable storage medium, which includes an offline message distribution program 10, and when the offline message distribution program 10 is executed by a processor, the following operations are implemented:
  • A1. Receive the message published by the first client, determine the message queue corresponding to the message according to the attribute information of the message, and save the message in the message queue based on the first preset rule;
  • A2. Receive the connection instruction of the second client, obtain the online time and the last offline time of the second client, and determine the offline time period;
  • A3. Determine one or more message queues corresponding to the second client respectively, find out the messages of the second client in the offline time period from the one or more message queues respectively, and generate the first The offline message list of the two clients;
  • A4. Distribute the messages in the offline message list to the second client based on the second preset rule.

Abstract

Disclosed in the present application is an MQTT protocol-based offline message distribution method. The method comprises: receiving a message issued by a first client and storing the message in a message queue; receiving a connection instruction of a second client, and determining an offline time period of the second client; separately determining messages in the offline time period corresponding to the second client to generate an offline message list of the second client; and distributing the messages in the offline message list to the second client. Also disclosed in the present application are a server and a computer storage medium. In using the present application, time complexity and space complexity are reduced, and the offline message distribution efficiency is improved.

Description

离线消息分发方法、服务器及存储介质Offline message distribution method, server and storage medium
本申请基于巴黎公约申明享有2019年01月04日递交的申请号为CN 201910007206.X、名称为“离线消息分发方法、服务器及存储介质”的中国专利申请的优先权,该中国专利申请的整体内容以参考的方式结合在本申请中。This application is based on the declaration of the Paris Convention and enjoys the priority of the Chinese patent application filed on January 4, 2019, with the application number CN201910007206.X and the name "offline message distribution method, server and storage medium". The entirety of the Chinese patent application The content is incorporated in this application by reference.
技术领域Technical field
本申请涉及数据处理技术领域,尤其涉及一种基于MQTT协议的离线消息分发方法、服务器及计算机可读存储介质。The present application relates to the field of data processing technology, and in particular to an offline message distribution method, server, and computer-readable storage medium based on the MQTT protocol.
背景技术Background technique
早在1999年,IBM的Andy Stanford-Clark博士以及Arcom公司ArlenNipper博士发明了MQTT(Message Queuing Telemetry Transport,消息队列遥测传输)技术。目前,国内很多企业都广泛使用MQTT作为Android手机客户端与服务器端推送消息的协议。其中,Sohu,Cmstop手机客户端中均有使用到MQTT作为消息推送消息。As early as 1999, Dr. Andy Stanford-Clark of IBM and Dr. ArlenNipper of Arcom Corporation invented the MQTT (Message Queuing Telemetry Transport) technology. At present, many domestic enterprises widely use MQTT as the protocol for pushing messages between the Android mobile client and the server. Among them, Sohu and Cmstop mobile client all use MQTT as a message push message.
MQTT协议中有一个功能是离线消息的处理。在市场上的很多MQTT产品对离线消息的处理都不一样,对于像ActiveMQ,moquette,apolo等开源MQTT服务端项目的离线消息都是针对一个客户端一个离线消息列表进行分发。不管从时间复杂度还是孔家复杂度考虑,客户端数量很大、离线消息数量很大时,不止会让服务器处理性能变差,还会浪费很多存储空间。One function of the MQTT protocol is offline message processing. Many MQTT products in the market deal with offline messages differently. Offline messages for open source MQTT server projects such as ActiveMQ, moquette, apolo, etc. are distributed for one client and one offline message list. Regardless of the time complexity or Kongjia complexity, when the number of clients is large and the number of offline messages is large, not only will the server processing performance be degraded, but also a lot of storage space will be wasted.
发明内容Summary of the invention
鉴于以上内容,本申请提供一种基于MQTT协议的离线消息分发方法、服务器及计算机可读存储介质,其主要目的在于降低了时间复杂度和空间复杂度,提高离线消息分发效率。In view of the above, the present application provides an offline message distribution method, server, and computer-readable storage medium based on the MQTT protocol. Its main purpose is to reduce time complexity and space complexity, and improve offline message distribution efficiency.
为实现上述目的,本申请提供一种基于MQTT协议的离线消息分发方法,该方法包括:To achieve the above purpose, the present application provides an offline message distribution method based on the MQTT protocol. The method includes:
S1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中;S1. Receive the message published by the first client, determine the message queue corresponding to the message according to the attribute information of the message, and save the message in the message queue based on the first preset rule;
S2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;S2. Receive the connection instruction of the second client, obtain the online time and the last offline time of the second client, and determine the offline time period;
S3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及S3. Determine one or more message queues corresponding to the second client respectively, find the messages of the second client in the offline time period from the one or more message queues respectively, and generate the first The offline message list of the two clients; and
S4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。S4. Distribute the messages in the offline message list to the second client based on the second preset rule.
此外,本申请还提供一种服务器,该服务器包括:存储器、处理器,所述存储器上存储有可在所述处理器上运行的离线消息分发程序,所述离线消息分发程序被所述处理器执行时,可实现如上所述离线消息分发方法中的任意步骤。In addition, the present application also provides a server including: a memory and a processor, and the memory stores an offline message distribution program that can run on the processor, and the offline message distribution program is used by the processor During execution, any steps in the offline message distribution method described above can be implemented.
此外,为实现上述目的,本申请还提供一种计算机可读存储介质,所述计算机可读存储介质中包括离线消息分发程序,所述离线消息分发程序被处理器执行时,可实现如上所述离线消息分发方法中的任意步骤。In addition, in order to achieve the above object, the present application also provides a computer-readable storage medium, the computer-readable storage medium includes an offline message distribution program, when the offline message distribution program is executed by the processor, the Any step in the offline message distribution method.
本申请提出的离线消息分发方法、服务器及计算机可读存储介质,接收第一客户端发布的消息,根据消息对应的topic(主题)、按照第一预设规则保存至对应的消息队列中,待第二客户端重新连接服务器时,确定第二客户端的离线时间段及离线时间段内的离线消息,按照第二预设规则将离线消息分发给第二客户端。每个topic对应一个消息列表,当有多个第二客户端重新连接服务器时,均从同一消息列表拉取某一个topic对应的离线消息,同时降低了时间复杂度和空间复杂度,提高离线消息分发效率。The offline message distribution method, server and computer-readable storage medium proposed in this application receive the message issued by the first client, and save it in the corresponding message queue according to the topic corresponding to the message and according to the first preset rule. When the second client reconnects to the server, the offline time period of the second client and the offline message within the offline time period are determined, and the offline message is distributed to the second client according to the second preset rule. Each topic corresponds to a message list. When multiple second clients reconnect to the server, all offline messages corresponding to a topic are pulled from the same message list, while reducing time and space complexity, and improving offline messages. Distribution efficiency.
附图说明BRIEF DESCRIPTION
图1为本申请服务器较佳实施例的示意图;FIG. 1 is a schematic diagram of a preferred embodiment of the application server;
图2为图1中离线消息分发程序的程序模块示意图;2 is a schematic diagram of program modules of the offline message distribution program in FIG. 1;
图3为本申请离线消息分发方法较佳实施例的流程图。FIG. 3 is a flowchart of a preferred embodiment of the offline message distribution method of the present application.
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The implementation, functional characteristics and advantages of the present application will be further described in conjunction with the embodiments and with reference to the drawings.
具体实施方式detailed description
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。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.
本申请提供一种服务器。参照图1所示,为本申请服务器较佳实施例的示意图。This application provides a server. Referring to FIG. 1, it is a schematic diagram of a preferred embodiment of the server of the present application.
所述服务器1应用于一种基于MQTT协议的消息分发系统(图中未标出),该系统包括:包括多个所述服务器1的服务器集群、第一客户端(图中未标出)、第二客户端(图中未标出)。其中,所述第一客户端为消息发布端,用于发布消息至服务器1;所述第二客户端为消息订阅端,第二客户端只有在订阅了第一客户端对应的topic(主题,例如,天气)后才能接收到第一客户端发布的消息。所述第一客户端和第二客户端可以是智能手机、平板电脑、便携计算机、桌上型计算机等具有数据处理功能的终端设备。The server 1 is applied to a message distribution system based on the MQTT protocol (not shown in the figure). The system includes: a server cluster including a plurality of the server 1 and a first client (not shown in the figure), The second client (not shown in the figure). Wherein, the first client is a message publishing terminal for publishing messages to the server 1; the second client is a message subscribing terminal, and the second client only subscribes to the topic (topic, topic) corresponding to the first client For example, the weather can only receive the message published by the first client. The first client and the second client may be terminal devices with data processing functions such as smart phones, tablet computers, portable computers, and desktop computers.
在其他实施例中,所述消息分发系统还包括:负载均衡设备(图中未标出)。In other embodiments, the message distribution system further includes: a load balancing device (not shown in the figure).
所述负载均衡设备包括:第一负载均衡设备(图中未标出)及第二负载均衡设备(图中未标出)。需要说明的是,所述第一负载均衡设备及第二负载均衡设备可以是同一个负载均衡设备,也可以是不同的额负载均衡设备。The load balancing device includes: a first load balancing device (not shown in the figure) and a second load balancing device (not shown in the figure). It should be noted that the first load balancing device and the second load balancing device may be the same load balancing device, or may be different load balancing devices.
其中,第一负载均衡设备用于接收第一客户端发布的消息,并将该消息基于预设负载均衡规则均衡分配给服务器集群中的每台服务器1进行存储。The first load balancing device is used to receive the message issued by the first client and distribute the message to each server 1 in the server cluster for storage based on a preset load balancing rule.
第二负载均衡设备用于接收第二客户端发出的连接指令,并将该连接指令基于预设负载均衡规则均衡分配给服务器集群中的每台服务器1进行处理。The second load balancing device is used to receive the connection instruction issued by the second client, and distribute the connection instruction to each server 1 in the server cluster for processing based on a preset load balancing rule.
鉴于第一客户端发布的消息都是存储到中央存储的,因此,每台服务器都能识别每台第二客户端对应的所有消息,并分发给对应的第二客户端。Since the messages published by the first client are stored in the central storage, each server can identify all the messages corresponding to each second client and distribute them to the corresponding second client.
所述预设负载均衡规则为:根据所述服务器集群中各服务器1的负载进行分配。例如,分配给实时负载最小的服务器进行处理。The preset load balancing rule is to distribute according to the load of each server 1 in the server cluster. For example, it is allocated to the server with the least real-time load for processing.
在本实施例中,所述服务器1还可以是机架式服务器、刀片式服务器、塔式服务器或机柜式服务器。In this embodiment, the server 1 may also be a rack server, a blade server, a tower server, or a rack server.
在图1中,所述服务器1包括存储器11、处理器12,及网络接口13。In FIG. 1, the server 1 includes a memory 11, a processor 12, and a network interface 13.
其中,存储器11至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁 性存储器、磁盘、光盘等。存储器11在一些实施例中可以是所述服务器1的内部存储单元,例如该服务器1的硬盘。存储器11在另一些实施例中也可以是所述服务器1的外部存储设备,例如该服务器1上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,存储器11还可以既包括该服务器1的内部存储单元也包括外部存储设备。Among them, the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a hard disk, a multimedia card, a card-type memory (for example, SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, and the like. In some embodiments, the memory 11 may be an internal storage unit of the server 1, such as the hard disk of the server 1. In other embodiments, the memory 11 may also be an external storage device of the server 1, such as a plug-in hard disk equipped on the server 1, a smart memory card (Smart, Media, Card, SMC), and a secure digital (SD, Digital, SD) ) Card, flash card (Flash Card), etc. Further, the memory 11 may also include both the internal storage unit of the server 1 and the external storage device.
存储器11不仅可以用于存储安装于该服务器1的应用软件及各类数据,例如离线消息分发程序10等,还可以用于暂时地存储已经输出或者将要输出的数据。The memory 11 can be used not only to store application software installed on the server 1 and various types of data, such as an offline message distribution program 10, but also to temporarily store data that has been or will be output.
处理器12在一些实施例中可以是一中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器11中存储的程序代码或处理数据,例如,离线消息分发程序10等。In some embodiments, the processor 12 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip for running the program code or processing stored in the memory 11 Data, for example, offline message distribution program 10, etc.
网络接口13可选的可以包括标准的有线接口、无线接口(如WI-FI接口),通常用于在该服务器1与其他电子设备之间建立通信连接。例如,与客户端(图中未标注)进行数据传输。The network interface 13 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface), and is generally used to establish a communication connection between the server 1 and other electronic devices. For example, data transmission with the client (not marked in the figure).
图1仅示出了具有组件11-13的服务器1,本领域技术人员可以理解的是,图1示出的结构并不构成对服务器1的限定,可以包括比图示更少或者更多的部件,或者组合某些部件,或者不同的部件布置。FIG. 1 only shows a server 1 having components 11-13. Those skilled in the art can understand that the structure shown in FIG. 1 does not constitute a limitation on the server 1, and may include fewer or more than shown. Components, or some combination of components, or different component arrangements.
可选地,该服务器1还可以包括用户接口,用户接口可以包括显示器(Display)、输入单元比如键盘(Keyboard),可选的用户接口还可以包括标准的有线接口、无线接口。Optionally, the server 1 may further include a user interface. The user interface may include a display, an input unit such as a keyboard, and the optional user interface may further include a standard wired interface and a wireless interface.
可选地,在一些实施例中,显示器可以是LED显示器、液晶显示器、触控式液晶显示器以及有机发光二极管(Organic Light-Emitting Diode,OLED)触摸器等。其中,显示器也可以称为显示屏或显示单元,用于显示在服务器1中处理的信息以及用于显示可视化的用户界面。Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an organic light-emitting diode (OLED) touch device, or the like. Among them, the display may also be referred to as a display screen or a display unit, for displaying information processed in the server 1 and for displaying a visual user interface.
在图1所示的服务器1实施例中,作为一种计算机存储介质的存储器11中存储离线消息分发程序10的程序代码,处理器12执行离线消息分发程序10的程序代码时,实现步骤:A1-A4。In the embodiment of the server 1 shown in FIG. 1, the memory 11 as a computer storage medium stores the program code of the offline message distribution program 10, and when the processor 12 executes the program code of the offline message distribution program 10, the implementation step is: A1 -A4.
A1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对 应的消息队列,并基于第一预设规则将该消息保存在该消息队列中。A1. Receive the message issued by the first client, determine the message queue corresponding to the message according to the attribute information of the message, and save the message in the message queue based on the first preset rule.
其中,第一客户端为消息发布端。Among them, the first client is the message publishing end.
所述消息的属性信息中包括消息的时间戳、消息对应的topic(例如,天气)等信息。MQTT协议规定,消息发布端在发送消息至服务器时,需一并传递消息对应的tipic(主题),因此,服务器可直接获取消息对应的topic信息。The attribute information of the message includes information such as the time stamp of the message, the topic (for example, weather) corresponding to the message, and the like. The MQTT protocol stipulates that when sending a message to a server, the message publisher needs to transmit the tipic corresponding to the message, so the server can directly obtain the topic information corresponding to the message.
需要说明的是,每个topic对应一个消息队列。也就是说,消息队列的多少只与topic有关,与第二客户端(消息订阅端)的数量无关。It should be noted that each topic corresponds to a message queue. In other words, the number of message queues is only related to the topic, and has nothing to do with the number of second clients (message subscribers).
每条消息只属于一个topic,只有订阅了该topic的客户端才能收到该类消息。例如,topic为天气,第一客户端为发布天气消息的客户端,只有订阅了订阅了“天气”这个topic的第二客户端才能收到天气消息。当第一客户端发布一条天气消息后,服务器接收该条天气消息,根据其属性信息确定对应的topic“天气”,将这条消息保存至“天气”对应的消息队列中。Each message belongs to only one topic, and only clients that subscribe to the topic can receive this type of message. For example, the topic is weather, and the first client is a client that publishes weather messages. Only the second client that subscribes to the topic "weather" can receive weather messages. After the first client publishes a weather message, the server receives the weather message, determines the corresponding topic "weather" according to its attribute information, and saves the message to the message queue corresponding to "weather".
本实施例中,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:In this embodiment, the "save the message in the message queue according to the first preset rule" includes:
从所述消息的属性信息中获取时间戳,根据所述时间戳从早到晚的顺序,依次将所述消息保存在该消息对应的消息队列的头部。Obtain a time stamp from the attribute information of the message, and according to the order of the time stamp from early to late, sequentially save the message at the head of the message queue corresponding to the message.
以topic为“天气”为例,消息的属性信息中还包括每一条消息的时间戳,时间戳为消息的发布时间,即,服务器接收到消息的时间。接收到消息之后,将消息按照时间的早晚顺序进行排序,然后找到“天气”这一通topic对应的消息队列,依次将消息存储至消息队列的头部,即,消息队列头部的消息为发布时间最晚(最新)的消息,消息队列尾部的消息为发布时间最早(最旧)的消息。Taking the topic "weather" as an example, the attribute information of the message also includes a time stamp of each message. The time stamp is the time when the message was published, that is, the time when the server received the message. After receiving the message, sort the messages according to the order of time, and then find the message queue corresponding to the topic of "weather", and store the message to the head of the message queue in sequence, that is, the message at the head of the message queue is the publication time The latest (newest) message, and the message at the end of the message queue is the oldest (oldest) message.
需要说明的是,每条消息的有效时间(例如,7天)是预先设定的,当消息保存至消息队列的时间超过预先设定的有效时间时,将所述消息从消息队列中删除。It should be noted that the effective time (for example, 7 days) of each message is preset, and when the time for saving the message to the message queue exceeds the preset effective time, the message is deleted from the message queue.
A2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段。A2. Receive the connection instruction of the second client, obtain the online time and the last offline time of the second client, and determine the offline time period.
第二客户端为消息订阅端,通过第二客户端订阅一个或多个topic,并接收一个或多个topic对应的消息。第二客户端执行每次离线或者上线操作时, 服务器均能获取并记录每一个第二客户端的每次离线或者上线的时间。用户通过第二客户端执行上线操作为触发离线消息的分发的信号。The second client is a message subscription end, subscribes to one or more topics through the second client, and receives messages corresponding to one or more topics. When the second client performs each offline or online operation, the server can obtain and record the time when each second client is offline or online. The online operation performed by the user through the second client is a signal that triggers the distribution of offline messages.
当侦测到第二客户端的连接指令时,获取当前第二客户端发出连接指令的时间作为离线时间段的结束时间,获取当前第二客户端发出连接指令前最近一次的离线时间,作为离线时间段的开始时间,根据开始时间及结束时间确定第二客户端本次的离线时间段。例如,本次上线时间为a,在本次上线前的离线时间为b,那么,第二客户端的离线时间段为b-a。When the connection instruction of the second client is detected, the time when the current second client issues the connection instruction is taken as the end time of the offline time period, and the latest offline time before the current second client issues the connection instruction as the offline time The start time of the segment determines the offline time period of the second client according to the start time and the end time. For example, the online time this time is a, and the offline time before this time online is b, then the offline time period of the second client is b-a.
对于不同的第二客户端,离线时间段可能相同,也可能不同。For different second clients, the offline time period may be the same or different.
A3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表。A3. Determine one or more message queues corresponding to the second client respectively, find out the messages of the second client in the offline time period from the one or more message queues respectively, and generate the first The offline message list of the two clients.
具体地,所述“分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,作为所述第二客户端的离线消息”,包括:Specifically, the "finding messages of the second client in the offline time period from the one or more message queues respectively as offline messages of the second client" includes:
获取一个消息队列的第一条消息,从所述第一条消息的属性信息中获取时间戳,判断该时间戳是否在离线时间段内;Obtain the first message of a message queue, obtain a time stamp from the attribute information of the first message, and determine whether the time stamp is within the offline time period;
若是,则判断该第一条消息是离线消息,并依次获取该消息队列中的下一条消息重复上述步骤;If yes, it is determined that the first message is an offline message, and the next message in the message queue is sequentially obtained and the above steps are repeated;
若否,则判断该第一条消息不是离线消息,判断该消息队列中不存在所述第二客户端的离线消息。If not, it is determined that the first message is not an offline message, and it is determined that there is no offline message of the second client in the message queue.
由于一个消息队列中消息是按照发布时间的早晚顺序排序的,若发布的最晚的消息的发布时间都不在离线时间段内,那么队列中其他消息也一定不在离线时间段内。若发布最晚的消息的是离线消息,则依次往前,判断第二条消息是否在离线时间段内。通过最先判断最新的消息是否为离线消息,可减少很多多余的判断,进而节约资源。Since the messages in a message queue are sorted in the order of the release time, if the release time of the latest message is not in the offline period, then other messages in the queue must not be in the offline period. If the latest message is an offline message, then go forward in turn to determine whether the second message is within the offline time period. By first judging whether the latest message is an offline message, many redundant judgments can be reduced, thereby saving resources.
重复上述步骤,获取第二客户端在离线时间段内所有消息队列中的离线消息、并生成离线消息列表。离线消息列表中,最新的离线消息排在前面,最旧的离线消息排在后面。Repeat the above steps to obtain offline messages in all message queues of the second client in the offline time period, and generate an offline message list. In the offline message list, the latest offline message is ranked first, and the oldest offline message is ranked next.
本实施例中,第二客户端对应的消息队列的数量与第二客户端订阅的TOPIC数量相同。每个第二客户端订阅了N个TOPIC,即对应N个消息队列,其中,N为大于或等于0的整数。In this embodiment, the number of message queues corresponding to the second client is the same as the number of TOPICs subscribed by the second client. Each second client subscribes to N TOPICs, that is, corresponds to N message queues, where N is an integer greater than or equal to 0.
例如,第二客户端P订阅了N个topic,依次从N个topic对应的消息队列中确定第二客户端P在离线时间段(b-a)内的消息,即,第二客户端P的离线消息。消息队列中可能存在第二客户端P的离线消息,也可能不存在第二客户端P的离线消息。For example, the second client P subscribes to N topics, and sequentially determines the messages of the second client P in the offline time period (ba) from the message queues corresponding to the N topics, that is, the offline messages of the second client P . There may be offline messages of the second client P in the message queue, or there may be no offline messages of the second client P.
需要说明的是,同一个消息队列是所有订阅该topic的第二客户端共有的,由于不同第二客户端的上线/离线时间(即,离线时间段)不一致,因此,不同第二客户端对应的离线消息列表也可能存在区别。It should be noted that the same message queue is common to all second clients subscribing to the topic. Because the online/offline time (ie, offline time period) of different second clients is inconsistent, therefore, different second clients correspond to There may also be differences in the offline message list.
A4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。A4. Distribute the messages in the offline message list to the second client based on the second preset rule.
其中,所述第二预设规则包括:Wherein, the second preset rule includes:
根据所述离线消息列表中各离线消息的排序,依次将离线消息发送至第二客户端。According to the order of the offline messages in the offline message list, the offline messages are sequentially sent to the second client.
例如,对于某一个离线消息列表L而言,在离线消息列表L中,各离线消息的排序为:m1、m2、m3、…、m10,其中,m1为最新的离线消息,m10为最旧的离线消息,在分发离线消息的过程中,先分发最新的离线消息m1,然后分发离线消息m2,以此类推。For example, for a certain offline message list L, in the offline message list L, the order of each offline message is: m1, m2, m3, ..., m10, where m1 is the latest offline message and m10 is the oldest For offline messages, in the process of distributing offline messages, the latest offline message m1 is distributed first, then the offline message m2 is distributed, and so on.
优选地,本实施例中的所述第二预设规则还包括:Preferably, the second preset rule in this embodiment further includes:
当所述第二客户端对应多个离线消息列表时,确定各离线消息列表对应的topic的订阅时间,按照订阅时间从早到晚的顺序,依次分发各离线消息列表中的离线消息。When the second client corresponds to multiple offline message lists, the subscription time of the topic corresponding to each offline message list is determined, and the offline messages in each offline message list are distributed in order according to the order of the subscription time from early to late.
当针对一个第二客户端分发离线消息时,若存在多个topic对应的离线消息需要分发,按照订阅时间的早晚顺序确定各topic的先后顺序,然后顺序获取各topic的离线消息进行分发。When distributing offline messages for a second client, if there are offline messages corresponding to multiple topics that need to be distributed, determine the order of the topics according to the order of the subscription time, and then obtain the offline messages of each topic for distribution.
上述实施例提出的服务器1,接收第一客户端发布的消息,根据消息对应的topic、按照第一预设规则保存至对应的消息队列中,待第二客户端重新连接服务器时,确定第二客户端的离线时间段及离线时间段内的离线消息,按照第二预设规则将离线消息分发给第二客户端。每个topic对应一个消息列表,当有多个第二客户端重新连接服务器时,均从同一消息列表拉取某一个topic对应的离线消息,同时降低了时间复杂度和空间复杂度,提高离线消息分发效率。The server 1 proposed in the above embodiment receives the message published by the first client, saves it to the corresponding message queue according to the topic corresponding to the message according to the first preset rule, and determines the second when the second client reconnects to the server The offline time period of the client and the offline messages in the offline time period distribute the offline message to the second client according to the second preset rule. Each topic corresponds to a message list. When multiple second clients reconnect to the server, all offline messages corresponding to a topic are pulled from the same message list, while reducing time and space complexity, and improving offline messages. Distribution efficiency.
在其他实施例中,步骤A1中的所述“根据第一预设规则将该消息保存在该消息队列中”,包括:In other embodiments, the "save the message in the message queue according to the first preset rule" in step A1 includes:
当所述消息队列中消息数量为第一预设阈值时,每接收一条新的消息时,移除所述消息队列尾部的一条消息,并将所述新的消息放置在消息队列的头部。When the number of messages in the message queue is the first preset threshold, each time a new message is received, a message at the end of the message queue is removed, and the new message is placed at the head of the message queue.
例如,预先设置消息队列的最大容量为1000条,若消息队列中已经有1000条消息,每进来一条新消息,需将最旧的信息删除,然后保存这条新消息。For example, the maximum capacity of the message queue is set in advance. If there are already 1000 messages in the message queue, the oldest message needs to be deleted every time a new message comes in, and then the new message is saved.
在其他实施例中,所述“根据第一预设规则将该消息保存在该消息队列中”,还包括:In other embodiments, the "save the message in the message queue according to the first preset rule" also includes:
当所述消息队列中消息数量达到第二预设阈值时,生成预警信息发送至预设终端,接收该预设终端发出的对所述第一预设阈值进行更新的指令,响应该指令并执行第一预设阈值更新操作。When the number of messages in the message queue reaches the second preset threshold, generate warning information and send it to a preset terminal, receive an instruction issued by the preset terminal to update the first preset threshold, respond to the instruction and execute The first preset threshold update operation.
例如,预先设置消息队列的容量的警戒值900,所述第二预设阈值与第一预设阈值是相对应的。当消息队列中消息数量达到900时,向预设终端发出预警信息(例如,“消息队列中的消息数量即将到达上限,请及时作出调整”)。管理人员通过预设终端发出对第一预设阈值进行调整的指令,指令中包括第一预设阈值的更新值,例如,1200。通过该步骤保证了消息的完整性。For example, the warning value 900 of the capacity of the message queue is preset, and the second preset threshold corresponds to the first preset threshold. When the number of messages in the message queue reaches 900, a warning message is sent to the preset terminal (for example, "the number of messages in the message queue is about to reach the upper limit, please make adjustments in time"). The administrator sends an instruction to adjust the first preset threshold through the preset terminal, and the instruction includes the updated value of the first preset threshold, for example, 1200. This step ensures the integrity of the message.
可选地,在其他的实施例中,离线消息分发程序10还可以被分割为一个或者多个模块,一个或者多个模块被存储于存储器11中,并由一个或多个处理器(本实施例为处理器12)所执行,以完成本申请,本申请所称的模块是指能够完成特定功能的一系列计算机程序指令段。Optionally, in other embodiments, the offline message distribution program 10 may also be divided into one or more modules, and the one or more modules are stored in the memory 11 and controlled by one or more processors (this implementation The example is executed by the processor 12) to complete this application. The module referred to in this application refers to a series of computer program instruction segments capable of performing specific functions.
例如,参照图2所示,为图1中离线消息分发程序10的模块示意图,该实施例中,离线消息分发程序10可以被分割为第一接收110、第二接收模块120、查询模块130及分发模块140,所述模块110-140所实现的功能或操作步骤均与上文类似,此处不再详述,示例性地,例如其中:For example, referring to FIG. 2, which is a block diagram of the offline message distribution program 10 in FIG. 1, in this embodiment, the offline message distribution program 10 may be divided into a first receiving 110, a second receiving module 120, a query module 130, and The distribution module 140, the functions or operation steps implemented by the modules 110-140 are similar to the above, and will not be described in detail here, for example, for example:
第一接收模块110,用于接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消 息队列中;The first receiving module 110 is configured to receive a message published by the first client, determine the message queue corresponding to the message according to the attribute information of the message, and save the message in the message queue based on the first preset rule;
第二接收模块120,用于接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;The second receiving module 120 is configured to receive the connection instruction of the second client, obtain the online time and the last offline time of the second client, and determine the offline time period;
查询模块130,用于分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及The query module 130 is configured to determine one or more message queues corresponding to the second client respectively, and find out the messages of the second client in the offline time period from the one or more message queues, Generate an offline message list of the second client; and
分发模块140,用于基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。The distribution module 140 is configured to distribute the messages in the offline message list to the second client based on the second preset rule.
本申请提供一种基于MQTT协议的离线消息分发方法。参照图3所示,为本申请基于MQTT协议的离线消息分发方法较佳实施例的流程图。该方法可以由一个服务器执行,该服务器可以由软件和/或硬件实现。This application provides an offline message distribution method based on the MQTT protocol. Referring to FIG. 3, it is a flowchart of a preferred embodiment of an offline message distribution method based on the MQTT protocol of the present application. The method may be executed by a server, and the server may be implemented by software and/or hardware.
在本实施例中,所述基于MQTT协议的离线消息分发方法应用于服务器,该方法包括步骤S1-S4。In this embodiment, the offline message distribution method based on the MQTT protocol is applied to the server, and the method includes steps S1-S4.
S1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中。S1. Receive the message published by the first client, determine the message queue corresponding to the message according to the attribute information of the message, and save the message in the message queue based on the first preset rule.
其中,第一客户端为消息发布端。Among them, the first client is the message publishing end.
所述消息的属性信息中包括消息的时间戳、消息对应的topic(例如,天气)等信息。MQTT协议规定,消息发布端在发送消息至服务器时,需一并传递消息对应的tipic(主题),因此,服务器可直接获取消息对应的topic信息。The attribute information of the message includes information such as the time stamp of the message, the topic (for example, weather) corresponding to the message, and the like. The MQTT protocol stipulates that when sending a message to a server, the message publisher needs to transmit the tipic corresponding to the message, so the server can directly obtain the topic information corresponding to the message.
需要说明的是,每个topic对应一个消息队列。也就是说,消息队列的多少只与topic有关,与第二客户端(消息订阅端)的数量无关。It should be noted that each topic corresponds to a message queue. In other words, the number of message queues is only related to the topic, and has nothing to do with the number of second clients (message subscribers).
每条消息只属于一个topic,只有订阅了该topic的客户端才能收到该类消息。例如,topic为天气,第一客户端为发布天气消息的客户端,只有订阅了订阅了“天气”这个topic的第二客户端才能收到天气消息。当第一客户端发布一条天气消息后,服务器接收该条天气消息,根据其属性信息确定对应的topic“天气”,将这条消息保存至“天气”对应的消息队列中。Each message belongs to only one topic, and only clients that subscribe to the topic can receive this type of message. For example, the topic is weather, and the first client is a client that publishes weather messages. Only the second client that subscribes to the topic "weather" can receive weather messages. After the first client publishes a weather message, the server receives the weather message, determines the corresponding topic "weather" according to its attribute information, and saves the message to the message queue corresponding to "weather".
本实施例中,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:In this embodiment, the "save the message in the message queue according to the first preset rule" includes:
从所述消息的属性信息中获取时间戳,根据所述时间戳从早到晚的顺序,依次将所述消息保存在该消息对应的消息队列的头部。Obtain a time stamp from the attribute information of the message, and according to the order of the time stamp from early to late, sequentially save the message at the head of the message queue corresponding to the message.
以topic为“天气”为例,消息的属性信息中还包括每一条消息的时间戳,时间戳为消息的发布时间,即,服务器接收到消息的时间。接收到消息之后,将消息按照时间的早晚顺序进行排序,然后找到“天气”这一通topic对应的消息队列,依次将消息存储至消息队列的头部,即,消息队列头部的消息为发布时间最晚(最新)的消息,消息队列尾部的消息为发布时间最早(最旧)的消息。Taking the topic "weather" as an example, the attribute information of the message also includes a time stamp of each message. The time stamp is the time when the message was published, that is, the time when the server received the message. After receiving the message, sort the messages according to the order of time, and then find the message queue corresponding to the topic of "weather", and store the message to the head of the message queue in sequence, that is, the message at the head of the message queue is the publication time The latest (newest) message, and the message at the end of the message queue is the oldest (oldest) message.
需要说明的是,每条消息的有效时间(例如,7天)是预先设定的,当消息保存至消息队列的时间超过预先设定的有效时间时,将所述消息从消息队列中删除。It should be noted that the effective time (for example, 7 days) of each message is preset, and when the time for saving the message to the message queue exceeds the preset effective time, the message is deleted from the message queue.
S2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段。S2. Receive the connection instruction of the second client, obtain the online time and the last offline time of the second client, and determine the offline time period.
第二客户端为消息订阅端,通过第二客户端订阅一个或多个topic,并接收一个或多个topic对应的消息。第二客户端执行每次离线或者上线操作时,服务器均能获取并记录每一个第二客户端的每次离线或者上线的时间。用户通过第二客户端执行上线操作为触发离线消息的分发的信号。The second client is a message subscription end, subscribes to one or more topics through the second client, and receives messages corresponding to one or more topics. When the second client performs each offline or online operation, the server can obtain and record the time when each second client is offline or online. The online operation performed by the user through the second client is a signal that triggers the distribution of offline messages.
当侦测到第二客户端的连接指令时,获取当前第二客户端发出连接指令的时间作为离线时间段的结束时间,获取当前第二客户端发出连接指令前最近一次的离线时间,作为离线时间段的开始时间,根据开始时间及结束时间确定第二客户端本次的离线时间段。例如,本次上线时间为a,在本次上线前的离线时间为b,那么,第二客户端的离线时间段为b-a。When the connection instruction of the second client is detected, the time when the current second client issues the connection instruction is taken as the end time of the offline time period, and the latest offline time before the current second client issues the connection instruction as the offline time The start time of the segment determines the offline time period of the second client according to the start time and the end time. For example, the online time this time is a, and the offline time before this time online is b, then the offline time period of the second client is b-a.
对于不同的第二客户端,离线时间段可能相同,也可能不同。For different second clients, the offline time period may be the same or different.
S3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表。S3. Determine one or more message queues corresponding to the second client respectively, find the messages of the second client in the offline time period from the one or more message queues respectively, and generate the first The offline message list of the two clients.
具体地,所述“分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,作为所述第二客户端的离线消息”,包括:Specifically, the "finding messages of the second client in the offline time period from the one or more message queues respectively as offline messages of the second client" includes:
获取一个消息队列的第一条消息,从所述第一条消息的属性信息中获取时间戳,判断该时间戳是否在离线时间段内;Obtain the first message of a message queue, obtain a time stamp from the attribute information of the first message, and determine whether the time stamp is within the offline time period;
若是,则判断该第一条消息是离线消息,并依次获取该消息队列中的下一条消息重复上述步骤;If yes, it is determined that the first message is an offline message, and the next message in the message queue is sequentially obtained and the above steps are repeated;
若否,则判断该第一条消息不是离线消息,判断该消息队列中不存在所述第二客户端的离线消息。If not, it is determined that the first message is not an offline message, and it is determined that there is no offline message of the second client in the message queue.
由于一个消息队列中消息是按照发布时间的早晚顺序排序的,若发布的最晚的消息的发布时间都不在离线时间段内,那么队列中其他消息也一定不在离线时间段内。若发布最晚的消息的是离线消息,则依次往前,判断第二条消息是否在离线时间段内。通过最先判断最新的消息是否为离线消息,可减少很多多余的判断,进而节约资源。Since the messages in a message queue are sorted in the order of the release time, if the release time of the latest message is not in the offline period, then other messages in the queue must not be in the offline period. If the latest message is an offline message, then go forward in turn to determine whether the second message is within the offline time period. By first judging whether the latest message is an offline message, many redundant judgments can be reduced, thereby saving resources.
重复上述步骤,获取第二客户端在离线时间段内所有消息队列中的离线消息、并生成离线消息列表。离线消息列表中,最新的离线消息排在前面,最旧的离线消息排在后面。Repeat the above steps to obtain offline messages in all message queues of the second client in the offline time period, and generate an offline message list. In the offline message list, the latest offline message is ranked first, and the oldest offline message is ranked next.
本实施例中,第二客户端对应的消息队列的数量与第二客户端订阅的TOPIC数量相同。每个第二客户端订阅了N个TOPIC,即对应N个消息队列,其中,N为大于或等于0的整数。In this embodiment, the number of message queues corresponding to the second client is the same as the number of TOPICs subscribed by the second client. Each second client subscribes to N TOPICs, that is, corresponds to N message queues, where N is an integer greater than or equal to 0.
例如,第二客户端P订阅了N个topic,依次从N个topic对应的消息队列中确定第二客户端P在离线时间段(b-a)内的消息,即,第二客户端P的离线消息。消息队列中可能存在第二客户端P的离线消息,也可能不存在第二客户端P的离线消息。For example, the second client P subscribes to N topics, and sequentially determines the messages of the second client P in the offline time period (ba) from the message queues corresponding to the N topics, that is, the offline messages of the second client P . There may be offline messages of the second client P in the message queue, or there may be no offline messages of the second client P.
需要说明的是,同一个消息队列是所有订阅该topic的第二客户端共有的,由于不同第二客户端的上线/离线时间(即,离线时间段)不一致,因此,不同第二客户端对应的离线消息列表也可能存在区别。It should be noted that the same message queue is common to all second clients subscribing to the topic. Because the online/offline time (ie, offline time period) of different second clients is inconsistent, therefore, different second clients correspond to There may also be differences in the offline message list.
S4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。S4. Distribute the messages in the offline message list to the second client based on the second preset rule.
其中,所述第二预设规则包括:Wherein, the second preset rule includes:
根据所述离线消息列表中各离线消息的排序,依次将离线消息发送至第二客户端。According to the order of the offline messages in the offline message list, the offline messages are sequentially sent to the second client.
例如,对于某一个离线消息列表L而言,在离线消息列表L中,各离线消息的排序为:m1、m2、m3、…、m10,其中,m1为最新的离线消息,m10为最旧的离线消息,在分发离线消息的过程中,先分发最新的离线消息m1, 然后分发离线消息m2,以此类推。For example, for a certain offline message list L, in the offline message list L, the order of each offline message is: m1, m2, m3, ..., m10, where m1 is the latest offline message and m10 is the oldest For offline messages, in the process of distributing offline messages, the latest offline message m1 is distributed first, then the offline message m2 is distributed, and so on.
优选地,本实施例中的所述第二预设规则还包括:Preferably, the second preset rule in this embodiment further includes:
当所述第二客户端对应多个离线消息列表时,确定各离线消息列表对应的topic的订阅时间,按照订阅时间从早到晚的顺序,依次分发各离线消息列表中的离线消息。When the second client corresponds to multiple offline message lists, the subscription time of the topic corresponding to each offline message list is determined, and the offline messages in each offline message list are distributed in order according to the order of the subscription time from early to late.
当针对一个第二客户端分发离线消息时,若存在多个topic对应的离线消息需要分发,按照订阅时间的早晚顺序确定各topic的先后顺序,然后顺序获取各topic的离线消息进行分发。When distributing offline messages for a second client, if there are offline messages corresponding to multiple topics that need to be distributed, determine the order of the topics according to the order of the subscription time, and then obtain the offline messages of each topic for distribution.
上述实施例提出的基于MQTT协议的离线消息分发方法,接收第一客户端发布的消息,根据消息对应的topic、按照第一预设规则保存至对应的消息队列中,待第二客户端重新连接服务器时,确定第二客户端的离线时间段及离线时间段内的离线消息,按照第二预设规则将离线消息分发给第二客户端。每个topic对应一个消息列表,当有多个第二客户端重新连接服务器时,均从同一消息列表拉取某一个topic对应的离线消息,同时降低了时间复杂度和空间复杂度,提高离线消息分发效率。The offline message distribution method based on the MQTT protocol proposed in the above embodiment receives the message published by the first client, saves it to the corresponding message queue according to the topic corresponding to the message according to the first preset rule, and waits for the second client to reconnect The server determines the offline time period of the second client and the offline message within the offline time period, and distributes the offline message to the second client according to the second preset rule. Each topic corresponds to a message list. When multiple second clients reconnect to the server, all offline messages corresponding to a topic are pulled from the same message list, while reducing time and space complexity, and improving offline messages. Distribution efficiency.
在其他实施例中,步骤S1中的所述“根据第一预设规则将该消息保存在该消息队列中”,包括:In other embodiments, the "save the message in the message queue according to the first preset rule" in step S1 includes:
当所述消息队列中消息数量为第一预设阈值时,每接收一条新的消息时,移除所述消息队列尾部的一条消息,并将所述新的消息放置在消息队列的头部。When the number of messages in the message queue is the first preset threshold, each time a new message is received, a message at the end of the message queue is removed, and the new message is placed at the head of the message queue.
例如,预先设置消息队列的最大容量为1000条,若消息队列中已经有1000条消息,每进来一条新消息,需将最旧的信息删除,然后保存这条新消息。For example, the maximum capacity of the message queue is set in advance. If there are already 1000 messages in the message queue, the oldest message needs to be deleted every time a new message comes in, and then the new message is saved.
在其他实施例中,步骤S1中的所述“根据第一预设规则将该消息保存在该消息队列中”,还包括:In other embodiments, the "save the message in the message queue according to the first preset rule" in step S1 also includes:
当所述消息队列中消息数量达到第二预设阈值时,生成预警信息发送至预设终端,接收该预设终端发出的对所述第一预设阈值进行更新的指令,响应该指令并执行第一预设阈值更新操作。When the number of messages in the message queue reaches the second preset threshold, generate warning information and send it to a preset terminal, receive an instruction issued by the preset terminal to update the first preset threshold, respond to the instruction and execute The first preset threshold update operation.
例如,预先设置消息队列的容量的警戒值900,所述第二预设阈值与第一预设阈值是相对应的。当消息队列中消息数量达到900时,向预设终端发出 预警信息(例如,“消息队列中的消息数量即将到达上限,请及时作出调整”)。管理人员通过预设终端发出对第一预设阈值进行调整的指令,指令中包括第一预设阈值的更新值,例如,1200。通过该步骤保证了消息的完整性。For example, the warning value 900 of the capacity of the message queue is preset, and the second preset threshold corresponds to the first preset threshold. When the number of messages in the message queue reaches 900, a warning message is sent to the preset terminal (for example, "the number of messages in the message queue is about to reach the upper limit, please make adjustments in time"). The administrator sends an instruction to adjust the first preset threshold through the preset terminal, and the instruction includes the updated value of the first preset threshold, for example, 1200. This step ensures the integrity of the message.
上述实施例提出的基于MQTT协议的离线消息分发方法,通过对每个消息队列中消息的容量进行管控,节省存储空间的同时,保证离线消息的完整性。The offline message distribution method based on the MQTT protocol proposed in the above embodiment manages and controls the capacity of messages in each message queue to save storage space while ensuring the integrity of offline messages.
此外,本申请实施例还提出一种计算机可读存储介质,所述计算机可读存储介质中包括离线消息分发程序10,所述离线消息分发程序10被处理器执行时实现如下操作:In addition, an embodiment of the present application also provides a computer-readable storage medium, which includes an offline message distribution program 10, and when the offline message distribution program 10 is executed by a processor, the following operations are implemented:
A1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中;A1. Receive the message published by the first client, determine the message queue corresponding to the message according to the attribute information of the message, and save the message in the message queue based on the first preset rule;
A2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;A2. Receive the connection instruction of the second client, obtain the online time and the last offline time of the second client, and determine the offline time period;
A3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及A3. Determine one or more message queues corresponding to the second client respectively, find out the messages of the second client in the offline time period from the one or more message queues respectively, and generate the first The offline message list of the two clients; and
A4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。A4. Distribute the messages in the offline message list to the second client based on the second preset rule.
本申请之计算机可读存储介质的具体实施方式与上述离线消息分发方法的具体实施方式大致相同,在此不再赘述。The specific implementation of the computer-readable storage medium of the present application is substantially the same as the specific implementation of the offline message distribution method described above, and details are not described herein again.
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。The sequence numbers of the above embodiments of the present application are for description only, and do not represent the advantages and disadvantages of the embodiments.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。It should be noted that in this article, the terms "include", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements It also includes other elements that are not explicitly listed, or include elements inherent to such processes, devices, objects, or methods. Without more restrictions, the element defined by the sentence "include one..." does not exclude that there are other identical elements in the process, device, article or method that includes the element.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述 实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。Through the description of the above embodiments, those skilled in the art can clearly understand that the methods in the above embodiments can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware, but in many cases the former is better Implementation. Based on this understanding, the technical solution of the present application can be embodied in the form of a software product in essence or part that contributes to the prior art, and the computer software product is stored in a storage medium (such as ROM/RAM) as described above , Magnetic disk, optical disk), including several instructions to enable a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to perform the method described in each embodiment of the present application.
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其它相关的技术领域,均同理包括在本申请的专利保护范围内。The above are only preferred embodiments of the present application, and do not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made by the description and drawings of this application, or directly or indirectly used in other related technical fields The same reason is included in the patent protection scope of this application.

Claims (20)

  1. 一种基于MQTT协议的离线消息分发方法,应用于服务器,其特征在于,所述方法包括:An offline message distribution method based on the MQTT protocol, applied to a server, characterized in that the method includes:
    S1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中;S1. Receive the message published by the first client, determine the message queue corresponding to the message according to the attribute information of the message, and save the message in the message queue based on the first preset rule;
    S2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;S2. Receive the connection instruction of the second client, obtain the online time and the last offline time of the second client, and determine the offline time period;
    S3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及S3. Determine one or more message queues corresponding to the second client respectively, find the messages of the second client in the offline time period from the one or more message queues respectively, and generate the first The offline message list of the two clients; and
    S4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。S4. Distribute the messages in the offline message list to the second client based on the second preset rule.
  2. 根据权利要求1所述的离线消息分发方法,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:从所述消息的属性信息中获取时间戳,根据所述时间戳从早到晚的顺序,依次将所述消息保存在该消息对应的消息队列的头部。The offline message distribution method according to claim 1, wherein the "save the message in the message queue according to the first preset rule" includes: obtaining a time stamp from the attribute information of the message, According to the order of the timestamps from early to late, the messages are sequentially saved at the head of the message queue corresponding to the messages.
  3. 根据权利要求1所述的离线消息分发方法,其特征在于,所述“分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,作为所述第二客户端的离线消息”,包括:The offline message distribution method according to claim 1, wherein the "finding messages of the second client in the offline time period from the one or more message queues as the first "Offline messages of the second client", including:
    获取一个消息队列的第一条消息,从所述第一条消息的属性信息中获取时间戳,判断该时间戳是否在离线时间段内;Obtain the first message of a message queue, obtain a time stamp from the attribute information of the first message, and determine whether the time stamp is within the offline time period;
    若是,则判断该第一条消息是离线消息,并依次获取该消息队列中的下一条消息重复执行判断步骤;If yes, it is judged that the first message is an offline message, and the next message in the message queue is sequentially obtained and the judgment step is repeated;
    若否,则判断该第一条消息不是离线消息,判断该消息队列中不存在所述第二客户端的离线消息。If not, it is determined that the first message is not an offline message, and it is determined that there is no offline message of the second client in the message queue.
  4. 根据权利要求3所述的离线消息分发方法,其特征在于,所述第二预设规则包括:根据所述离线消息列表中各离线消息的排序,依次将离线消息发送至第二客户端。The offline message distribution method according to claim 3, wherein the second preset rule includes: according to the order of the offline messages in the offline message list, sequentially sending the offline messages to the second client.
  5. 根据权利要求4所述的离线消息分发方法,其特征在于,所述第二预 设规则还包括:当所述第二客户端对应多个离线消息列表时,确定各离线消息列表对应的主题的订阅时间,按照订阅时间从早到晚的顺序,依次分发各离线消息列表中的离线消息。The offline message distribution method according to claim 4, wherein the second preset rule further comprises: when the second client corresponds to a plurality of offline message lists, determining the theme of the topic corresponding to each offline message list Subscription time, according to the order of the subscription time from morning to night, distribute the offline messages in each offline message list in turn.
  6. 根据权利要求3所述的离线消息分发方法,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:当所述消息队列中消息数量为第一预设阈值时,每接收一条新的消息时,移除所述消息队列尾部的一条消息,并将所述新的消息放置在消息队列的头部。The offline message distribution method according to claim 3, wherein the "save the message in the message queue according to the first preset rule" includes: when the number of messages in the message queue is the first When the threshold is set, each time a new message is received, a message at the end of the message queue is removed, and the new message is placed at the head of the message queue.
  7. 根据权利要求6所述的离线消息分发方法,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,还包括:The offline message distribution method according to claim 6, wherein the "save the message in the message queue according to the first preset rule" further includes:
    当所述消息队列中消息数量达到第二预设阈值时,生成预警信息发送至预设终端,并接收该预设终端发出的对所述第一预设阈值进行更新的指令,响应该指令并执行第一预设阈值更新操作。When the number of messages in the message queue reaches a second preset threshold, generate warning information and send it to a preset terminal, and receive an instruction issued by the preset terminal to update the first preset threshold, respond to the instruction and Perform the first preset threshold update operation.
  8. 一种服务器,其特征在于,该服务器包括:存储器、处理器,所述存储器上存储有可在所述处理器上运行的离线消息分发程序,所述离线消息分发程序被所述处理器执行时,可实现如下步骤:A server, characterized in that the server includes: a memory and a processor, and the memory stores an offline message distribution program that can run on the processor, when the offline message distribution program is executed by the processor , The following steps can be achieved:
    A1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中;A1. Receive the message published by the first client, determine the message queue corresponding to the message according to the attribute information of the message, and save the message in the message queue based on the first preset rule;
    A2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;A2. Receive the connection instruction of the second client, obtain the online time and the last offline time of the second client, and determine the offline time period;
    A3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及A3. Determine one or more message queues corresponding to the second client respectively, find out the messages of the second client in the offline time period from the one or more message queues respectively, and generate the first The offline message list of the two clients; and
    A4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。A4. Distribute the messages in the offline message list to the second client based on the second preset rule.
  9. 根据权利要求8所述的服务器,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:从所述消息的属性信息中获取时间戳,根据所述时间戳从早到晚的顺序,依次将所述消息保存在该消息对应的消息队列的头部。The server according to claim 8, wherein the "save the message in the message queue according to the first preset rule" includes: obtaining a time stamp from attribute information of the message, according to the In the order of timestamps from early to late, the message is sequentially saved at the head of the message queue corresponding to the message.
  10. 根据权利要求8所述的服务器,其特征在于,所述“分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,作为所述第 二客户端的离线消息”,包括:The server according to claim 8, wherein the "find messages of the second client in the offline time period from the one or more message queues respectively, as the second client's Offline messages", including:
    获取一个消息队列的第一条消息,从所述第一条消息的属性信息中获取时间戳,判断该时间戳是否在离线时间段内;Obtain the first message of a message queue, obtain a time stamp from the attribute information of the first message, and determine whether the time stamp is within the offline time period;
    若是,则判断该第一条消息是离线消息,并依次获取该消息队列中的下一条消息重复执行判断步骤;If yes, it is judged that the first message is an offline message, and the next message in the message queue is sequentially obtained and the judgment step is repeated;
    若否,则判断该第一条消息不是离线消息,判断该消息队列中不存在所述第二客户端的离线消息。If not, it is determined that the first message is not an offline message, and it is determined that there is no offline message of the second client in the message queue.
  11. 根据权利要求10所述的服务器,其特征在于,所述第二预设规则包括:根据所述离线消息列表中各离线消息的排序,依次将离线消息发送至第二客户端。The server according to claim 10, wherein the second preset rule includes: according to the order of each offline message in the offline message list, sequentially sending offline messages to the second client.
  12. 根据权利要求11所述的服务器,其特征在于,所述第二预设规则还包括:当所述第二客户端对应多个离线消息列表时,确定各离线消息列表对应的主题的订阅时间,按照订阅时间从早到晚的顺序,依次分发各离线消息列表中的离线消息。The server according to claim 11, wherein the second preset rule further comprises: when the second client corresponds to multiple offline message lists, determining the subscription time of the topic corresponding to each offline message list, According to the order of the subscription time from early to late, the offline messages in each offline message list are distributed in sequence.
  13. 根据权利要求10所述的服务器,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:当所述消息队列中消息数量为第一预设阈值时,每接收一条新的消息时,移除所述消息队列尾部的一条消息,并将所述新的消息放置在消息队列的头部。The server according to claim 10, wherein the "save the message in the message queue according to the first preset rule" includes: when the number of messages in the message queue is the first preset threshold Each time a new message is received, a message at the end of the message queue is removed, and the new message is placed at the head of the message queue.
  14. 根据权利要求13所述的服务器,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,还包括:The server according to claim 13, wherein the "save the message in the message queue according to the first preset rule" further includes:
    当所述消息队列中消息数量达到第二预设阈值时,生成预警信息发送至预设终端,并接收该预设终端发出的对所述第一预设阈值进行更新的指令,响应该指令并执行第一预设阈值更新操作。When the number of messages in the message queue reaches a second preset threshold, generate warning information and send it to a preset terminal, and receive an instruction issued by the preset terminal to update the first preset threshold, respond to the instruction and Perform the first preset threshold update operation.
  15. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中包括离线消息分发程序,所述离线消息分发程序被处理器执行时,可实现如下步骤:A computer-readable storage medium, characterized in that the computer-readable storage medium includes an offline message distribution program. When the offline message distribution program is executed by a processor, the following steps may be implemented:
    A1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中;A1. Receive the message published by the first client, determine the message queue corresponding to the message according to the attribute information of the message, and save the message in the message queue based on the first preset rule;
    A2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;A2. Receive the connection instruction of the second client, obtain the online time and the last offline time of the second client, and determine the offline time period;
    A3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及A3. Determine one or more message queues corresponding to the second client respectively, find out the messages of the second client in the offline time period from the one or more message queues respectively, and generate the first The offline message list of the two clients; and
    A4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。A4. Distribute the messages in the offline message list to the second client based on the second preset rule.
  16. 根据权利要求15所述的计算机可读存储介质,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:从所述消息的属性信息中获取时间戳,根据所述时间戳从早到晚的顺序,依次将所述消息保存在该消息对应的消息队列的头部。The computer-readable storage medium according to claim 15, wherein the "save the message in the message queue according to the first preset rule" includes: obtaining a time stamp from attribute information of the message , According to the order of the timestamps from early to late, save the message in sequence at the head of the message queue corresponding to the message.
  17. 根据权利要求15所述的计算机可读存储介质,其特征在于,所述“分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,作为所述第二客户端的离线消息”,包括:The computer-readable storage medium according to claim 15, wherein the "find messages of the second client in the offline time period from the one or more message queues respectively, as the Offline message of the second client", including:
    获取一个消息队列的第一条消息,从所述第一条消息的属性信息中获取时间戳,判断该时间戳是否在离线时间段内;Obtain the first message of a message queue, obtain a time stamp from the attribute information of the first message, and determine whether the time stamp is within the offline time period;
    若是,则判断该第一条消息是离线消息,并依次获取该消息队列中的下一条消息重复执行判断步骤;If yes, it is judged that the first message is an offline message, and the next message in the message queue is sequentially obtained and the judgment step is repeated;
    若否,则判断该第一条消息不是离线消息,判断该消息队列中不存在所述第二客户端的离线消息。If not, it is determined that the first message is not an offline message, and it is determined that there is no offline message of the second client in the message queue.
  18. 根据权利要求17所述的计算机可读存储介质,其特征在于,所述第二预设规则包括:根据所述离线消息列表中各离线消息的排序,依次将离线消息发送至第二客户端。The computer-readable storage medium according to claim 17, wherein the second preset rule includes: according to the order of the offline messages in the offline message list, sending offline messages to the second client in sequence.
  19. 根据权利要求18所述的计算机可读存储介质,其特征在于,所述第二预设规则还包括:当所述第二客户端对应多个离线消息列表时,确定各离线消息列表对应的主题的订阅时间,按照订阅时间从早到晚的顺序,依次分发各离线消息列表中的离线消息。The computer-readable storage medium according to claim 18, wherein the second preset rule further comprises: when the second client corresponds to multiple offline message lists, determining the theme corresponding to each offline message list For the subscription time, the offline messages in each offline message list are distributed in order according to the order of the subscription time from morning to night.
  20. 根据权利要求17所述的计算机可读存储介质,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:当所述消息队列中消息数量为第一预设阈值时,每接收一条新的消息时,移除所述消息队列尾部的一条消息,并将所述新的消息放置在消息队列的头部。The computer-readable storage medium according to claim 17, wherein the "save the message in the message queue according to the first preset rule" includes: when the number of messages in the message queue is the first When the threshold is preset, each time a new message is received, a message at the end of the message queue is removed, and the new message is placed at the head of the message queue.
PCT/CN2019/117333 2019-01-04 2019-11-12 Offline message distribution method, server and storage medium WO2020140614A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910007206.XA CN109756417B (en) 2019-01-04 2019-01-04 Offline message distribution method, server and storage medium
CN201910007206.X 2019-01-04

Publications (1)

Publication Number Publication Date
WO2020140614A1 true WO2020140614A1 (en) 2020-07-09

Family

ID=66405363

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/117333 WO2020140614A1 (en) 2019-01-04 2019-11-12 Offline message distribution method, server and storage medium

Country Status (2)

Country Link
CN (1) CN109756417B (en)
WO (1) WO2020140614A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114338805A (en) * 2021-12-29 2022-04-12 金卡智能集团股份有限公司 Data processing method and device and server
CN114760259A (en) * 2022-04-27 2022-07-15 深圳小湃科技有限公司 Offline message sending method and device, electronic equipment and readable storage medium

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109756417B (en) * 2019-01-04 2022-08-30 平安科技(深圳)有限公司 Offline message distribution method, server and storage medium
CN110391974A (en) * 2019-08-01 2019-10-29 北京云中融信网络科技有限公司 A kind of message synchronization method, server-side, terminal and system
CN112751892B (en) * 2019-10-30 2022-06-17 腾讯科技(深圳)有限公司 Information distribution method, device, equipment and storage medium
CN111212135A (en) * 2019-12-31 2020-05-29 北京金山云网络技术有限公司 Message subscription method, device, system, electronic equipment and storage medium
CN111654428B (en) * 2020-06-05 2022-05-17 天津卓朗科技发展有限公司 Offline message processing method and device and server
CN112422369B (en) * 2020-11-19 2022-08-02 青岛海尔科技有限公司 Method and device for determining offline time, storage medium and electronic device
CN112764947B (en) * 2021-01-15 2023-12-26 百果园技术(新加坡)有限公司 Message data pulling method, device, equipment and storage medium
CN115297076B (en) * 2022-08-01 2024-03-19 招商局金融科技有限公司 Offline message pulling method and device, computer equipment and storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016012751A1 (en) * 2014-07-22 2016-01-28 Simple Matters Limited A chat system
CN105306413A (en) * 2014-06-13 2016-02-03 北京视联动力国际信息技术有限公司 Information release method and system, articulated naturality web server and release terminal
CN108023923A (en) * 2016-11-04 2018-05-11 中兴通讯股份有限公司 The processing method and processing device of deferred information
CN108416006A (en) * 2018-02-28 2018-08-17 百度在线网络技术(北京)有限公司 Information off-line recommends method, apparatus, client, server and storage medium
CN108494815A (en) * 2018-02-06 2018-09-04 北京极智感科技有限公司 A kind of method and system of transmission message
CN108768826A (en) * 2018-05-16 2018-11-06 华南理工大学 Based on the message route method under MQTT and Kafka high concurrent scenes
CN109756417A (en) * 2019-01-04 2019-05-14 平安科技(深圳)有限公司 Offline message distribution method, server and storage medium

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9628413B2 (en) * 2012-12-14 2017-04-18 International Business Machines Corporation Low latency messaging chat server
US10616289B2 (en) * 2016-02-16 2020-04-07 LinkTime Corp. System and method for managing online group chat
CN106385410A (en) * 2016-09-08 2017-02-08 四川长虹电器股份有限公司 Intelligent household appliance control system based on MQTT
CN106656751A (en) * 2016-12-05 2017-05-10 北京中交兴路信息科技有限公司 Data communication method and device
CN108390933B (en) * 2018-02-26 2021-03-09 广州方硅信息技术有限公司 Message distribution method, device, server and storage medium
CN108965265A (en) * 2018-06-26 2018-12-07 四川斐讯信息技术有限公司 A kind of chat method and system based on MQTT agreement

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105306413A (en) * 2014-06-13 2016-02-03 北京视联动力国际信息技术有限公司 Information release method and system, articulated naturality web server and release terminal
WO2016012751A1 (en) * 2014-07-22 2016-01-28 Simple Matters Limited A chat system
CN108023923A (en) * 2016-11-04 2018-05-11 中兴通讯股份有限公司 The processing method and processing device of deferred information
CN108494815A (en) * 2018-02-06 2018-09-04 北京极智感科技有限公司 A kind of method and system of transmission message
CN108416006A (en) * 2018-02-28 2018-08-17 百度在线网络技术(北京)有限公司 Information off-line recommends method, apparatus, client, server and storage medium
CN108768826A (en) * 2018-05-16 2018-11-06 华南理工大学 Based on the message route method under MQTT and Kafka high concurrent scenes
CN109756417A (en) * 2019-01-04 2019-05-14 平安科技(深圳)有限公司 Offline message distribution method, server and storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114338805A (en) * 2021-12-29 2022-04-12 金卡智能集团股份有限公司 Data processing method and device and server
CN114338805B (en) * 2021-12-29 2023-05-16 金卡智能集团股份有限公司 Data processing method and server
CN114760259A (en) * 2022-04-27 2022-07-15 深圳小湃科技有限公司 Offline message sending method and device, electronic equipment and readable storage medium
CN114760259B (en) * 2022-04-27 2024-01-16 深圳小湃科技有限公司 Offline message sending method and device, electronic equipment and readable storage medium

Also Published As

Publication number Publication date
CN109756417B (en) 2022-08-30
CN109756417A (en) 2019-05-14

Similar Documents

Publication Publication Date Title
WO2020140614A1 (en) Offline message distribution method, server and storage medium
US20220150193A1 (en) Push notification delivery system
WO2020211344A1 (en) Mqtt-based message distribution method, server, apparatus, and storage medium
US8635250B2 (en) Methods and systems for deleting large amounts of data from a multitenant database
US20140156586A1 (en) Big-fast data connector between in-memory database system and data warehouse system
CN110546923A (en) selective distribution of messages in a scalable real-time messaging system
CN108390933B (en) Message distribution method, device, server and storage medium
US11488082B2 (en) Monitoring and verification system for end-to-end distribution of messages
US11553256B2 (en) Method and device for processing message in live broadcast room
CN110851248A (en) Asynchronous task data processing method and device and computer readable storage medium
US20160352649A1 (en) Methods for an automatic scaling of data consumers and apparatuses using the same
WO2019061647A1 (en) Queue message processing method and device, terminal device and medium
CN107784085B (en) Data list exporting method and terminal thereof
CN113783913A (en) Message pushing management method and device
WO2022142008A1 (en) Data processing method and apparatus, electronic device, and storage medium
CN116880990A (en) Task execution method, device, electronic equipment and computer readable storage medium
CN113127923A (en) Method and device for managing authority
CN107229424B (en) Data writing method for distributed storage system and distributed storage system
US20140330889A1 (en) Data stage-in for network nodes
CN111459981B (en) Query task processing method, device, server and system
WO2020238057A1 (en) Redis-based mqtt cluster monitoring method, apparatus, and storage medium
CN110019671B (en) Method and system for processing real-time message
CN113556370A (en) Service calling method and device
CN113572704A (en) Information processing method, production end, consumption end and server
WO2020024375A1 (en) Data transmission management method and device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19907391

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19907391

Country of ref document: EP

Kind code of ref document: A1