WO2020140614A1 - 离线消息分发方法、服务器及存储介质 - Google Patents
离线消息分发方法、服务器及存储介质 Download PDFInfo
- 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
- Legal status (The legal status 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 status listed.)
- Ceased
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L65/00—Network arrangements, protocols or services for supporting real-time applications in data packet communication
- H04L65/40—Support 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.
Landscapes
- Engineering & Computer Science (AREA)
- Multimedia (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Information Transfer Between Computers (AREA)
Abstract
本申请揭露了一种基于MQTT协议的离线消息分发方法,该方法包括:接收第一客户端发布的消息,将该消息保存在消息队列中;接收第二客户端的连接指令,确定第二客户端的离线时间段;分别确定所述第二客户端对应的离线时间段内的消息,生成所述第二客户端的离线消息列表;及,将所述离线消息列表中的消息分发至所述第二客户端。本申请还揭露了一种服务器及计算机存储介质。利用本申请,降低了时间复杂度和空间复杂度,提高离线消息分发效率。
Description
本申请基于巴黎公约申明享有2019年01月04日递交的申请号为CN 201910007206.X、名称为“离线消息分发方法、服务器及存储介质”的中国专利申请的优先权,该中国专利申请的整体内容以参考的方式结合在本申请中。
本申请涉及数据处理技术领域,尤其涉及一种基于MQTT协议的离线消息分发方法、服务器及计算机可读存储介质。
早在1999年,IBM的Andy Stanford-Clark博士以及Arcom公司ArlenNipper博士发明了MQTT(Message Queuing Telemetry Transport,消息队列遥测传输)技术。目前,国内很多企业都广泛使用MQTT作为Android手机客户端与服务器端推送消息的协议。其中,Sohu,Cmstop手机客户端中均有使用到MQTT作为消息推送消息。
MQTT协议中有一个功能是离线消息的处理。在市场上的很多MQTT产品对离线消息的处理都不一样,对于像ActiveMQ,moquette,apolo等开源MQTT服务端项目的离线消息都是针对一个客户端一个离线消息列表进行分发。不管从时间复杂度还是孔家复杂度考虑,客户端数量很大、离线消息数量很大时,不止会让服务器处理性能变差,还会浪费很多存储空间。
发明内容
鉴于以上内容,本申请提供一种基于MQTT协议的离线消息分发方法、服务器及计算机可读存储介质,其主要目的在于降低了时间复杂度和空间复杂度,提高离线消息分发效率。
为实现上述目的,本申请提供一种基于MQTT协议的离线消息分发方法,该方法包括:
S1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中;
S2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;
S3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及
S4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。
此外,本申请还提供一种服务器,该服务器包括:存储器、处理器,所述存储器上存储有可在所述处理器上运行的离线消息分发程序,所述离线消息分发程序被所述处理器执行时,可实现如上所述离线消息分发方法中的任意步骤。
此外,为实现上述目的,本申请还提供一种计算机可读存储介质,所述计算机可读存储介质中包括离线消息分发程序,所述离线消息分发程序被处理器执行时,可实现如上所述离线消息分发方法中的任意步骤。
本申请提出的离线消息分发方法、服务器及计算机可读存储介质,接收第一客户端发布的消息,根据消息对应的topic(主题)、按照第一预设规则保存至对应的消息队列中,待第二客户端重新连接服务器时,确定第二客户端的离线时间段及离线时间段内的离线消息,按照第二预设规则将离线消息分发给第二客户端。每个topic对应一个消息列表,当有多个第二客户端重新连接服务器时,均从同一消息列表拉取某一个topic对应的离线消息,同时降低了时间复杂度和空间复杂度,提高离线消息分发效率。
图1为本申请服务器较佳实施例的示意图;
图2为图1中离线消息分发程序的程序模块示意图;
图3为本申请离线消息分发方法较佳实施例的流程图。
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
本申请提供一种服务器。参照图1所示,为本申请服务器较佳实施例的示意图。
所述服务器1应用于一种基于MQTT协议的消息分发系统(图中未标出),该系统包括:包括多个所述服务器1的服务器集群、第一客户端(图中未标出)、第二客户端(图中未标出)。其中,所述第一客户端为消息发布端,用于发布消息至服务器1;所述第二客户端为消息订阅端,第二客户端只有在订阅了第一客户端对应的topic(主题,例如,天气)后才能接收到第一客户端发布的消息。所述第一客户端和第二客户端可以是智能手机、平板电脑、便携计算机、桌上型计算机等具有数据处理功能的终端设备。
在其他实施例中,所述消息分发系统还包括:负载均衡设备(图中未标出)。
所述负载均衡设备包括:第一负载均衡设备(图中未标出)及第二负载均衡设备(图中未标出)。需要说明的是,所述第一负载均衡设备及第二负载均衡设备可以是同一个负载均衡设备,也可以是不同的额负载均衡设备。
其中,第一负载均衡设备用于接收第一客户端发布的消息,并将该消息基于预设负载均衡规则均衡分配给服务器集群中的每台服务器1进行存储。
第二负载均衡设备用于接收第二客户端发出的连接指令,并将该连接指令基于预设负载均衡规则均衡分配给服务器集群中的每台服务器1进行处理。
鉴于第一客户端发布的消息都是存储到中央存储的,因此,每台服务器都能识别每台第二客户端对应的所有消息,并分发给对应的第二客户端。
所述预设负载均衡规则为:根据所述服务器集群中各服务器1的负载进行分配。例如,分配给实时负载最小的服务器进行处理。
在本实施例中,所述服务器1还可以是机架式服务器、刀片式服务器、塔式服务器或机柜式服务器。
在图1中,所述服务器1包括存储器11、处理器12,及网络接口13。
其中,存储器11至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁 性存储器、磁盘、光盘等。存储器11在一些实施例中可以是所述服务器1的内部存储单元,例如该服务器1的硬盘。存储器11在另一些实施例中也可以是所述服务器1的外部存储设备,例如该服务器1上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,存储器11还可以既包括该服务器1的内部存储单元也包括外部存储设备。
存储器11不仅可以用于存储安装于该服务器1的应用软件及各类数据,例如离线消息分发程序10等,还可以用于暂时地存储已经输出或者将要输出的数据。
处理器12在一些实施例中可以是一中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器11中存储的程序代码或处理数据,例如,离线消息分发程序10等。
网络接口13可选的可以包括标准的有线接口、无线接口(如WI-FI接口),通常用于在该服务器1与其他电子设备之间建立通信连接。例如,与客户端(图中未标注)进行数据传输。
图1仅示出了具有组件11-13的服务器1,本领域技术人员可以理解的是,图1示出的结构并不构成对服务器1的限定,可以包括比图示更少或者更多的部件,或者组合某些部件,或者不同的部件布置。
可选地,该服务器1还可以包括用户接口,用户接口可以包括显示器(Display)、输入单元比如键盘(Keyboard),可选的用户接口还可以包括标准的有线接口、无线接口。
可选地,在一些实施例中,显示器可以是LED显示器、液晶显示器、触控式液晶显示器以及有机发光二极管(Organic Light-Emitting Diode,OLED)触摸器等。其中,显示器也可以称为显示屏或显示单元,用于显示在服务器1中处理的信息以及用于显示可视化的用户界面。
在图1所示的服务器1实施例中,作为一种计算机存储介质的存储器11中存储离线消息分发程序10的程序代码,处理器12执行离线消息分发程序10的程序代码时,实现步骤:A1-A4。
A1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对 应的消息队列,并基于第一预设规则将该消息保存在该消息队列中。
其中,第一客户端为消息发布端。
所述消息的属性信息中包括消息的时间戳、消息对应的topic(例如,天气)等信息。MQTT协议规定,消息发布端在发送消息至服务器时,需一并传递消息对应的tipic(主题),因此,服务器可直接获取消息对应的topic信息。
需要说明的是,每个topic对应一个消息队列。也就是说,消息队列的多少只与topic有关,与第二客户端(消息订阅端)的数量无关。
每条消息只属于一个topic,只有订阅了该topic的客户端才能收到该类消息。例如,topic为天气,第一客户端为发布天气消息的客户端,只有订阅了订阅了“天气”这个topic的第二客户端才能收到天气消息。当第一客户端发布一条天气消息后,服务器接收该条天气消息,根据其属性信息确定对应的topic“天气”,将这条消息保存至“天气”对应的消息队列中。
本实施例中,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:
从所述消息的属性信息中获取时间戳,根据所述时间戳从早到晚的顺序,依次将所述消息保存在该消息对应的消息队列的头部。
以topic为“天气”为例,消息的属性信息中还包括每一条消息的时间戳,时间戳为消息的发布时间,即,服务器接收到消息的时间。接收到消息之后,将消息按照时间的早晚顺序进行排序,然后找到“天气”这一通topic对应的消息队列,依次将消息存储至消息队列的头部,即,消息队列头部的消息为发布时间最晚(最新)的消息,消息队列尾部的消息为发布时间最早(最旧)的消息。
需要说明的是,每条消息的有效时间(例如,7天)是预先设定的,当消息保存至消息队列的时间超过预先设定的有效时间时,将所述消息从消息队列中删除。
A2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段。
第二客户端为消息订阅端,通过第二客户端订阅一个或多个topic,并接收一个或多个topic对应的消息。第二客户端执行每次离线或者上线操作时, 服务器均能获取并记录每一个第二客户端的每次离线或者上线的时间。用户通过第二客户端执行上线操作为触发离线消息的分发的信号。
当侦测到第二客户端的连接指令时,获取当前第二客户端发出连接指令的时间作为离线时间段的结束时间,获取当前第二客户端发出连接指令前最近一次的离线时间,作为离线时间段的开始时间,根据开始时间及结束时间确定第二客户端本次的离线时间段。例如,本次上线时间为a,在本次上线前的离线时间为b,那么,第二客户端的离线时间段为b-a。
对于不同的第二客户端,离线时间段可能相同,也可能不同。
A3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表。
具体地,所述“分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,作为所述第二客户端的离线消息”,包括:
获取一个消息队列的第一条消息,从所述第一条消息的属性信息中获取时间戳,判断该时间戳是否在离线时间段内;
若是,则判断该第一条消息是离线消息,并依次获取该消息队列中的下一条消息重复上述步骤;
若否,则判断该第一条消息不是离线消息,判断该消息队列中不存在所述第二客户端的离线消息。
由于一个消息队列中消息是按照发布时间的早晚顺序排序的,若发布的最晚的消息的发布时间都不在离线时间段内,那么队列中其他消息也一定不在离线时间段内。若发布最晚的消息的是离线消息,则依次往前,判断第二条消息是否在离线时间段内。通过最先判断最新的消息是否为离线消息,可减少很多多余的判断,进而节约资源。
重复上述步骤,获取第二客户端在离线时间段内所有消息队列中的离线消息、并生成离线消息列表。离线消息列表中,最新的离线消息排在前面,最旧的离线消息排在后面。
本实施例中,第二客户端对应的消息队列的数量与第二客户端订阅的TOPIC数量相同。每个第二客户端订阅了N个TOPIC,即对应N个消息队列,其中,N为大于或等于0的整数。
例如,第二客户端P订阅了N个topic,依次从N个topic对应的消息队列中确定第二客户端P在离线时间段(b-a)内的消息,即,第二客户端P的离线消息。消息队列中可能存在第二客户端P的离线消息,也可能不存在第二客户端P的离线消息。
需要说明的是,同一个消息队列是所有订阅该topic的第二客户端共有的,由于不同第二客户端的上线/离线时间(即,离线时间段)不一致,因此,不同第二客户端对应的离线消息列表也可能存在区别。
A4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。
其中,所述第二预设规则包括:
根据所述离线消息列表中各离线消息的排序,依次将离线消息发送至第二客户端。
例如,对于某一个离线消息列表L而言,在离线消息列表L中,各离线消息的排序为:m1、m2、m3、…、m10,其中,m1为最新的离线消息,m10为最旧的离线消息,在分发离线消息的过程中,先分发最新的离线消息m1,然后分发离线消息m2,以此类推。
优选地,本实施例中的所述第二预设规则还包括:
当所述第二客户端对应多个离线消息列表时,确定各离线消息列表对应的topic的订阅时间,按照订阅时间从早到晚的顺序,依次分发各离线消息列表中的离线消息。
当针对一个第二客户端分发离线消息时,若存在多个topic对应的离线消息需要分发,按照订阅时间的早晚顺序确定各topic的先后顺序,然后顺序获取各topic的离线消息进行分发。
上述实施例提出的服务器1,接收第一客户端发布的消息,根据消息对应的topic、按照第一预设规则保存至对应的消息队列中,待第二客户端重新连接服务器时,确定第二客户端的离线时间段及离线时间段内的离线消息,按照第二预设规则将离线消息分发给第二客户端。每个topic对应一个消息列表,当有多个第二客户端重新连接服务器时,均从同一消息列表拉取某一个topic对应的离线消息,同时降低了时间复杂度和空间复杂度,提高离线消息分发效率。
在其他实施例中,步骤A1中的所述“根据第一预设规则将该消息保存在该消息队列中”,包括:
当所述消息队列中消息数量为第一预设阈值时,每接收一条新的消息时,移除所述消息队列尾部的一条消息,并将所述新的消息放置在消息队列的头部。
例如,预先设置消息队列的最大容量为1000条,若消息队列中已经有1000条消息,每进来一条新消息,需将最旧的信息删除,然后保存这条新消息。
在其他实施例中,所述“根据第一预设规则将该消息保存在该消息队列中”,还包括:
当所述消息队列中消息数量达到第二预设阈值时,生成预警信息发送至预设终端,接收该预设终端发出的对所述第一预设阈值进行更新的指令,响应该指令并执行第一预设阈值更新操作。
例如,预先设置消息队列的容量的警戒值900,所述第二预设阈值与第一预设阈值是相对应的。当消息队列中消息数量达到900时,向预设终端发出预警信息(例如,“消息队列中的消息数量即将到达上限,请及时作出调整”)。管理人员通过预设终端发出对第一预设阈值进行调整的指令,指令中包括第一预设阈值的更新值,例如,1200。通过该步骤保证了消息的完整性。
可选地,在其他的实施例中,离线消息分发程序10还可以被分割为一个或者多个模块,一个或者多个模块被存储于存储器11中,并由一个或多个处理器(本实施例为处理器12)所执行,以完成本申请,本申请所称的模块是指能够完成特定功能的一系列计算机程序指令段。
例如,参照图2所示,为图1中离线消息分发程序10的模块示意图,该实施例中,离线消息分发程序10可以被分割为第一接收110、第二接收模块120、查询模块130及分发模块140,所述模块110-140所实现的功能或操作步骤均与上文类似,此处不再详述,示例性地,例如其中:
第一接收模块110,用于接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消 息队列中;
第二接收模块120,用于接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;
查询模块130,用于分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及
分发模块140,用于基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。
本申请提供一种基于MQTT协议的离线消息分发方法。参照图3所示,为本申请基于MQTT协议的离线消息分发方法较佳实施例的流程图。该方法可以由一个服务器执行,该服务器可以由软件和/或硬件实现。
在本实施例中,所述基于MQTT协议的离线消息分发方法应用于服务器,该方法包括步骤S1-S4。
S1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中。
其中,第一客户端为消息发布端。
所述消息的属性信息中包括消息的时间戳、消息对应的topic(例如,天气)等信息。MQTT协议规定,消息发布端在发送消息至服务器时,需一并传递消息对应的tipic(主题),因此,服务器可直接获取消息对应的topic信息。
需要说明的是,每个topic对应一个消息队列。也就是说,消息队列的多少只与topic有关,与第二客户端(消息订阅端)的数量无关。
每条消息只属于一个topic,只有订阅了该topic的客户端才能收到该类消息。例如,topic为天气,第一客户端为发布天气消息的客户端,只有订阅了订阅了“天气”这个topic的第二客户端才能收到天气消息。当第一客户端发布一条天气消息后,服务器接收该条天气消息,根据其属性信息确定对应的topic“天气”,将这条消息保存至“天气”对应的消息队列中。
本实施例中,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:
从所述消息的属性信息中获取时间戳,根据所述时间戳从早到晚的顺序,依次将所述消息保存在该消息对应的消息队列的头部。
以topic为“天气”为例,消息的属性信息中还包括每一条消息的时间戳,时间戳为消息的发布时间,即,服务器接收到消息的时间。接收到消息之后,将消息按照时间的早晚顺序进行排序,然后找到“天气”这一通topic对应的消息队列,依次将消息存储至消息队列的头部,即,消息队列头部的消息为发布时间最晚(最新)的消息,消息队列尾部的消息为发布时间最早(最旧)的消息。
需要说明的是,每条消息的有效时间(例如,7天)是预先设定的,当消息保存至消息队列的时间超过预先设定的有效时间时,将所述消息从消息队列中删除。
S2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段。
第二客户端为消息订阅端,通过第二客户端订阅一个或多个topic,并接收一个或多个topic对应的消息。第二客户端执行每次离线或者上线操作时,服务器均能获取并记录每一个第二客户端的每次离线或者上线的时间。用户通过第二客户端执行上线操作为触发离线消息的分发的信号。
当侦测到第二客户端的连接指令时,获取当前第二客户端发出连接指令的时间作为离线时间段的结束时间,获取当前第二客户端发出连接指令前最近一次的离线时间,作为离线时间段的开始时间,根据开始时间及结束时间确定第二客户端本次的离线时间段。例如,本次上线时间为a,在本次上线前的离线时间为b,那么,第二客户端的离线时间段为b-a。
对于不同的第二客户端,离线时间段可能相同,也可能不同。
S3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表。
具体地,所述“分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,作为所述第二客户端的离线消息”,包括:
获取一个消息队列的第一条消息,从所述第一条消息的属性信息中获取时间戳,判断该时间戳是否在离线时间段内;
若是,则判断该第一条消息是离线消息,并依次获取该消息队列中的下一条消息重复上述步骤;
若否,则判断该第一条消息不是离线消息,判断该消息队列中不存在所述第二客户端的离线消息。
由于一个消息队列中消息是按照发布时间的早晚顺序排序的,若发布的最晚的消息的发布时间都不在离线时间段内,那么队列中其他消息也一定不在离线时间段内。若发布最晚的消息的是离线消息,则依次往前,判断第二条消息是否在离线时间段内。通过最先判断最新的消息是否为离线消息,可减少很多多余的判断,进而节约资源。
重复上述步骤,获取第二客户端在离线时间段内所有消息队列中的离线消息、并生成离线消息列表。离线消息列表中,最新的离线消息排在前面,最旧的离线消息排在后面。
本实施例中,第二客户端对应的消息队列的数量与第二客户端订阅的TOPIC数量相同。每个第二客户端订阅了N个TOPIC,即对应N个消息队列,其中,N为大于或等于0的整数。
例如,第二客户端P订阅了N个topic,依次从N个topic对应的消息队列中确定第二客户端P在离线时间段(b-a)内的消息,即,第二客户端P的离线消息。消息队列中可能存在第二客户端P的离线消息,也可能不存在第二客户端P的离线消息。
需要说明的是,同一个消息队列是所有订阅该topic的第二客户端共有的,由于不同第二客户端的上线/离线时间(即,离线时间段)不一致,因此,不同第二客户端对应的离线消息列表也可能存在区别。
S4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。
其中,所述第二预设规则包括:
根据所述离线消息列表中各离线消息的排序,依次将离线消息发送至第二客户端。
例如,对于某一个离线消息列表L而言,在离线消息列表L中,各离线消息的排序为:m1、m2、m3、…、m10,其中,m1为最新的离线消息,m10为最旧的离线消息,在分发离线消息的过程中,先分发最新的离线消息m1, 然后分发离线消息m2,以此类推。
优选地,本实施例中的所述第二预设规则还包括:
当所述第二客户端对应多个离线消息列表时,确定各离线消息列表对应的topic的订阅时间,按照订阅时间从早到晚的顺序,依次分发各离线消息列表中的离线消息。
当针对一个第二客户端分发离线消息时,若存在多个topic对应的离线消息需要分发,按照订阅时间的早晚顺序确定各topic的先后顺序,然后顺序获取各topic的离线消息进行分发。
上述实施例提出的基于MQTT协议的离线消息分发方法,接收第一客户端发布的消息,根据消息对应的topic、按照第一预设规则保存至对应的消息队列中,待第二客户端重新连接服务器时,确定第二客户端的离线时间段及离线时间段内的离线消息,按照第二预设规则将离线消息分发给第二客户端。每个topic对应一个消息列表,当有多个第二客户端重新连接服务器时,均从同一消息列表拉取某一个topic对应的离线消息,同时降低了时间复杂度和空间复杂度,提高离线消息分发效率。
在其他实施例中,步骤S1中的所述“根据第一预设规则将该消息保存在该消息队列中”,包括:
当所述消息队列中消息数量为第一预设阈值时,每接收一条新的消息时,移除所述消息队列尾部的一条消息,并将所述新的消息放置在消息队列的头部。
例如,预先设置消息队列的最大容量为1000条,若消息队列中已经有1000条消息,每进来一条新消息,需将最旧的信息删除,然后保存这条新消息。
在其他实施例中,步骤S1中的所述“根据第一预设规则将该消息保存在该消息队列中”,还包括:
当所述消息队列中消息数量达到第二预设阈值时,生成预警信息发送至预设终端,接收该预设终端发出的对所述第一预设阈值进行更新的指令,响应该指令并执行第一预设阈值更新操作。
例如,预先设置消息队列的容量的警戒值900,所述第二预设阈值与第一预设阈值是相对应的。当消息队列中消息数量达到900时,向预设终端发出 预警信息(例如,“消息队列中的消息数量即将到达上限,请及时作出调整”)。管理人员通过预设终端发出对第一预设阈值进行调整的指令,指令中包括第一预设阈值的更新值,例如,1200。通过该步骤保证了消息的完整性。
上述实施例提出的基于MQTT协议的离线消息分发方法,通过对每个消息队列中消息的容量进行管控,节省存储空间的同时,保证离线消息的完整性。
此外,本申请实施例还提出一种计算机可读存储介质,所述计算机可读存储介质中包括离线消息分发程序10,所述离线消息分发程序10被处理器执行时实现如下操作:
A1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中;
A2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;
A3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及
A4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。
本申请之计算机可读存储介质的具体实施方式与上述离线消息分发方法的具体实施方式大致相同,在此不再赘述。
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述 实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其它相关的技术领域,均同理包括在本申请的专利保护范围内。
Claims (20)
- 一种基于MQTT协议的离线消息分发方法,应用于服务器,其特征在于,所述方法包括:S1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中;S2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;S3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及S4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。
- 根据权利要求1所述的离线消息分发方法,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:从所述消息的属性信息中获取时间戳,根据所述时间戳从早到晚的顺序,依次将所述消息保存在该消息对应的消息队列的头部。
- 根据权利要求1所述的离线消息分发方法,其特征在于,所述“分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,作为所述第二客户端的离线消息”,包括:获取一个消息队列的第一条消息,从所述第一条消息的属性信息中获取时间戳,判断该时间戳是否在离线时间段内;若是,则判断该第一条消息是离线消息,并依次获取该消息队列中的下一条消息重复执行判断步骤;若否,则判断该第一条消息不是离线消息,判断该消息队列中不存在所述第二客户端的离线消息。
- 根据权利要求3所述的离线消息分发方法,其特征在于,所述第二预设规则包括:根据所述离线消息列表中各离线消息的排序,依次将离线消息发送至第二客户端。
- 根据权利要求4所述的离线消息分发方法,其特征在于,所述第二预 设规则还包括:当所述第二客户端对应多个离线消息列表时,确定各离线消息列表对应的主题的订阅时间,按照订阅时间从早到晚的顺序,依次分发各离线消息列表中的离线消息。
- 根据权利要求3所述的离线消息分发方法,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:当所述消息队列中消息数量为第一预设阈值时,每接收一条新的消息时,移除所述消息队列尾部的一条消息,并将所述新的消息放置在消息队列的头部。
- 根据权利要求6所述的离线消息分发方法,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,还包括:当所述消息队列中消息数量达到第二预设阈值时,生成预警信息发送至预设终端,并接收该预设终端发出的对所述第一预设阈值进行更新的指令,响应该指令并执行第一预设阈值更新操作。
- 一种服务器,其特征在于,该服务器包括:存储器、处理器,所述存储器上存储有可在所述处理器上运行的离线消息分发程序,所述离线消息分发程序被所述处理器执行时,可实现如下步骤:A1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中;A2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;A3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及A4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。
- 根据权利要求8所述的服务器,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:从所述消息的属性信息中获取时间戳,根据所述时间戳从早到晚的顺序,依次将所述消息保存在该消息对应的消息队列的头部。
- 根据权利要求8所述的服务器,其特征在于,所述“分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,作为所述第 二客户端的离线消息”,包括:获取一个消息队列的第一条消息,从所述第一条消息的属性信息中获取时间戳,判断该时间戳是否在离线时间段内;若是,则判断该第一条消息是离线消息,并依次获取该消息队列中的下一条消息重复执行判断步骤;若否,则判断该第一条消息不是离线消息,判断该消息队列中不存在所述第二客户端的离线消息。
- 根据权利要求10所述的服务器,其特征在于,所述第二预设规则包括:根据所述离线消息列表中各离线消息的排序,依次将离线消息发送至第二客户端。
- 根据权利要求11所述的服务器,其特征在于,所述第二预设规则还包括:当所述第二客户端对应多个离线消息列表时,确定各离线消息列表对应的主题的订阅时间,按照订阅时间从早到晚的顺序,依次分发各离线消息列表中的离线消息。
- 根据权利要求10所述的服务器,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:当所述消息队列中消息数量为第一预设阈值时,每接收一条新的消息时,移除所述消息队列尾部的一条消息,并将所述新的消息放置在消息队列的头部。
- 根据权利要求13所述的服务器,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,还包括:当所述消息队列中消息数量达到第二预设阈值时,生成预警信息发送至预设终端,并接收该预设终端发出的对所述第一预设阈值进行更新的指令,响应该指令并执行第一预设阈值更新操作。
- 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中包括离线消息分发程序,所述离线消息分发程序被处理器执行时,可实现如下步骤:A1、接收第一客户端发布的消息,根据该消息的属性信息确定该消息对应的消息队列,并基于第一预设规则将该消息保存在该消息队列中;A2、接收第二客户端的连接指令,获取所述第二客户端的上线时间及上一次离线时间,确定离线时间段;A3、分别确定所述第二客户端对应的一个或多个消息队列,分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,生成所述第二客户端的离线消息列表;及A4、基于第二预设规则将所述离线消息列表中的消息分发至所述第二客户端。
- 根据权利要求15所述的计算机可读存储介质,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:从所述消息的属性信息中获取时间戳,根据所述时间戳从早到晚的顺序,依次将所述消息保存在该消息对应的消息队列的头部。
- 根据权利要求15所述的计算机可读存储介质,其特征在于,所述“分别从所述一个或多个消息队列中找出所述第二客户端在离线时间段内的消息,作为所述第二客户端的离线消息”,包括:获取一个消息队列的第一条消息,从所述第一条消息的属性信息中获取时间戳,判断该时间戳是否在离线时间段内;若是,则判断该第一条消息是离线消息,并依次获取该消息队列中的下一条消息重复执行判断步骤;若否,则判断该第一条消息不是离线消息,判断该消息队列中不存在所述第二客户端的离线消息。
- 根据权利要求17所述的计算机可读存储介质,其特征在于,所述第二预设规则包括:根据所述离线消息列表中各离线消息的排序,依次将离线消息发送至第二客户端。
- 根据权利要求18所述的计算机可读存储介质,其特征在于,所述第二预设规则还包括:当所述第二客户端对应多个离线消息列表时,确定各离线消息列表对应的主题的订阅时间,按照订阅时间从早到晚的顺序,依次分发各离线消息列表中的离线消息。
- 根据权利要求17所述的计算机可读存储介质,其特征在于,所述“根据第一预设规则将该消息保存在该消息队列中”,包括:当所述消息队列中消息数量为第一预设阈值时,每接收一条新的消息时,移除所述消息队列尾部的一条消息,并将所述新的消息放置在消息队列的头部。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910007206.X | 2019-01-04 | ||
| CN201910007206.XA CN109756417B (zh) | 2019-01-04 | 2019-01-04 | 离线消息分发方法、服务器及存储介质 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2020140614A1 true WO2020140614A1 (zh) | 2020-07-09 |
Family
ID=66405363
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2019/117333 Ceased WO2020140614A1 (zh) | 2019-01-04 | 2019-11-12 | 离线消息分发方法、服务器及存储介质 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN109756417B (zh) |
| WO (1) | WO2020140614A1 (zh) |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114338805A (zh) * | 2021-12-29 | 2022-04-12 | 金卡智能集团股份有限公司 | 数据处理方法、装置和服务器 |
| CN114760259A (zh) * | 2022-04-27 | 2022-07-15 | 深圳小湃科技有限公司 | 离线消息发送方法、装置、电子设备及可读存储介质 |
Families Citing this family (8)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109756417B (zh) * | 2019-01-04 | 2022-08-30 | 平安科技(深圳)有限公司 | 离线消息分发方法、服务器及存储介质 |
| CN110391974A (zh) * | 2019-08-01 | 2019-10-29 | 北京云中融信网络科技有限公司 | 一种消息同步方法、服务端、终端及系统 |
| CN112751892B (zh) * | 2019-10-30 | 2022-06-17 | 腾讯科技(深圳)有限公司 | 一种信息分发方法、装置、设备及存储介质 |
| CN111212135A (zh) * | 2019-12-31 | 2020-05-29 | 北京金山云网络技术有限公司 | 消息订阅方法、装置、系统、电子设备及存储介质 |
| CN111654428B (zh) * | 2020-06-05 | 2022-05-17 | 天津卓朗科技发展有限公司 | 离线消息处理方法、装置和服务器 |
| CN112422369B (zh) * | 2020-11-19 | 2022-08-02 | 青岛海尔科技有限公司 | 离线时间的确定方法及装置、存储介质、电子装置 |
| CN112764947B (zh) * | 2021-01-15 | 2023-12-26 | 百果园技术(新加坡)有限公司 | 消息数据拉取方法、装置、设备和存储介质 |
| CN115297076B (zh) * | 2022-08-01 | 2024-03-19 | 招商局金融科技有限公司 | 离线消息拉取方法、装置、计算机设备及存储介质 |
Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2016012751A1 (en) * | 2014-07-22 | 2016-01-28 | Simple Matters Limited | A chat system |
| CN105306413A (zh) * | 2014-06-13 | 2016-02-03 | 北京视联动力国际信息技术有限公司 | 一种信息发布方法和系统,视联网服务器和发布终端 |
| CN108023923A (zh) * | 2016-11-04 | 2018-05-11 | 中兴通讯股份有限公司 | 离线消息的处理方法及装置 |
| CN108416006A (zh) * | 2018-02-28 | 2018-08-17 | 百度在线网络技术(北京)有限公司 | 离线信息推荐方法、装置、客户端、服务器及存储介质 |
| CN108494815A (zh) * | 2018-02-06 | 2018-09-04 | 北京极智感科技有限公司 | 一种传输消息的方法和系统 |
| CN108768826A (zh) * | 2018-05-16 | 2018-11-06 | 华南理工大学 | 基于MQTT和Kafka高并发场景下的消息路由方法 |
| CN109756417A (zh) * | 2019-01-04 | 2019-05-14 | 平安科技(深圳)有限公司 | 离线消息分发方法、服务器及存储介质 |
Family Cites Families (6)
| 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 (zh) * | 2016-09-08 | 2017-02-08 | 四川长虹电器股份有限公司 | 基于mqtt的智能家电设备控制系统 |
| CN106656751A (zh) * | 2016-12-05 | 2017-05-10 | 北京中交兴路信息科技有限公司 | 一种数据通信的方法及装置 |
| CN108390933B (zh) * | 2018-02-26 | 2021-03-09 | 广州方硅信息技术有限公司 | 消息分发方法、装置、服务器及存储介质 |
| CN108965265A (zh) * | 2018-06-26 | 2018-12-07 | 四川斐讯信息技术有限公司 | 一种基于mqtt协议的聊天方法及系统 |
-
2019
- 2019-01-04 CN CN201910007206.XA patent/CN109756417B/zh active Active
- 2019-11-12 WO PCT/CN2019/117333 patent/WO2020140614A1/zh not_active Ceased
Patent Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105306413A (zh) * | 2014-06-13 | 2016-02-03 | 北京视联动力国际信息技术有限公司 | 一种信息发布方法和系统,视联网服务器和发布终端 |
| WO2016012751A1 (en) * | 2014-07-22 | 2016-01-28 | Simple Matters Limited | A chat system |
| CN108023923A (zh) * | 2016-11-04 | 2018-05-11 | 中兴通讯股份有限公司 | 离线消息的处理方法及装置 |
| CN108494815A (zh) * | 2018-02-06 | 2018-09-04 | 北京极智感科技有限公司 | 一种传输消息的方法和系统 |
| CN108416006A (zh) * | 2018-02-28 | 2018-08-17 | 百度在线网络技术(北京)有限公司 | 离线信息推荐方法、装置、客户端、服务器及存储介质 |
| CN108768826A (zh) * | 2018-05-16 | 2018-11-06 | 华南理工大学 | 基于MQTT和Kafka高并发场景下的消息路由方法 |
| CN109756417A (zh) * | 2019-01-04 | 2019-05-14 | 平安科技(深圳)有限公司 | 离线消息分发方法、服务器及存储介质 |
Cited By (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114338805A (zh) * | 2021-12-29 | 2022-04-12 | 金卡智能集团股份有限公司 | 数据处理方法、装置和服务器 |
| CN114338805B (zh) * | 2021-12-29 | 2023-05-16 | 金卡智能集团股份有限公司 | 数据处理方法和服务器 |
| CN114760259A (zh) * | 2022-04-27 | 2022-07-15 | 深圳小湃科技有限公司 | 离线消息发送方法、装置、电子设备及可读存储介质 |
| CN114760259B (zh) * | 2022-04-27 | 2024-01-16 | 深圳小湃科技有限公司 | 离线消息发送方法、装置、电子设备及可读存储介质 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN109756417A (zh) | 2019-05-14 |
| CN109756417B (zh) | 2022-08-30 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| WO2020140614A1 (zh) | 离线消息分发方法、服务器及存储介质 | |
| CN106534281B (zh) | 一种数据请求的响应方法、装置及系统 | |
| WO2020211344A1 (zh) | 一种基于mqtt的消息分发方法、服务器、装置及存储介质 | |
| CN106487928B (zh) | 消息推送方法及装置 | |
| CN108696374A (zh) | 更新客户端配置的方法和装置 | |
| CN201886473U (zh) | 配置文件更新系统、配置服务器及应用服务器 | |
| CN111339057B (zh) | 减少回源请求的方法、装置及计算机可读存储介质 | |
| US11488082B2 (en) | Monitoring and verification system for end-to-end distribution of messages | |
| CN110659124A (zh) | 一种消息处理方法和装置 | |
| WO2019062019A1 (zh) | 一种数据列表的导出方法及其终端 | |
| CN113014608A (zh) | 一种流量分发控制方法、装置、电子设备及存储介质 | |
| CN114647701A (zh) | 分布式数据库的负载均衡方法、装置、电子设备及介质 | |
| CN114138895B (zh) | 多数据源的数据同步方法、装置、计算机设备和存储介质 | |
| CN110620722A (zh) | 一种订单处理的方法和装置 | |
| CN116263768B (zh) | 基于云平台的信息推送方法及装置 | |
| WO2020238057A1 (zh) | 基于Redis的mqtt集群的监控方法、装置及存储介质 | |
| WO2020024375A1 (zh) | 一种数据传输管理的方法及装置 | |
| CN113783913A (zh) | 一种消息推送管理方法和装置 | |
| CN104462106A (zh) | 数据更新方法及系统 | |
| CN115037802B (zh) | 一种请求处理方法、装置、电子设备和存储介质 | |
| CN117435363A (zh) | 进程间通信方法、系统、装置、电子设备及介质 | |
| CN116346611A (zh) | 配置更新方法、装置、电子设备及计算机可读存储介质 | |
| CN115640303A (zh) | 数据查询服务集控方法及其装置、设备、介质、产品 | |
| CN108924579A (zh) | 视频网络系统、回源网络节点设备、方法和存储介质 | |
| CN111143397B (zh) | 混合数据查询方法及装置、存储介质 |
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 |