[go: up one dir, main page]

WO2022211724A1 - Method and apparatus for transmitting messages, and device and storage medium thereof - Google Patents

Method and apparatus for transmitting messages, and device and storage medium thereof Download PDF

Info

Publication number
WO2022211724A1
WO2022211724A1 PCT/SG2022/050123 SG2022050123W WO2022211724A1 WO 2022211724 A1 WO2022211724 A1 WO 2022211724A1 SG 2022050123 W SG2022050123 W SG 2022050123W WO 2022211724 A1 WO2022211724 A1 WO 2022211724A1
Authority
WO
WIPO (PCT)
Prior art keywords
message
queued
storage file
consumption
file
Prior art date
Application number
PCT/SG2022/050123
Other languages
French (fr)
Inventor
Meng CHAI
Changdong CUI
Yang Zhang
Jialin QIAN
Original Assignee
Envision Digital International Pte. Ltd.
Spic Envision Intelligence Technology (Jiangsu) Co., Ltd.
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 Envision Digital International Pte. Ltd., Spic Envision Intelligence Technology (Jiangsu) Co., Ltd. filed Critical Envision Digital International Pte. Ltd.
Publication of WO2022211724A1 publication Critical patent/WO2022211724A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/5038Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/542Event management; Broadcasting; Multicasting; Notifications
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/547Messaging middleware
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Definitions

  • Embodiments of the present disclosure relates to the field of the Internet of things (loT) technologies, and more particularly, relate to a method and apparatus for transmitting messages, and a de vice and storage medium thereof.
  • LoT Internet of things
  • a message queue refers to a "first-in, first-out" data structure in basic data structures, and is generally configured to solve the problems such as application decoupling, asynchronous messages, and traffic peak clipping. After a producer generates a message and posts the message into a queue, a consumer receives this message in the queue and processes this message accordingly.
  • An MQ in related aits is mainly implemented by virtue of message-oriented middleware and a database, or directly cached in a device memory. After a producer sends a message to the MQ, the MQ copies the received message to respective consumption channels, and a consumer then consumes messages from the corresponding consumption channel.
  • Embodiments of the present disclosure disclose a method and apparatus for transmitting messages, and a device and storage medium thereof.
  • the embodiments of the present disclosure provide a method for transmitting messages.
  • llie method includes: persistently writing a queued message sent by a message producer into a disk according to a chronological sequence of message generation time; adjusting a message reading position of a consumption channel based on index information of a message that a message consumer has read and according to a write sequence of the queued message, the message reading position being configured to indicate a storage position of the queued message in the disk; reading the queued message from the disk over the consumption channel based on the message reading position; and sending the queued messages read from the consumption channel to the message consumer in response to the message consumer being online.
  • the embodiments of the present disclosure provide an apparatus for transmitting messages.
  • llie apparatus includes: a writing module, configured to persistently writing a queued message sent by a message producer into a disk according to a chronological sequence of message generation time; a first adjusting module, configured to adjust a message reading position of a consumption channel based on index information of a message that a message consumer has read and according to a write sequence of the queued message, the message reading position being configured to indicate a storage position of the queued message in the disk; a reading module, configured to read the queued message from the disk over the consumption channel based on the message reading position; and a sending module, configured to send the queued message read over the consumption channel to the message consumer in response to the message consumer being online.
  • the embodiments of the present disclosure provide a computer device.
  • the computer device includes a processor and a memory, wherein the memory is configured to store at least one instruction, at least one program, a code set, or an instruction set therein, wherein the at least one instruction, the at least one program, the code set or the instruction set, when loaded and executed by the processor, causes the processor to perform the method for transmiting messages as described above.
  • the embodiments of the present disclosure provide a computer-readable storage medium, storing at least one computer program therein, wherein the at least one computer program, when loaded and run by a processor of a computer device, causes the computer device to perform the method for transmitting messages as described above.
  • the embodiments of the present disclosure provide a computer program product or a computer program.
  • the computer program product or the computer program includes a computer instruction stored in a computer-readable storage medium, wherein the at least one computer instruction, when loaded and executed by a processor of a computer device, causes the computer device to perform the methods for transmitting messages as described above.
  • the queued message sent by the message producer is received and then persisted to the disk, which avoids data loss when the device is abnormal compared to a method of writing the queued message to a memory in the related arts.
  • the queued message is stored according to the chronological sequence of message generation time, and the message reading position of the consumption channel is adjusted according to the write sequence of the queued message, which meets the demand of an loT edge device for a chronological sequence of messages.
  • the process of sending the message to the message consumer based on the message reading position indicated by the index information only requires persisting the queued message once, which greatly improves the efficiency of message transmission in the case of more consumption channels compared to a method in which a queued message needs to be sequentially copied to respective consumption channels in the related arts, thereby avoiding a case where a message consumer needs to wait because the message transmission time is too long.
  • FIG. 1 is a schematic diagram of an implementation environment according to an exemplary embodiment of the present disclosure
  • FIG. 2 is a flowchart of a method for transmitting messages according to an exemplary embodiment of tire present disclosure:
  • FIG. 3 is a flowchart of a method for transmitting messages according to another exemplary embodiment of the present disclosure
  • FIG. 4 is a flowchart of a method for transmiting messages according to yet another exemplary embodiment of the present disclosure
  • FIG. 5 is a flowchart of a method for transmitting messages according to still yet another exemplary' embodiment of the present disclosure
  • FIG. 6 is a flowchart of a method for transmitting messages according to still yet another exemplary embodiment of the present disclosure
  • FIG. 7 is a schematic diagram of a first consumption mode according to an exemplary- embodiment of the present disclosure.
  • FIG. 8 is a schematic diagram of a second consumption mode according to an exemplary embodiment of the present disclosure.
  • FIG. 9 is a schematic diagram of a third consumption mode according to an exemplary- embodiment of the present disclosure.
  • FIG. 10 is a structural block diagram of an apparatus for transmiting messages according to an exemplary- embodiment of the present disclosure.
  • FIG. 11 is a structural block diagram of a computer device according to an exemplary embodiment of the present disclosure.
  • a and/or B can be expressed as: A exists alone, A and B exist concurrently, or B exists alone.
  • the symbol generally indicates an "or" relationship between the contextual ob j ects.
  • an embodiment of the present disclosure provides a method for transmitting messages.
  • a message reading position of a consumption channel is adjusted according to a write sequence of a queued message by persisting the queued message to a disk and performing consumption at a message consumer, which meets the demand of an loT edge device for a chronological sequence of messages.
  • the process of sending the message to the message consumer based on the message reading position indicated by index information only requires persisting the queued message once, which greatly improves the efficiency of message transmission in the case of more consumption channels, thereby avoiding a case where tire message consumer needs to wait because the message transmission time is too long.
  • FIG. 1 is a schematic diagram of an implementation environment according to an embodiment of the present disclosure.
  • a message producer 110 sends a produced queued message to message-oriented middleware 12.0 which then forwards the queued message to a message consumer 130.
  • the message-oriented middleware includes at least one queue topic 121, wherein each queue topic 121 corresponds to a persistent message storage file 122.
  • the message consumer 130 consumes messages over a consumption channel 123 and reads the queued message in the message storage file 122.
  • the queued message is stored according to a chronological sequence of message generation time.
  • the queued message is read over respective consumption channels 123 under the same queue topic 121 according to a chronological sequence of generation time of files in the message storage file 122, and a message reading position is ad j usted based on index information of the message consumer 130.
  • the message producer 110 and the message consumer 130 may be devices with data generation and data transmission functions, or may be applications.
  • the message producer 110, the message consumer 130 and the message-oriented middleware 120 may belong to the same computer device, or may be respectively provided in independent computer devices.
  • FIG, 1 only illustrates one message producer 1 10 and one queue topic 121.
  • more message producers 110 and more queue topics 121 may be present, wherein one message producer 110 may correspond to a plurality' of queue topics 121, or a plurality of message producers 110 may correspond to the same queue topic 121, which is not limited in this embodiment of the present disclosure.
  • FIG. 2 is a flowchart of a method for transmitting messages according to an exemplary embodiment of the present disclosure. This embodiment is described by taking this method being applied to a computer device with message storage and message transmission functions as an example. The method includes the following steps.
  • step 201 a queued message sent by a message producer is persistently written into a disk according to a chronological sequence of message generation time.
  • message-oriented middleware in the computer device receives the queued message and then persistently writes the queued message to the disk, e.g., to a disk file configured to store queued messages.
  • a sequence in which the queued message actually arrives at the middleware may be inconsistent with a sequence in which the queued message is generated, i.e., the queued message generated by the message producer later arrives at the middleware first.
  • the computer device In order to ensure that the queued messages can be stored and consumed according to a generation sequence of the queued messages, and to meet the requirements of an loT edge device for a timing sequence of messages, the computer device achieves message persistence m strict accordance with the chronological sequence of message generation time.
  • the message producer may send the queued message together with its time stamp while sending the queued message to the message-oriented middleware, the time stamp being message generation time of the queued message, such that the message-oriented middleware determines a chronological sequence of respective queued messages.
  • a time stamp corresponding to the previous queued message received by the message-oriented middleware is 00:01:00, while a time stamp of the currently received queued message is 00:01:02.
  • the computer device suspends the storage of the currently received queued message, and after a queued message with a time stamp of 00:01:01 arrives, stores this queued message according to a chronological sequence of the time stamps: or the computer device stores the queued messages received at every predetermined duration in a centralized manner, thereby storing the queued messages received within the predetermined duration in a chronological sequence.
  • a message reading position of a consumption channel is adjusted based on index information of a message that a message consumer has read and according to a write sequence of the queued message, wherein the message reading position is configured to indicate a storage position of the queued message in the disk.
  • the message consumer is responsible for maintaining the index information. For example, after the consumption channel of the message-oriented middleware sends one queued message to the message consumer, the message consumer sends the index information to the corresponding consumption channel in the case that the message consumer has successfully received this queued message. Thus, the consumption channel adjusts the message reading position, such that the message reading position moves to the next queued message of the read message.
  • the same consumption channel may correspond to a plurality of message consumers; and a competitive relationship is present among the message consumers corresponding to the same consumption channel, and the message consumers jointly maintain a piece of index information.
  • a consumption channel A corresponds to a message consumer a and a message consumer b
  • a consumption channel C corresponds to a message consumer c
  • the message consumer c consumes the queued message transmitted by the consumption channel C alone
  • the message consumer a and the message consumer b compete to acquire data transmitted by the consumption channel A.
  • the consumption channel can adjust the message reading position in response to receiving the index information sent by' one of the message consumers.
  • the message-oriented middleware adjusts the message reading position of the consumption channel according to the write sequence of the queued messages in response to receiving the index information.
  • the message-oriented middleware after determining from the index information that the message consumer has received the queued message 1, adjusts a message reading position of the consumption channel A from a storage position of the queued message 1 to a storage position of the queued message 2.
  • step 203 the queued message is read from the disk over the consumption channel based on the message reading position.
  • the message -oriented middleware after adjusting the message reading position of the consumption channel, controls the consumption channel to read the queued message corresponding to the message reading position.
  • this embodiment of the present disclosure can realize the sequential writing and sequential consumption of the queued messages, and ensure that the message consumer can receive the queued messages according to the chronological sequence of message generation time.
  • the queued message read over the consumption channel is sent to the message consumer in response to the message consumer being online.
  • the message-oriented middleware sends the queued message read over tire consumption channel to the message consumer in response to the message consumer being online.
  • the queued message is sent to the message consumer over the consumption channel in the case that the message-oriented middleware detects that the message consumer is online; or the message consumer acquires the queued message from the consumption channel by means of active polling after going online,
  • the queued message sent by the message producer is received and then persisted to the disk, which avoids data loss when a device is abnormal compared to a method of writing the queued message to a memory in the related arts.
  • the queued message is stored according to die chronological sequence of message generation time, and the message reading position of the consumption channel is adjusted according to the write sequence of the queued message, which meets the demand of an IoT edge device for a chronological sequence of messages.
  • the process of sending die message to the message consumer based on die message reading position indicated by the index information only requires persisting the queued message once, which greatly improves the efficiency of message transmission in the case of more consumption channels compared to a method in which queued messages need to be sequentially copied to respective consumption channels in the related arts, thereby avoiding a case where a message consumer needs to wait because the message transmission time is too long.
  • the message-oriented middleware persists the queued message sent by the message producer to the disk.
  • the message-oriented middleware stores message queues in blocks.
  • FIG. 3 is a flowchart of a method for transmitting messages according to still yet another exemplary embodiment of the present disclosure. This embodiment is described by taking this method being applied to a computer device with message storage and message transmission functions as an example. The method includes the following steps.
  • step 301 a queued message sent by the message producer is acquired.
  • the message-oriented middleware in the computer device acquires the queued message sent by the message producer in real time, and persists the acquired queued message to a disk.
  • the persistence of the queued message is asynchronous, i.e., after the message producer sends the queued message to the message-oriented middleware, it is unnecessary to wait for the persistence to end and return. Therefore, the production cycle of the message producer is shorter, and the throughput of the message-oriented middleware can be improved.
  • step 302 the queued message is written into a message storage file based on a data volume of a target message storage file and according to a chronological sequence of message generation time, wherein the target message storage file is a message storage file having the latest file generation time in the disk.
  • the message-oriented middleware in order to improve the high availability of the message- oriented middleware and the efficiency of message transmission, stores the queued messages in blocks, which still ensures the security of queued messages in other files in the case that one message storage file is damaged.
  • the message-oriented middleware reads the queued messages, it is only necessary' to load a file where a queued message to be read is located, rather than all the message storage files, such that a memor)? size required for message reading is reduced accordingly.
  • Step 302 further includes the following sub-steps.
  • sub-step 302a the queued message is written into the target message storage file according to the chronological sequence of message generation time in response to the data volume of the target message storage file not reaching a predetermined data volume.
  • the message -oriented middleware is preassigned a predetermined data volume (for example, 30M) of a message storage file.
  • the message -oriented middleware writes the queued messages to a message storage file in sequence.
  • a new message storage file is created, and queued messages are then continued to be written into the newly created message storage file.
  • the target message storage file refers to a message storage file with the latest file generation time in the disk.
  • the message-oriented middleware confirms the data volume of the target message storage file in response to receiving the queued messages. In the case that the data volume does not reach the predetennined data volume, it is determined that the target message storage file can continue to store queued messages.
  • a newly-built message storage file is generated in response to the data volume of the target message storage file reaching the predetermined data volume, and the queued messages are written into the newly-built message storage file according to the chronological sequence of message generation time.
  • the message-oriented middleware needs to create a new message storage file, and write subsequently received queued messages into the newly-built message storage file according to the chronological sequence of message generation time.
  • a read message storage file corresponding to a read message is determined based on a file identifier in index information, and a storage position of the read message in the read message storage file is determined based on a message identifier in the index information.
  • the queued message and the message identifier thereof are associatively stored in the message storage file.
  • the index information contains a file identifier of the read message and the message identifier.
  • information such as the message identifiers, the queued messages, time stamps, and message attributes are associatively stored in the message storage file by the message-oriented middleware, such that a consumption channel can determine a storage position of the queued message in the message storage file based on the corresponding message identifier, and the queued message is read over the consumption channel. Since the message-oriented middleware in this embodiment of the present disclosure stores the queued messages in blocks, it is also necessary to set a unique file identifier for each message storage file.
  • the message consumer in response to receiving the queued message, sends index information indicating that queue data has been successfully received to the corresponding consumption channel.
  • the consumption channel in response to receiving the index information, determines that the message consumer has successfully consumed the corresponding queue data, and adjusts a message reading position based on the index information.
  • the message reading position is moved to a storage position of the next queued message based on the storage position of the read message in the read message storage file and the write sequence of the queued message.
  • three message storage files are stored in the disk of the computer device where the message-oriented middleware is located, including a file 1, a file 2, and a file 3.
  • queued messages with message identifiers of 001, 002, and 003, respectively are stored in the file 1; queued messages with message identifiers of 001, 002, and 003, respectively are stored in the file 2; and queued messages with message identifiers of 001 and 002, respectively are stored in the file 3.
  • the message-oriented middleware moves the message reading position of the consumption channel to (file 2, 002); and in the case that the consumption channel receives index information containing (file 2, 003) sent by the message consumer, the message-oriented middleware moves the message read position of the consumption channel to (file 3, 001).
  • step 305 the queued message is read from the disk over the consumption channel based on the message reading position.
  • step 306 the queued message read over tire consumption channel is sent to the message consumer in response to the message consumer being online.
  • steps 305 to 306 For specific implementations of steps 305 to 306, reference may be made to steps 203 to 204, which are not described herein again in this embodiment of the present disclosure.
  • the message-oriented middleware stores the queued messages in blocks, which still ensures the security of queued messages in other files in the case that one message storage file is damaged.
  • the message-oriented middleware reads the queued messages, it is only necessary to load a file where a queued message to be read is located, rather than all the message storage files, such that a memory size required for message reading will be reduced accordingly.
  • the message-oriented middleware adjusts the message reading positions of the consumption charmels sequentially- based on the index information maintained by the message consumer, without the need to copy the message storage file to the consumption channel, thereby further improving the efficiency of message transmission.
  • FIG. 4 is a flowchart of a method for transmitting messages according to still yet another exemplary embodiment of the present disclosure. This embodiment is described by taking this method being applied to a computer device with message storage and message transmission functions as an example. The method includes the following steps.
  • step 401 a message storage file is deleted in response to all queued messages in this message storage file having been acquired by respective consumption channels under a target queue topic.
  • Tope 1 contains a consumption channel A and a consumption channel B, and message storage files corresponding to Tope 1 are file 1 and file 2.
  • the message-oriented middleware deletes file 1.
  • die message-oriented middleware determines whether a queued message is stored in a message storage file in wliich all queued messages have been acquired by all consumption channels based on the message reading positions of respective consumption channels.
  • step 402 n message storage files having the earliest file creation time in the target queue topic are deleted according to a predetermined file amount in response to the amount of files in the message storage file in the target queue topic in the disk being greater than the predetermined file amount , wherein n is a positive integer.
  • the message-oriented middleware is preassigned the maximum amount of message storage files that each queue topic can have, that is, the predetermined file amount.
  • the message-oriented middleware numbers the respective message storage files based on a file generation sequence.
  • the message-oriented middleware performs a file deletion operation; or the message-oriented middleware detects the amount of files in the message storage file corresponding to each queue topic once within every predetermined duration, and removes the files.
  • the amount of predetermined files corresponding to each queue topic is 5.
  • the message storage files corresponding to Topic 1 include file 1, file 2, file 3, file 4, file 5 and file 6.
  • the message-oriented middleware deletes file 1 in Topic 1. Assuming that a consumption channel whose message reading position is in file 1 before a file is deleted is present, the message- oriented middleware adjusts the message reading position of this consumption channel to a position of a first queued message in file 2.
  • m message storage files having the latest file creation time in the target queue topic are retained in response to no message consumer existing under the target queue topic, and other message storage files in the target queue topic are deleted, wherein m is a positi ve integer.
  • a message consumer under a queue topic does not consume any message for a long time, or all message consumers cancel their subscriptions to queued messages. That is, it is considered that no message consumer is present under this queue topic. At this time, disk resources may be wasted in the case that the message-oriented middleware saves more message storage files. Therefore, the message-oriented middleware only saves the latest m message storage files.
  • the message-oriented middleware in the case that no message consumer is present under the target queue topic, the message-oriented middleware only retains one latest message storage file in the target queue topic. For example, in the case that no message consumer is present under Topic 1, the message-oriented middleware continuously stores queued messages in file 1. In the case that a data volume of file 1 reaches a predetermined data volume, the message-oriented middleware creates file 2, continues to write queued messages in file 2, and deletes file 1.
  • This embodiment of the present disclosure provi des three deletion strategies for message storage files, and a user may set one or more appropriate deletion strategies according to actual business situations, thereby effectively cleaning up the disk.
  • step 501 the amount of files in a message storage file under a target queue topic is acquired.
  • step 502 whether the amount of files is greater than a predetermined file amount is determined. In the case that the amount of files is greater than the predetermined file amount, step 503 is performed, or step 507 is performed.
  • step 503 message reading positions of respective consumption channels under a target queue topic are acquired.
  • step 504 whether a message reading position needs to be moved is determ ined. In the case that the message reading position needs to be moved, step 505 is performed, or step 506 is performed. [0082] In step 505, the message reading position is moved,
  • step 506 n message storage files with the earliest file creation time in the target queue topic are deleted.
  • step 507 whether a message consumer is present is determined. In the case that the message consumer is present, step 509 is performed: and otherwise, step 508 is performed.
  • step 508 m message storage files with the latest file creation time in the target queue topic are retained, and other message storage files are deleted.
  • step 509 whether all the queued messages in the target message storage file have been acquired by the respective consumption channels is determined. In the case that all the queued messages in the target message storage file have been acquired by the respective consumption channels, step 510 is performed, or the process is ended.
  • step 510 the target message storage file is deleted.
  • step 302 may further include sub-step 302a,
  • sub-step 302a the queued messages are written into a message storage file based on the data volume of a target message storage file and the consumption mode corresponding to the queue topic and according to the chronological sequence of message generation time.
  • sub-step 302a includes the following steps.
  • step 1 a queued message is written into the target message storage file according to the chronological sequence of message generation time in response to the data volume of the target message storage file not reaching the predetermined data volume.
  • a newly-built message storage file is generated in response to the data volume of the target message storage file reaching the predetermined data volume, and the queued message is written into the newly-built message storage file according to the chronological sequence of message generation time.
  • the message-oriented middleware continuously accepts and stores the queued messages sent by the message producer, and continuously sends the queued messages to online message consumers without interfering with each other. That is, die message consumer consumes messages according to the chronological sequence of message generation time in response the message consumer being online; and in the case that the message consumer is offline, the queued messages may not be lost. Therefore, the message-oriented middleware normally stores the queued messages based on the predetermined data volume of the message storage file. As shown in FIG.
  • the flow of die first consumption mode includes: 701, publishing a queued message by a message producer; 702, storing the queued message by the message-oriented middleware; and 703, perfontiing online consumption by a message consumer.
  • the normal mode is mainly applied to a conventional inter-device communication scenario, or a scenario where a message queue loss is not allowed.
  • a device such as a fan sends collected data to an upstream device, or the message-oriented middleware temporarily stores some messages for subsequent use .
  • sub-step 302a includes the following steps.
  • step 3 a queued message is discarded m response to all message consumers under the queue topic being offline.
  • the message consumer consumes this queued message when it is online, and does not consume this queued message when it is offline.
  • the message-oriented middleware discards the queued messages received in the ease that the message consumers are all offline.
  • the broadcast mode is mainly used for real-time message deliver ⁇ ' .
  • an upstream device issues a control instruction to a downstream fan device, and the fan device only needs to receive the latest control instruction online because such messages cannot be backlogged.
  • step 4 the queued message is w'ritten into the message storage file based on the data volume of the target message storage file and according to the chronological sequence of message generation time, in response to the presence of the message consumer in an online state under the queue topic.
  • a message transmission process corresponding to the second consumption mode includes: 801, publishing a queued message by a message producer; 802, determining whether the message consumer is online by the message-oriented middleware, in the case that the message consumer is online, performing step 803, or performing step 804; 803, performing online consumption by the message consumer; and 804, discarding the queued message.
  • the method for transmitting messages in this embodiment of the present disclosure includes the following steps.
  • step 5 a time difference is determined based on a current time and the message generation time of a queued message written at the earliest time in the queue topic.
  • the message-oriented middleware In the timeout mode, the message-oriented middleware only retains queued messages within a certain time range. For the timed-out queued messages, the message-oriented middleware will discard them regardless of whether they are consumed by message consumers.
  • the timeout mode is mainly used for transmitting messages of a notification type. For example, a cloud issues resources to an edge side, and a device on the edge side receives this message and then forwards this message to the message-oriented middleware, and thus notify other devices to update resources. At this time, some devices may be updated quickly, and some devices may be updated slowly, so the message-oriented middleware allows such messages to be stored for a certain duration.
  • step 6 the queued message written at the earliest time is deleted in response to the time difference being greater than a predetermined time difference.
  • a message transmission process corresponding to the third consumption mode includes: 901, publishing a queued message by a message producer; 902, determ ining whether the queued message has timed out by the message-oriented middleware, in the case that the queued message has timed out, performing step 903, or performing a step 904; 903, discarding the queued message; and 904, performing online consumption by the message consumer.
  • the user may set the consumption mode by setting the attributes of the queue topic, such that the consumption modes of the respective queue topics can be switched at any time according to the needs.
  • a method for transmitting messages in this embodiment of the present disclosure further includes the following steps.
  • step 7 a mode switch instruction is received over a mode switching interface corresponding to the queue topic, the mode switch instruction is configured to set a consumption mode parameter in the mode switching interface.
  • a user-oriented mode switching interface is set in the message-oriented middleware, and the user can set the attributes of the queue topic by calling the mode switching interface.
  • the mode switching interface includes consumption mode parameters, and the user may select the corresponding consumption mode over an interactive interface, such that the message-oriented middleware receives the mode switch instruction,
  • step 8 the consumption mode of the queue topic is switched to the consumption mode corresponding to the consumption mode parameter
  • the message-oriented middleware in response to receiving the mode switch instruction, immediately adjusts the consumption mode parameter to a consumption mode parameter indicated by the mode switch instruction, and continues to store and transmit the queued message based on the consumption mode corresponding to the adjusted consumption mode parameter.
  • each queue topic is assigned a separate consumption mode.
  • the user can switch the consumption mode of any queue topic at any time, which meets different requirements for message transmission in complex business scenarios at the edge side of loT, improves the efficiency of message transmission, and avoids the storage and transmission of invalid queued messages.
  • FIG. 10 is a schematic structural diagram of an apparatus for transmitting messages according to an exemplary embodiment of the present disclosure.
  • the apparatus includes: a writing module 1001, configured to persistently writing a queued message sent by a message producer into a disk according to a chronological sequence of message generation time; a first adjusting module 1002, configured to adjust a message reading position of a consumption channel based on index information of a message that a message consumer has read and according to a write sequence of the queued message, wherein the message reading position is configured to indicate a storage position of the queued message in the disk; a reading module 1003, configured to read the queued message from the disk over the consumption channel based on the message reading position; and a sending module 1004, configured to send the queued message read over the consumption channel to the message consumer in response to the message consumer being online.
  • a writing module 1001 configured to persistently writing a queued message sent by a message producer into a disk according to a chronological sequence of message generation time
  • a first adjusting module 1002 configured to adjust a message reading position of a consumption channel based on index information of a message that a message consumer has read and according to
  • the waiting module 1001 includes: an acquiring unit, configured to acquire the queued message sent by the message producer; and a writing unit, configured to write the queued message into a message storage file based on a data volume of a target message storage file and according to the chronological sequence of message generation time, wherein the target message storage file is a message storage file having the latest file generation time in the disk.
  • the first writing module is further configured to: write the queued messages into the target message storage file according to the chronological sequence of message generation time in response to the data volume of the target message storage file not reaching a predetermined data volume; and generate a newly-built message storage file in response to the data volume of the target message storage file reaching the predetermined data volume, and write the queued message into the newly-built message storage file according to the chronological sequence of message generation time.
  • the queued message and a message identifier of the queued message are associatively- stored in the message storage file, and the index information contains a file identifier of the read message and the message i dentifi er; and the first adjusting module 1002 includes: a determining unit, configured to determine a read message storage file corresponding to the read message based on the file identifier in the index information, and determine a storage position of the read message in the read message storage file based on the message identifier in the index information; and an adjusting unit, configured to move the message reading position to a storage position of the next queued message based on the storage position of the read message in the read message storage file and a write sequence of the queued message.
  • the queued messages of different attributes belong to different queue topics, at least one of the consumption channels is included under the same queue topic, and the message consumer acquires the queued message under a target queue topic over a target consumption channel; and the apparatus further includes: a first deleting module, configured to delete the message storage file in response to all the queued messages in the message storage file having been acquired by the respective consumption channels under the target queue topic; and/or, a second deleting module, configured to delete the n message storage files having the earliest file creation time in the target queue topic based on a predetermined file amount in response to the amount of files in the message storage file in the target queue topic in the disk being greater than the predetermined file amount, wherein n is a positive integer; and/or, a third deleting module, configured to retain the m message storage files having the latest file creation time in the target queue topic in response to no message consumer existing under the target queue topic, and delete other message storage files in the target queue topic, wherein m is a positive integer.
  • the queued messages of different attributes belong to different queue topics, at least one of the consumption channels is included under the same queue topic, and each queue topic is assigned a consumption mode; and the writing module is further configured to write the queued message into the message storage file based on the data volume of the target message storage file and the consumption mode corresponding to the queue topic and according to the chronological sequence of message generation time.
  • the consumption mode of the queue topic is a first consumption mode; and the writing unit is further configured to: write the queued message into the target message storage file according to the chronological sequence of message generation time in response to the data volume of the target message storage file not reaching a predetermined data volume; and generate a newly-built message storage file in response to the data volume of the target message storage file reaching the predetermined data volume, and write the queued message into the newly-built message storage file based on the chronological sequence of message generation time.
  • the consumption mode of the queue topic is a second consumption mode; and the writing module is further configured to: discard the queued message in response to the message consumer under the queue topic being offline; and write the queued message into the message storage file based on the data volume of the targe t message storage file and according to the chronological sequence of message generation time, in response to the presence of the message consumer in an online state under the queue topic.
  • tire consumption mode of the queue topic is a third consumption mode; and the apparatus further includes: a determining module, configured to determine a time difference based on a current time and the message generation time of the queued message writen at the earliest time in the queue topic; and a fourth deleting module, configured to delete the queued message written at the earliest time in response to the time difference being greater than a predetermined time difference.
  • the apparatus further includes: a receiving module, configured to receive a mode switch instruction over a mode switching interface corresponding to the queue topic, wherein the mode switch instruction is configured to set a consumption mode parameter in the mode switching interface; and a second adjusting module, configured to switch the consumption mode of the queue topic to the consumption mode corresponding to the consumption mode parameter.
  • FIG. 11 is a schematic structural diagram of a computer device according to an exemplary embodiment of the present disclosure.
  • the computer device 1100 includes a central processing unit (CPU) 1101, a system memory 1104 including a random access memory 1102 and a read only memory 1103, and a system bus 1105 is connected to the system memory 1104 and the central processing unit 1101.
  • the computer device 1100 further includes a basic input/output system (I/O system) 1106 that facilitates to transmit information between respective devices within the computer, and a mass storage device 1107 configured to store an operating system 1113, an application 1114, and other program modules 1115.
  • I/O system basic input/output system
  • the basic input/output system 1106 includes a display 1108 configured to display information and an input device 1109, such as a mouse or keyboard, for tire user to input information.
  • the display 1108 and the input device 1109 are both connected to the CPU 1101 via an input/output controller 1110 that is connected to the system bus 1105.
  • the basic I/O system 1106 may further include an input/output controller 1110 configured to receive and process the input from a plurality of other devices, such as a keyboard, a mouse, or an electronic stylus.
  • the input/output controller 1110 further provides output to a display screen, a printer, or other types of output devices.
  • the mass storage device 1107 is connected to the CPU 1101 by a mass storage controller (not shown) connected to the system bus 1105.
  • the mass storage device 1107 and the related computer-readable mediums provide a non-volatile storage for the computer device 1100. That is, the mass storage device 1107 may include a computer-readable medium (not shown), such as, a hard disk or a drive.
  • the computer-readable medium may include a computer storage medium and a communication medium.
  • the computer storage medium includes volatile and nonvolatile, removable and non-removable mediums implemented by any method or technology for storing the information, such as, computer-readable instructions, data structures, program modules or other data.
  • the computer storage medium includes a random- access memory' (RAM), a read-only memory (ROM), a flash memory or other solid state storage technologies, a compact disc read-only memory (CD-ROM), a digital versatile disc (DVD) or other optical storage devices, a tape cartridge, a magnetic tape, a magnetic disk storage device or other magnetic storage devices.
  • RAM random- access memory'
  • ROM read-only memory
  • CD-ROM compact disc read-only memory
  • DVD digital versatile disc
  • the computer storage medium is not limited to the above ones.
  • the aforesaid system memory 1104 and mass storage device 1107 may be collectively referred to as a memory'.
  • Hie memory is configured to store one or more programs therein, which are configured to be executed by the one or more central processing units 1101.
  • the one or more programs contain instructions for implementing the foregoing methods, and are executed by the central processing unit 1101 to implement the methods according to the foregoing method embodiments.
  • the computer de v ice 1100 may further be operated by a remote computer connected to the network over the network such as the Internet. That is, the computer device 1100 may be connected to the network 1112 by a network interface unit 1111 connected to the system bus 1105, or may be connected to other types of networks or remote computer systems (not shown) by the network interface unit 1111.
  • the memory is configured to store one or more programs therein, which include steps that are implemented by a computer device in the methods according to the embodiments of the present disclosure.
  • An embodiment of the present disclosure provides a computer-readable storage medium, storing at least one instruction therein, wherein the at least one instruction, when loaded and executed by the processor, causes tire processor to perform any of the methods for transmitting messages as described in above embodiments.
  • An embodiment of the present disclosure provides a computer program product or a computer program is provided.
  • the computer program product or the computer program includes a computer instruction stored in a computer-readable storage medium.
  • the computer instruction when loaded and executed by a processor of the computer device, causes the computer device to perform the methods for transmitting messages according to the embodiments as described above.
  • the functions described in the embodiments of the present disclosure may be implemented in hardware, software, firmware or any combination thereof.
  • these functions may be stored in a computer-readable storage medium, or transmitted over as one or more instructions or codes in the computer-readable storage medium.
  • the computer-readable storage medium includes a computer storage medium and a communication medium.
  • the communication medium includes any medium that may be configured to transmit computer programs from one location to another location.
  • the storage medium may be any available medium that is accessible by a general or special computer.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Multimedia (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

Disclosed are a method and apparatus for transmitting messages. The method includes: persistently writing a queued message sent by a message producer into a disk according to a chronological sequence of message generation time; adjusting a message reading position of a consumption channel based on index information of a message that a message consumer has read and according to a write sequence of the queued message; reading the queued message from the disk over the consumption channel based on the message reading position; and sending the queued message read over the consumption channel to the message consumer in response to the message consumer being online. According to the present disclosure, the persistence of the queued message to the disk can avoid data loss when a device is abnormal; the storage and consumption based on the chronological sequence of message generation time can meet the demand of an IoT edge device for a chronological sequence of messages; and the process of sending the message to the message consumer based on the message reading position indicated by the index information only requires persisting the queued message once, which improves the efficiency of message transmission.

Description

METHOD AND APPARATUS FOR TRANSMITTING
MESSAGES, AND DEVICE AND STORAGE MEDIUM THEREOF
TECHNICAL FIELD
[0001] Embodiments of the present disclosure relates to the field of the Internet of things (loT) technologies, and more particularly, relate to a method and apparatus for transmitting messages, and a de vice and storage medium thereof.
BACKGROUND
[0002] A message queue (MQ) refers to a "first-in, first-out" data structure in basic data structures, and is generally configured to solve the problems such as application decoupling, asynchronous messages, and traffic peak clipping. After a producer generates a message and posts the message into a queue, a consumer receives this message in the queue and processes this message accordingly.
[0003] An MQ in related aits is mainly implemented by virtue of message-oriented middleware and a database, or directly cached in a device memory. After a producer sends a message to the MQ, the MQ copies the received message to respective consumption channels, and a consumer then consumes messages from the corresponding consumption channel.
[0004] However, in message transmission methods of tire related arts, a consumer cannot successfully acquire a message until an MQ copies this message to a consumption channel. In the case of many consumption channels, the message transmission efficiency is relatively low, and the consumer may need to wait. In addition, for enhancement of throughput of the MQ, messages may not generally be received or published according to a timing sequence of the messages in the related arts, and hence the sequential consumption requirements of loT edge devices fail to be satisfied.
SUMMARY
[0005] Embodiments of the present disclosure disclose a method and apparatus for transmitting messages, and a device and storage medium thereof.
[0006] According to one aspect, the embodiments of the present disclosure provide a method for transmitting messages.
[0007] llie method includes: persistently writing a queued message sent by a message producer into a disk according to a chronological sequence of message generation time; adjusting a message reading position of a consumption channel based on index information of a message that a message consumer has read and according to a write sequence of the queued message, the message reading position being configured to indicate a storage position of the queued message in the disk; reading the queued message from the disk over the consumption channel based on the message reading position; and sending the queued messages read from the consumption channel to the message consumer in response to the message consumer being online.
[0008] According to another aspect, the embodiments of the present disclosure provide an apparatus for transmitting messages.
[0009] llie apparatus includes: a writing module, configured to persistently writing a queued message sent by a message producer into a disk according to a chronological sequence of message generation time; a first adjusting module, configured to adjust a message reading position of a consumption channel based on index information of a message that a message consumer has read and according to a write sequence of the queued message, the message reading position being configured to indicate a storage position of the queued message in the disk; a reading module, configured to read the queued message from the disk over the consumption channel based on the message reading position; and a sending module, configured to send the queued message read over the consumption channel to the message consumer in response to the message consumer being online.
[0010] According to yet another aspect, the embodiments of the present disclosure provide a computer device. The computer device includes a processor and a memory, wherein the memory is configured to store at least one instruction, at least one program, a code set, or an instruction set therein, wherein the at least one instruction, the at least one program, the code set or the instruction set, when loaded and executed by the processor, causes the processor to perform the method for transmiting messages as described above.
[0011] According to yet still another aspect, the embodiments of the present disclosure prov ide a computer-readable storage medium, storing at least one computer program therein, wherein the at least one computer program, when loaded and run by a processor of a computer device, causes the computer device to perform the method for transmitting messages as described above.
[0012] According to yet still another aspect, the embodiments of the present disclosure provide a computer program product or a computer program. The computer program product or the computer program includes a computer instruction stored in a computer-readable storage medium, wherein the at least one computer instruction, when loaded and executed by a processor of a computer device, causes the computer device to perform the methods for transmitting messages as described above.
[0013] The technical solutions according to the embodiments of the present disclosure at least achieve the following beneficial effects. [0014] In the embodiments of the present disclosure, the queued message sent by the message producer is received and then persisted to the disk, which avoids data loss when the device is abnormal compared to a method of writing the queued message to a memory in the related arts. In addition, the queued message is stored according to the chronological sequence of message generation time, and the message reading position of the consumption channel is adjusted according to the write sequence of the queued message, which meets the demand of an loT edge device for a chronological sequence of messages. Moreo ver, the process of sending the message to the message consumer based on the message reading position indicated by the index information only requires persisting the queued message once, which greatly improves the efficiency of message transmission in the case of more consumption channels compared to a method in which a queued message needs to be sequentially copied to respective consumption channels in the related arts, thereby avoiding a case where a message consumer needs to wait because the message transmission time is too long.
BRIEF DESCRIPTION OF THE DRAWINGS [0015] FIG. 1 is a schematic diagram of an implementation environment according to an exemplary embodiment of the present disclosure;
[0016] FIG. 2 is a flowchart of a method for transmitting messages according to an exemplary embodiment of tire present disclosure:
[0017] FIG. 3 is a flowchart of a method for transmitting messages according to another exemplary embodiment of the present disclosure;
[0018] FIG. 4 is a flowchart of a method for transmiting messages according to yet another exemplary embodiment of the present disclosure;
[0019] FIG. 5 is a flowchart of a method for transmitting messages according to still yet another exemplary' embodiment of the present disclosure;
[0020] FIG. 6 is a flowchart of a method for transmitting messages according to still yet another exemplary embodiment of the present disclosure;
[0021] FIG. 7 is a schematic diagram of a first consumption mode according to an exemplary- embodiment of the present disclosure;
[0022] FIG. 8 is a schematic diagram of a second consumption mode according to an exemplary embodiment of the present disclosure;
[0023] FIG. 9 is a schematic diagram of a third consumption mode according to an exemplary- embodiment of the present disclosure;
[0024] FIG. 10 is a structural block diagram of an apparatus for transmiting messages according to an exemplary- embodiment of the present disclosure; and [0025] FIG. 11 is a structural block diagram of a computer device according to an exemplary embodiment of the present disclosure.
DETAILED DESCRIPTION
[0026] For clearer descriptions of the objectives, technical schemes and advantages of the present disclosure, the embodiments of the present disclosure are illustrated in detail hereinafter with reference to the accompanying drawings.
[0027] The term "a plurality of herein refers to two or more. The term "and/or" herein describes the correspondence of corresponding objects, indicating three kinds of relationship. For example, A and/or B, can be expressed as: A exists alone, A and B exist concurrently, or B exists alone. The symbol generally indicates an "or" relationship between the contextual objects.
[0028] In the related arts, after a message producer sends a message to an MQ, the MQ copies the received message to respective consumption channels, and a message consumer then consumes messages from the corresponding consumption channel. However, in message transmission methods of the related arts, a consumer cannot successfully acquire a message until an MQ copies this message to a consumption channel. In the case of many consumption channels, the message transmission efficiency is relatively low, and tire consumer may need to wait. In addition, m order to improve the throughput of the MQ, messages may not generally be received and published according to a timing sequence of the messages in the related arts, and hence the sequential consumption requirements of loT edge devices fail to be satisfied.
[0029] To solve the above technical problems, an embodiment of the present disclosure provides a method for transmitting messages. According to this method, a message reading position of a consumption channel is adjusted according to a write sequence of a queued message by persisting the queued message to a disk and performing consumption at a message consumer, which meets the demand of an loT edge device for a chronological sequence of messages. Moreover, the process of sending the message to the message consumer based on the message reading position indicated by index information only requires persisting the queued message once, which greatly improves the efficiency of message transmission in the case of more consumption channels, thereby avoiding a case where tire message consumer needs to wait because the message transmission time is too long.
[0030] FIG. 1 is a schematic diagram of an implementation environment according to an embodiment of the present disclosure. A message producer 110 sends a produced queued message to message-oriented middleware 12.0 which then forwards the queued message to a message consumer 130. The message-oriented middleware includes at least one queue topic 121, wherein each queue topic 121 corresponds to a persistent message storage file 122. The message consumer 130 consumes messages over a consumption channel 123 and reads the queued message in the message storage file 122. In the message storage file 122, the queued message is stored according to a chronological sequence of message generation time. The queued message is read over respective consumption channels 123 under the same queue topic 121 according to a chronological sequence of generation time of files in the message storage file 122, and a message reading position is adjusted based on index information of the message consumer 130.
[0031] The message producer 110 and the message consumer 130 may be devices with data generation and data transmission functions, or may be applications. The message producer 110, the message consumer 130 and the message-oriented middleware 120 may belong to the same computer device, or may be respectively provided in independent computer devices.
[0032] FIG, 1 only illustrates one message producer 1 10 and one queue topic 121. In other embodiments, more message producers 110 and more queue topics 121 may be present, wherein one message producer 110 may correspond to a plurality' of queue topics 121, or a plurality of message producers 110 may correspond to the same queue topic 121, which is not limited in this embodiment of the present disclosure.
[0033] FIG. 2 is a flowchart of a method for transmitting messages according to an exemplary embodiment of the present disclosure. This embodiment is described by taking this method being applied to a computer device with message storage and message transmission functions as an example. The method includes the following steps.
[0034] In step 201, a queued message sent by a message producer is persistently written into a disk according to a chronological sequence of message generation time.
[0035] In a possible embodiment, message-oriented middleware in the computer device receives the queued message and then persistently writes the queued message to the disk, e.g., to a disk file configured to store queued messages. In general cases, because a delay may be present in the process of transmitting the message to the message-oriented middleware from the message producer, a sequence in which the queued message actually arrives at the middleware may be inconsistent with a sequence in which the queued message is generated, i.e., the queued message generated by the message producer later arrives at the middleware first. In order to ensure that the queued messages can be stored and consumed according to a generation sequence of the queued messages, and to meet the requirements of an loT edge device for a timing sequence of messages, the computer device achieves message persistence m strict accordance with the chronological sequence of message generation time.
[0036] The message producer may send the queued message together with its time stamp while sending the queued message to the message-oriented middleware, the time stamp being message generation time of the queued message, such that the message-oriented middleware determines a chronological sequence of respective queued messages.
[0037] in an exemplary embodiment, in the case that a message producer generates and sends a queued message every 1 second, a time stamp corresponding to the previous queued message received by the message-oriented middleware is 00:01:00, while a time stamp of the currently received queued message is 00:01:02. Then, the computer device suspends the storage of the currently received queued message, and after a queued message with a time stamp of 00:01:01 arrives, stores this queued message according to a chronological sequence of the time stamps: or the computer device stores the queued messages received at every predetermined duration in a centralized manner, thereby storing the queued messages received within the predetermined duration in a chronological sequence.
[0038] In step 202, a message reading position of a consumption channel is adjusted based on index information of a message that a message consumer has read and according to a write sequence of the queued message, wherein the message reading position is configured to indicate a storage position of the queued message in the disk.
[0039] In a possible embodiment, the message consumer is responsible for maintaining the index information. For example, after the consumption channel of the message-oriented middleware sends one queued message to the message consumer, the message consumer sends the index information to the corresponding consumption channel in the case that the message consumer has successfully received this queued message. Thus, the consumption channel adjusts the message reading position, such that the message reading position moves to the next queued message of the read message.
[0040] It is worth noting that the same consumption channel may correspond to a plurality of message consumers; and a competitive relationship is present among the message consumers corresponding to the same consumption channel, and the message consumers jointly maintain a piece of index information. For example, in the case that a consumption channel A corresponds to a message consumer a and a message consumer b, and a consumption channel C corresponds to a message consumer c, the message consumer c consumes the queued message transmitted by the consumption channel C alone; and the message consumer a and the message consumer b compete to acquire data transmitted by the consumption channel A. That is, a sum of the amount of queued messages consumed by the message consumer a and the amount of queued messages consumed by the message consumer b is the amount of the queued messages transmitted by the consumption channel A. Therefore, the consumption channel can adjust the message reading position in response to receiving the index information sent by' one of the message consumers. [0041] The message-oriented middleware adjusts the message reading position of the consumption channel according to the write sequence of the queued messages in response to receiving the index information. For example, in the case that a queued message 1 and a queued message 2 are sequentially stored in a disk file corresponding to consumption channel A, the message-oriented middleware, after determining from the index information that the message consumer has received the queued message 1, adjusts a message reading position of the consumption channel A from a storage position of the queued message 1 to a storage position of the queued message 2.
[0042] In step 203, the queued message is read from the disk over the consumption channel based on the message reading position.
[0043] The message -oriented middleware, after adjusting the message reading position of the consumption channel, controls the consumption channel to read the queued message corresponding to the message reading position. In this way, this embodiment of the present disclosure can realize the sequential writing and sequential consumption of the queued messages, and ensure that the message consumer can receive the queued messages according to the chronological sequence of message generation time.
[0044] In 204, the queued message read over the consumption channel is sent to the message consumer in response to the message consumer being online.
[0045] The message-oriented middleware sends the queued message read over tire consumption channel to the message consumer in response to the message consumer being online. In some embodiments, the queued message is sent to the message consumer over the consumption channel in the case that the message-oriented middleware detects that the message consumer is online; or the message consumer acquires the queued message from the consumption channel by means of active polling after going online,
[0046] In summary, in this embodiment of the present disclosure, the queued message sent by the message producer is received and then persisted to the disk, which avoids data loss when a device is abnormal compared to a method of writing the queued message to a memory in the related arts. In addition, the queued message is stored according to die chronological sequence of message generation time, and the message reading position of the consumption channel is adjusted according to the write sequence of the queued message, which meets the demand of an IoT edge device for a chronological sequence of messages. Moreover, the process of sending die message to the message consumer based on die message reading position indicated by the index information only requires persisting the queued message once, which greatly improves the efficiency of message transmission in the case of more consumption channels compared to a method in which queued messages need to be sequentially copied to respective consumption channels in the related arts, thereby avoiding a case where a message consumer needs to wait because the message transmission time is too long.
[0047] in tire above embodiments of the present disclosure, the message-oriented middleware persists the queued message sent by the message producer to the disk. In order to facilitate the management of the queued messages and improve a loading speed of the queued messages by the message-oriented middleware, in a possible embodiment, the message-oriented middleware stores message queues in blocks. FIG. 3 is a flowchart of a method for transmitting messages according to still yet another exemplary embodiment of the present disclosure. This embodiment is described by taking this method being applied to a computer device with message storage and message transmission functions as an example. The method includes the following steps.
[0048] In step 301 , a queued message sent by the message producer is acquired.
[0049] The message-oriented middleware in the computer device acquires the queued message sent by the message producer in real time, and persists the acquired queued message to a disk. The persistence of the queued message is asynchronous, i.e., after the message producer sends the queued message to the message-oriented middleware, it is unnecessary to wait for the persistence to end and return. Therefore, the production cycle of the message producer is shorter, and the throughput of the message-oriented middleware can be improved.
[0050] In step 302, the queued message is written into a message storage file based on a data volume of a target message storage file and according to a chronological sequence of message generation time, wherein the target message storage file is a message storage file having the latest file generation time in the disk.
[0051] In an optional embodiment, in order to improve the high availability of the message- oriented middleware and the efficiency of message transmission, the message-oriented middleware stores the queued messages in blocks, which still ensures the security of queued messages in other files in the case that one message storage file is damaged. In addition, when the message-oriented middleware reads the queued messages, it is only necessary' to load a file where a queued message to be read is located, rather than all the message storage files, such that a memor)? size required for message reading is reduced accordingly. Step 302 further includes the following sub-steps.
[0052] In sub-step 302a, the queued message is written into the target message storage file according to the chronological sequence of message generation time in response to the data volume of the target message storage file not reaching a predetermined data volume.
[0053] In a possible embodiment, the message -oriented middleware is preassigned a predetermined data volume (for example, 30M) of a message storage file. The message -oriented middleware writes the queued messages to a message storage file in sequence. When the data volume of the message storage file reaches the predetermined data volume, a new message storage file is created, and queued messages are then continued to be written into the newly created message storage file. The target message storage file refers to a message storage file with the latest file generation time in the disk. The message-oriented middleware confirms the data volume of the target message storage file in response to receiving the queued messages. In the case that the data volume does not reach the predetennined data volume, it is determined that the target message storage file can continue to store queued messages.
[0054] hi sub-step 302b, a newly-built message storage file is generated in response to the data volume of the target message storage file reaching the predetermined data volume, and the queued messages are written into the newly-built message storage file according to the chronological sequence of message generation time.
[0055] In the case that the data volume of the target message storage file reaches the predetennined data volume, the message-oriented middleware needs to create a new message storage file, and write subsequently received queued messages into the newly-built message storage file according to the chronological sequence of message generation time.
[0056] In step 303, a read message storage file corresponding to a read message is determined based on a file identifier in index information, and a storage position of the read message in the read message storage file is determined based on a message identifier in the index information. [0057] The queued message and the message identifier thereof are associatively stored in the message storage file. The index information contains a file identifier of the read message and the message identifier. For example, information such as the message identifiers, the queued messages, time stamps, and message attributes are associatively stored in the message storage file by the message-oriented middleware, such that a consumption channel can determine a storage position of the queued message in the message storage file based on the corresponding message identifier, and the queued message is read over the consumption channel. Since the message-oriented middleware in this embodiment of the present disclosure stores the queued messages in blocks, it is also necessary to set a unique file identifier for each message storage file.
[0058] in an optional embodiment, the message consumer, in response to receiving the queued message, sends index information indicating that queue data has been successfully received to the corresponding consumption channel. The consumption channel, in response to receiving the index information, determines that the message consumer has successfully consumed the corresponding queue data, and adjusts a message reading position based on the index information. [0059] In step 304, the message reading position is moved to a storage position of the next queued message based on the storage position of the read message in the read message storage file and the write sequence of the queued message.
[0060] For example, three message storage files are stored in the disk of the computer device where the message-oriented middleware is located, including a file 1, a file 2, and a file 3. According to the chronological sequence of message generation time, queued messages with message identifiers of 001, 002, and 003, respectively are stored in the file 1; queued messages with message identifiers of 001, 002, and 003, respectively are stored in the file 2; and queued messages with message identifiers of 001 and 002, respectively are stored in the file 3. In the ease that the consumption channel receives index information containing (file 2, 001) sent by the message consumer, the message-oriented middleware moves the message reading position of the consumption channel to (file 2, 002); and in the case that the consumption channel receives index information containing (file 2, 003) sent by the message consumer, the message-oriented middleware moves the message read position of the consumption channel to (file 3, 001).
[0061] In step 305, the queued message is read from the disk over the consumption channel based on the message reading position.
[0062] In step 306, the queued message read over tire consumption channel is sent to the message consumer in response to the message consumer being online.
[0063] For specific implementations of steps 305 to 306, reference may be made to steps 203 to 204, which are not described herein again in this embodiment of the present disclosure.
[0064] In this embodiment of the present disclosure, the message-oriented middleware stores the queued messages in blocks, which still ensures the security of queued messages in other files in the case that one message storage file is damaged. In addition, when the message-oriented middleware reads the queued messages, it is only necessary to load a file where a queued message to be read is located, rather than all the message storage files, such that a memory size required for message reading will be reduced accordingly. In addition, the message-oriented middleware adjusts the message reading positions of the consumption charmels sequentially- based on the index information maintained by the message consumer, without the need to copy the message storage file to the consumption channel, thereby further improving the efficiency of message transmission.
[0065] The above embodiment describes the processes of the message-oriented middleware to receive and store the queued message, and send the message to the message consumer. In a possible embodiment, in order to reduce the disk size occupied by the message storage file, the message-oriented middleware remove a message storage file in a predetermined manner. In addition, since the queued messages are stored in blocks, it is more convenient for the message- oriented middleware to remove files. FIG. 4 is a flowchart of a method for transmitting messages according to still yet another exemplary embodiment of the present disclosure. This embodiment is described by taking this method being applied to a computer device with message storage and message transmission functions as an example. The method includes the following steps.
[0066] In step 401, a message storage file is deleted in response to all queued messages in this message storage file having been acquired by respective consumption channels under a target queue topic.
[0067] in the case that all the queued messages in the message storage file have been acquired by all consumption channels under the target queue topic to which all the queued messages belong, no message consumer acquires the queued message in the message storage file in the future. Therefore, the message storage file may be deleted.
[0068] In an exemplary embodiment, Tope 1 contains a consumption channel A and a consumption channel B, and message storage files corresponding to Tope 1 are file 1 and file 2. When all queued messages in file I are acquired by both the consumption channel A and the consumption channel B, the message-oriented middleware deletes file 1. In a possible embodiment, die message-oriented middleware determines whether a queued message is stored in a message storage file in wliich all queued messages have been acquired by all consumption channels based on the message reading positions of respective consumption channels.
[0069] In step 402, n message storage files having the earliest file creation time in the target queue topic are deleted according to a predetermined file amount in response to the amount of files in the message storage file in the target queue topic in the disk being greater than the predetermined file amount , wherein n is a positive integer.
[0070] In a possible embodiment, the message-oriented middleware is preassigned the maximum amount of message storage files that each queue topic can have, that is, the predetermined file amount.
[0071] In some embodiments, the message-oriented middleware numbers the respective message storage files based on a file generation sequence. When the number corresponding to a newly created message storage file indicates that the amount of message storage files in the target queue topic is greater than the predetermined file amount, the message-oriented middleware performs a file deletion operation; or the message-oriented middleware detects the amount of files in the message storage file corresponding to each queue topic once within every predetermined duration, and removes the files.
[0072] In an exemplar}- embodiment, the amount of predetermined files corresponding to each queue topic is 5. Based on the chronological sequence of file generation time, the message storage files corresponding to Topic 1 include file 1, file 2, file 3, file 4, file 5 and file 6. Then, the message-oriented middleware deletes file 1 in Topic 1. Assuming that a consumption channel whose message reading position is in file 1 before a file is deleted is present, the message- oriented middleware adjusts the message reading position of this consumption channel to a position of a first queued message in file 2.
[0073] In 403, m message storage files having the latest file creation time in the target queue topic are retained in response to no message consumer existing under the target queue topic, and other message storage files in the target queue topic are deleted, wherein m is a positi ve integer. [0074] in a possible embodiment, a message consumer under a queue topic does not consume any message for a long time, or all message consumers cancel their subscriptions to queued messages. That is, it is considered that no message consumer is present under this queue topic. At this time, disk resources may be wasted in the case that the message-oriented middleware saves more message storage files. Therefore, the message-oriented middleware only saves the latest m message storage files.
[0075] In an exemplar}' embodiment, in the case that no message consumer is present under the target queue topic, the message-oriented middleware only retains one latest message storage file in the target queue topic. For example, in the case that no message consumer is present under Topic 1, the message-oriented middleware continuously stores queued messages in file 1. In the case that a data volume of file 1 reaches a predetermined data volume, the message-oriented middleware creates file 2, continues to write queued messages in file 2, and deletes file 1.
[0076] This embodiment of the present disclosure provi des three deletion strategies for message storage files, and a user may set one or more appropriate deletion strategies according to actual business situations, thereby effectively cleaning up the disk.
[0077] In an exemplar}' embodiment, in the case that the above three deletion strategies are employed at the same time, the process of removing a message storage file by the message- oriented middleware is shown in FIG. 5.
[0078] In step 501, the amount of files in a message storage file under a target queue topic is acquired.
[0079] in step 502, whether the amount of files is greater than a predetermined file amount is determined. In the case that the amount of files is greater than the predetermined file amount, step 503 is performed, or step 507 is performed.
[0080] In step 503, message reading positions of respective consumption channels under a target queue topic are acquired.
[0081] In step 504, whether a message reading position needs to be moved is determ ined. In the case that the message reading position needs to be moved, step 505 is performed, or step 506 is performed. [0082] In step 505, the message reading position is moved,
[0083] in step 506, n message storage files with the earliest file creation time in the target queue topic are deleted.
[0084] In step 507, whether a message consumer is present is determined. In the case that the message consumer is present, step 509 is performed: and otherwise, step 508 is performed.
[0085] In step 508, m message storage files with the latest file creation time in the target queue topic are retained, and other message storage files are deleted.
[0086] In step 509, whether all the queued messages in the target message storage file have been acquired by the respective consumption channels is determined. In the case that all the queued messages in the target message storage file have been acquired by the respective consumption channels, step 510 is performed, or the process is ended.
[0087] In step 510, the target message storage file is deleted.
[0088] In the related arts, respective queue topics of the message-oriented middleware usually employ the same consumption mode. However, in an application scenario of loT, many business modules are configured for an edge device, which generate many types of queued messages. Therefore, the consumption modes in the related arts are relatively simple. In order to meet the requirements of the edge device for various business scenarios, the related arts need to deploy more components. In a possible embodiment, queued messages with different atributes belong to different queue topics, the same queue topic contains at least one consumption channel, and each queue topic is assigned a consumption mode, such that the user can set appropriate consumption modes for respective queue topics according to actual business needs, wherein the consumption modes of different queue topics may he different. Based on FIG. 3, referring to FIG. 6, step 302 may further include sub-step 302a,
[0089] In sub-step 302a, the queued messages are written into a message storage file based on the data volume of a target message storage file and the consumption mode corresponding to the queue topic and according to the chronological sequence of message generation time.
[0090] In the case that the consumption mode of the queue topic is a first consumption mode (a normal mode), sub-step 302a includes the following steps.
[0091] In step 1, a queued message is written into the target message storage file according to the chronological sequence of message generation time in response to the data volume of the target message storage file not reaching the predetermined data volume.
[0092] hi step 2, a newly-built message storage file is generated in response to the data volume of the target message storage file reaching the predetermined data volume, and the queued message is written into the newly-built message storage file according to the chronological sequence of message generation time. [0093] In the normal mode, the message-oriented middleware continuously accepts and stores the queued messages sent by the message producer, and continuously sends the queued messages to online message consumers without interfering with each other. That is, die message consumer consumes messages according to the chronological sequence of message generation time in response the message consumer being online; and in the case that the message consumer is offline, the queued messages may not be lost. Therefore, the message-oriented middleware normally stores the queued messages based on the predetermined data volume of the message storage file. As shown in FIG. 7, the flow of die first consumption mode includes: 701, publishing a queued message by a message producer; 702, storing the queued message by the message-oriented middleware; and 703, perfontiing online consumption by a message consumer. [0094] The normal mode is mainly applied to a conventional inter-device communication scenario, or a scenario where a message queue loss is not allowed. For example, a device such as a fan sends collected data to an upstream device, or the message-oriented middleware temporarily stores some messages for subsequent use .
[0095] In the case that the consumption mode of the queue topic is a second consumption mode (a broadcast mode), sub-step 302a includes the following steps.
[0096] In step 3, a queued message is discarded m response to all message consumers under the queue topic being offline.
[0097] In the broadcast mode, for the queued message published by the message producer, the message consumer consumes this queued message when it is online, and does not consume this queued message when it is offline. The message-oriented middleware discards the queued messages received in the ease that the message consumers are all offline. The broadcast mode is mainly used for real-time message deliver}'. For example, an upstream device issues a control instruction to a downstream fan device, and the fan device only needs to receive the latest control instruction online because such messages cannot be backlogged.
[0098] In step 4, the queued message is w'ritten into the message storage file based on the data volume of the target message storage file and according to the chronological sequence of message generation time, in response to the presence of the message consumer in an online state under the queue topic.
[0099] In the case that an online message consumer is present, the message-oriented middleware sends the received queued message to the online message consumer. As showai m FIG. 8, a message transmission process corresponding to the second consumption mode includes: 801, publishing a queued message by a message producer; 802, determining whether the message consumer is online by the message-oriented middleware, in the case that the message consumer is online, performing step 803, or performing step 804; 803, performing online consumption by the message consumer; and 804, discarding the queued message.
[00100] In the case that the consumption mode of the queue topic is a third consumption mode (a timeout mode), the method for transmitting messages in this embodiment of the present disclosure includes the following steps.
[00101] In step 5, a time difference is determined based on a current time and the message generation time of a queued message written at the earliest time in the queue topic.
[00102] In the timeout mode, the message-oriented middleware only retains queued messages within a certain time range. For the timed-out queued messages, the message-oriented middleware will discard them regardless of whether they are consumed by message consumers. [00103] The timeout mode is mainly used for transmitting messages of a notification type. For example, a cloud issues resources to an edge side, and a device on the edge side receives this message and then forwards this message to the message-oriented middleware, and thus notify other devices to update resources. At this time, some devices may be updated quickly, and some devices may be updated slowly, so the message-oriented middleware allows such messages to be stored for a certain duration.
[00104] In step 6, the queued message written at the earliest time is deleted in response to the time difference being greater than a predetermined time difference.
[00105] In tire case that the time difference is greater than the predetermined time difference, the queued message written at the earliest time has timed out, and the message- oriented middleware discards this queued message. As shown in FIG. 9, a message transmission process corresponding to the third consumption mode includes: 901, publishing a queued message by a message producer; 902, determ ining whether the queued message has timed out by the message-oriented middleware, in the case that the queued message has timed out, performing step 903, or performing a step 904; 903, discarding the queued message; and 904, performing online consumption by the message consumer.
[00106] In a possible embodiment, the user may set the consumption mode by setting the attributes of the queue topic, such that the consumption modes of the respective queue topics can be switched at any time according to the needs. A method for transmitting messages in this embodiment of the present disclosure further includes the following steps.
[00107] In step 7, a mode switch instruction is received over a mode switching interface corresponding to the queue topic, the mode switch instruction is configured to set a consumption mode parameter in the mode switching interface.
[00108] In a possible embodiment, a user-oriented mode switching interface is set in the message-oriented middleware, and the user can set the attributes of the queue topic by calling the mode switching interface. The mode switching interface includes consumption mode parameters, and the user may select the corresponding consumption mode over an interactive interface, such that the message-oriented middleware receives the mode switch instruction,
[00109] In step 8, the consumption mode of the queue topic is switched to the consumption mode corresponding to the consumption mode parameter,
[00110] The message-oriented middleware, in response to receiving the mode switch instruction, immediately adjusts the consumption mode parameter to a consumption mode parameter indicated by the mode switch instruction, and continues to store and transmit the queued message based on the consumption mode corresponding to the adjusted consumption mode parameter.
[00111] In this embodiment of the present disclosure, three consumption modes are provided, and each queue topic is assigned a separate consumption mode. In addition, the user can switch the consumption mode of any queue topic at any time, which meets different requirements for message transmission in complex business scenarios at the edge side of loT, improves the efficiency of message transmission, and avoids the storage and transmission of invalid queued messages.
[00112] FIG. 10 is a schematic structural diagram of an apparatus for transmitting messages according to an exemplary embodiment of the present disclosure.
[00113] The apparatus includes: a writing module 1001, configured to persistently writing a queued message sent by a message producer into a disk according to a chronological sequence of message generation time; a first adjusting module 1002, configured to adjust a message reading position of a consumption channel based on index information of a message that a message consumer has read and according to a write sequence of the queued message, wherein the message reading position is configured to indicate a storage position of the queued message in the disk; a reading module 1003, configured to read the queued message from the disk over the consumption channel based on the message reading position; and a sending module 1004, configured to send the queued message read over the consumption channel to the message consumer in response to the message consumer being online.
[00114] In some embodiments, the waiting module 1001 includes: an acquiring unit, configured to acquire the queued message sent by the message producer; and a writing unit, configured to write the queued message into a message storage file based on a data volume of a target message storage file and according to the chronological sequence of message generation time, wherein the target message storage file is a message storage file having the latest file generation time in the disk. [00115] In some embodiments, the first writing module is further configured to: write the queued messages into the target message storage file according to the chronological sequence of message generation time in response to the data volume of the target message storage file not reaching a predetermined data volume; and generate a newly-built message storage file in response to the data volume of the target message storage file reaching the predetermined data volume, and write the queued message into the newly-built message storage file according to the chronological sequence of message generation time.
[00116] In some embodiments, the queued message and a message identifier of the queued message are associatively- stored in the message storage file, and the index information contains a file identifier of the read message and the message i dentifi er; and the first adjusting module 1002 includes: a determining unit, configured to determine a read message storage file corresponding to the read message based on the file identifier in the index information, and determine a storage position of the read message in the read message storage file based on the message identifier in the index information; and an adjusting unit, configured to move the message reading position to a storage position of the next queued message based on the storage position of the read message in the read message storage file and a write sequence of the queued message.
[00117] In some embodiments, the queued messages of different attributes belong to different queue topics, at least one of the consumption channels is included under the same queue topic, and the message consumer acquires the queued message under a target queue topic over a target consumption channel; and the apparatus further includes: a first deleting module, configured to delete the message storage file in response to all the queued messages in the message storage file having been acquired by the respective consumption channels under the target queue topic; and/or, a second deleting module, configured to delete the n message storage files having the earliest file creation time in the target queue topic based on a predetermined file amount in response to the amount of files in the message storage file in the target queue topic in the disk being greater than the predetermined file amount, wherein n is a positive integer; and/or, a third deleting module, configured to retain the m message storage files having the latest file creation time in the target queue topic in response to no message consumer existing under the target queue topic, and delete other message storage files in the target queue topic, wherein m is a positive integer.
[00118] In some embodiments, the queued messages of different attributes belong to different queue topics, at least one of the consumption channels is included under the same queue topic, and each queue topic is assigned a consumption mode; and the writing module is further configured to write the queued message into the message storage file based on the data volume of the target message storage file and the consumption mode corresponding to the queue topic and according to the chronological sequence of message generation time.
[00119] In some embodiments, the consumption mode of the queue topic is a first consumption mode; and the writing unit is further configured to: write the queued message into the target message storage file according to the chronological sequence of message generation time in response to the data volume of the target message storage file not reaching a predetermined data volume; and generate a newly-built message storage file in response to the data volume of the target message storage file reaching the predetermined data volume, and write the queued message into the newly-built message storage file based on the chronological sequence of message generation time.
[00120] In some embodiments, the consumption mode of the queue topic is a second consumption mode; and the writing module is further configured to: discard the queued message in response to the message consumer under the queue topic being offline; and write the queued message into the message storage file based on the data volume of the targe t message storage file and according to the chronological sequence of message generation time, in response to the presence of the message consumer in an online state under the queue topic.
[00121] In some embodiments, tire consumption mode of the queue topic is a third consumption mode; and the apparatus further includes: a determining module, configured to determine a time difference based on a current time and the message generation time of the queued message writen at the earliest time in the queue topic; and a fourth deleting module, configured to delete the queued message written at the earliest time in response to the time difference being greater than a predetermined time difference.
[00122] In some embodiments, the apparatus further includes: a receiving module, configured to receive a mode switch instruction over a mode switching interface corresponding to the queue topic, wherein the mode switch instruction is configured to set a consumption mode parameter in the mode switching interface; and a second adjusting module, configured to switch the consumption mode of the queue topic to the consumption mode corresponding to the consumption mode parameter.
[00123] FIG. 11 is a schematic structural diagram of a computer device according to an exemplary embodiment of the present disclosure. Specifically, the computer device 1100 includes a central processing unit (CPU) 1101, a system memory 1104 including a random access memory 1102 and a read only memory 1103, and a system bus 1105 is connected to the system memory 1104 and the central processing unit 1101. The computer device 1100 further includes a basic input/output system (I/O system) 1106 that facilitates to transmit information between respective devices within the computer, and a mass storage device 1107 configured to store an operating system 1113, an application 1114, and other program modules 1115.
[00124] The basic input/output system 1106 includes a display 1108 configured to display information and an input device 1109, such as a mouse or keyboard, for tire user to input information. The display 1108 and the input device 1109 are both connected to the CPU 1101 via an input/output controller 1110 that is connected to the system bus 1105. The basic I/O system 1106 may further include an input/output controller 1110 configured to receive and process the input from a plurality of other devices, such as a keyboard, a mouse, or an electronic stylus. Similarly, the input/output controller 1110 further provides output to a display screen, a printer, or other types of output devices.
[00125] The mass storage device 1107 is connected to the CPU 1101 by a mass storage controller (not shown) connected to the system bus 1105. The mass storage device 1107 and the related computer-readable mediums provide a non-volatile storage for the computer device 1100. That is, the mass storage device 1107 may include a computer-readable medium (not shown), such as, a hard disk or a drive.
[00126] Without loss of generality, the computer-readable medium may include a computer storage medium and a communication medium. The computer storage medium includes volatile and nonvolatile, removable and non-removable mediums implemented by any method or technology for storing the information, such as, computer-readable instructions, data structures, program modules or other data. The computer storage medium includes a random- access memory' (RAM), a read-only memory (ROM), a flash memory or other solid state storage technologies, a compact disc read-only memory (CD-ROM), a digital versatile disc (DVD) or other optical storage devices, a tape cartridge, a magnetic tape, a magnetic disk storage device or other magnetic storage devices. A person skilled in the art will appreciate that the computer storage medium is not limited to the above ones. The aforesaid system memory 1104 and mass storage device 1107 may be collectively referred to as a memory'.
[00127] Hie memory is configured to store one or more programs therein, which are configured to be executed by the one or more central processing units 1101. The one or more programs contain instructions for implementing the foregoing methods, and are executed by the central processing unit 1101 to implement the methods according to the foregoing method embodiments.
[00128] According to various embodiments of the present disclosure, the computer de v ice 1100 may further be operated by a remote computer connected to the network over the network such as the Internet. That is, the computer device 1100 may be connected to the network 1112 by a network interface unit 1111 connected to the system bus 1105, or may be connected to other types of networks or remote computer systems (not shown) by the network interface unit 1111. [00129] The memory is configured to store one or more programs therein, which include steps that are implemented by a computer device in the methods according to the embodiments of the present disclosure.
[00130] An embodiment of the present disclosure provides a computer-readable storage medium, storing at least one instruction therein, wherein the at least one instruction, when loaded and executed by the processor, causes tire processor to perform any of the methods for transmitting messages as described in above embodiments.
[00131] An embodiment of the present disclosure provides a computer program product or a computer program is provided. The computer program product or the computer program includes a computer instruction stored in a computer-readable storage medium. The computer instruction, when loaded and executed by a processor of the computer device, causes the computer device to perform the methods for transmitting messages according to the embodiments as described above.
[00132] A person skilled in the art should recognize that in one or more examples, the functions described in the embodiments of the present disclosure may be implemented in hardware, software, firmware or any combination thereof. In the case that the functions are implemented in software, these functions may be stored in a computer-readable storage medium, or transmitted over as one or more instructions or codes in the computer-readable storage medium. The computer-readable storage medium includes a computer storage medium and a communication medium. The communication medium includes any medium that may be configured to transmit computer programs from one location to another location. The storage medium may be any available medium that is accessible by a general or special computer.
[00133] Described above are merely exemplary7 embodiments of the present disclosure, and are not intended to limit the present disclosure. Within the spirit and principles of the present disclosure, any modifications, equivalent substitutions, improvements, and the like are within the protection scope of the present disclosure.

Claims

CLAIMS What is claimed is:
1. A method for transmitting messages, comprising: persistently writing a queued message sent by a message producer into a disk according to a chronological sequence of message generation time; adjusting a message reading position of a consumption channel based on index information of a message that a message consumer has read and according to a write sequence of the queued message, the message reading position being configured to indicate a storage position of the queued message in the disk; reading the queued message from the disk over the consumption channel based on the message reading position; and sending the queued message read over the consumption channel to the message consumer in response to the message consumer being online.
2. The method according to claim 1, wherein persistently writing the queued message sent by the message producer into the disk according to the chronological sequence of message generation time comprises: acquiring the queued message sent by the message producer; and writing the queued message into a message storage file based on a data volume of a target message storage file and according to the chronological sequence of message generation time, the target message storage file being a message storage file having a latest file generation time in the disk.
3. The method according to claim 2, wherein writing the queued messages into the message storage file based on the data volume of the target message storage file and according to the chronological sequence of message generation time comprises: writing the queued message into the target message storage file according to the chronological sequence of message generation time in response to the data volume of the target message storage file not reaching a predetermined data volume; and generating a newly-built message storage file in response to the data volume of the target message storage file reaching the predetermined data volume, and writing the queued message into the newly-built message storage file according to the chronological sequence of message generation time.
4. The method according to claim 2, wherein the queued message and a message identifier of the queued message are associatively stored in the message storage file, and the index information contains a file identifier of the read message and the message identifier; and adjusting the message reading position of the consumption channel based on the index information of the message that the message consumer has read and according to the write sequence of the queued message comprises: determining a read message storage file corresponding to the read message based on the file identifier in the index information, and determining a storage position of the read message in the read message storage file based on the message identifier in the index information; and moving the message reading position to a storage position of a next queued message based on the storage position of the read message in the read message storage file and the write sequence of the queued message.
5. The method according to any one of claims 2 to 4, wherein the queued messages of different attributes belong to different queue topics, at least one of the consumption channels is included under the same queue topic, and the message consumer acquires the queued message under a target queue topic over a target consumption channel; and the method further comprises: deleting the message storage file in response to all the queued messages in the message storage file having been acquired by the respective consumption channels under the target queue topic; and/or, deleting the n message storage files having the earliest file creation time in the target queue topic based on a predetermined file amount in response to the amount of files in the message storage file in the target queue topic in the disk being greater than a predetermined file amount, n being a positive integer; and/or, retaining the m message storage files having the latest file creation time in the target queue topic in response to no message consumer existing under the target queue topic, and deleting other message storage files in the target queue topic, m being a positive integer.
6. The method according to claim 2, wherein the queued messages of different attributes belong to different queue topics, at least one of the consumption channels is included under the same queue topic, and the queue topic is assigned a consumption mode; and writing the queued message into the message storage file based on the data volume of the target message storage file and according to the chronological sequence of message generation time comprises: writing the queued message into the message storage file based on the data volume of the target message storage file and the consumption mode corresponding to the queue topic and according to the chronological sequence of message generation time.
7. The method according to claim 6, wherein the consumption mode of the queue topic is a first consumption mode; and writing the queued message into the message storage file based on the data volume of the target message storage file and the consumption mode corresponding to the queue topic and according to the chronological sequence of message generation time comprises: writing the queued message into the target message storage file based on the chronological sequence of message generation time in response to the data volume of the target message storage file not reaching a predetermined data volume; and generating a newly-built message storage file in response to the data volume of the target message storage file reaching the predetermined data volume, and writing the queued message into the newly-built message storage file based on the chronological sequence of message generation time.
8. The method according to claim 6, wherein the consumption mode of the queue topic is a second consumption mode; and writing the queued message into the message storage file based on the data volume of the target message storage file and the consumption mode corresponding to the queue topic and according to the chronological sequence of message generation time comprises: discarding the queued message in response to all of the message consumers under the queue topic being offline; and writing the queued message into the message storage file based on the data volume of the target message storage file and according to the chronological sequence of message generation time, in response to presence of the message consumer in an online state under the queue topic.
9. The method according to claim 6, wherein the consumption mode of the queue topic is a third consumption mode; and the method further comprises: determining a time difference based on a current time and the message generation time of the queued message written at the earliest time in the queue topic; and deleting the queued message written at the earliest time in response to the time difference being greater than a predetermined time difference.
10. The method according to any one of claims 6 to 9, further comprising: receiving a mode switching instruction over a mode switching interface corresponding to the queue topic, the mode switching instruction being configured to set a consumption mode parameter in the mode switching interface; and switching the consumption mode of the queue topic to the consumption mode corresponding to the consumption mode parameter.
11. An apparatus for transmitting messages, comprising: a writing module, configured to persistently writing a queued message sent by a message producer into a disk according to a chronological sequence of message generation time; a first adjusting module, configured to adjust a message reading position of a consumption channel based on index information of a message that a message consumer has read and according to a write sequence of the queued message, the message reading position being configured to indicate a storage position of the queued message in the disk; a reading module, configured to read the queued message from the disk over the consumption channel based on the message reading position; and a sending module, configured to send the queued message read over the consumption channel to the message consumer in response to the message consumer being online.
12. A computer device, comprising a processor and a memory, wherein the memory is configured to store at least one instruction, at least one program, a code set, or an instruction set therein, wherein the at least one instruction, the at least one program, the code set or the instruction set, when loaded and executed by the processor, causes the processor to perform the method for transmitting messages as defined in any one of claims 1 to 10.
13. A computer-readable storage medium, storing at least one computer program therein, wherein the at least one computer program, when loaded and run by a processor of a computer device, causes the computer device to perform the method for transmitting messages as defined in any one of claims 1 to 10.
PCT/SG2022/050123 2021-03-29 2022-03-11 Method and apparatus for transmitting messages, and device and storage medium thereof WO2022211724A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110335960.3 2021-03-29
CN202110335960.3A CN112965839B (en) 2021-03-29 2021-03-29 Message transmission method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
WO2022211724A1 true WO2022211724A1 (en) 2022-10-06

Family

ID=76278874

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/SG2022/050123 WO2022211724A1 (en) 2021-03-29 2022-03-11 Method and apparatus for transmitting messages, and device and storage medium thereof

Country Status (2)

Country Link
CN (1) CN112965839B (en)
WO (1) WO2022211724A1 (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113656199A (en) * 2021-08-19 2021-11-16 深圳华锐金融技术股份有限公司 Service message transmission method, device, computer equipment and storage medium
CN116028511A (en) * 2021-10-25 2023-04-28 福建天晴在线互动科技有限公司 A ClickHouse data writing method and server
CN114490138A (en) * 2022-02-16 2022-05-13 平安普惠企业管理有限公司 Message distributed processing method, device, computer equipment and storage medium
CN114640707A (en) * 2022-03-04 2022-06-17 微位(深圳)网络科技有限公司 Message asynchronous processing method and device, electronic equipment and storage medium
CN114666292A (en) * 2022-04-01 2022-06-24 广州大学 Instant messaging technology method, system and medium
CN116112518A (en) * 2022-12-15 2023-05-12 漳州立达信光电子科技有限公司 Method, system, and storage medium for cloud-edge collaborative message exchange of Internet of Things
CN117931484B (en) * 2024-03-22 2024-06-14 中国人民解放军国防科技大学 Message consumption method, device, equipment and storage medium based on sliding window

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104092767A (en) * 2014-07-21 2014-10-08 北京邮电大学 A publish/subscribe system with added message queue model and its working method

Family Cites Families (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9256477B2 (en) * 2014-05-29 2016-02-09 Netapp, Inc. Lockless waterfall thread communication
US10230670B1 (en) * 2014-11-10 2019-03-12 Google Llc Watermark-based message queue
CN110321215A (en) * 2018-03-29 2019-10-11 华为技术有限公司 Queue control method and device
US10810064B2 (en) * 2018-04-27 2020-10-20 Nasdaq Technology Ab Publish-subscribe framework for application execution
CN110720096B (en) * 2019-07-03 2022-07-08 深圳市速腾聚创科技有限公司 Multi-sensor state estimation method and device and terminal equipment
CN111400056B (en) * 2019-12-31 2023-07-28 远景智能国际私人投资有限公司 Message transmission method, device and equipment based on message queue
CN111381987A (en) * 2020-03-13 2020-07-07 北京金山云网络技术有限公司 Message processing method and device, electronic equipment and medium
CN111858095B (en) * 2020-07-17 2022-06-10 山东云海国创云计算装备产业创新中心有限公司 Hardware queue multithreading sharing method, device, equipment and storage medium
CN112527528B (en) * 2020-12-18 2025-05-16 平安科技(深圳)有限公司 Data transmission method, device and storage medium based on message queue

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104092767A (en) * 2014-07-21 2014-10-08 北京邮电大学 A publish/subscribe system with added message queue model and its working method

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
"ActiveMQ in Action", 30 December 2011, MANNING, US, ISBN: 1-933988-94-0, article BRUCE SNYDER, DEJAN BOSANAC, ROB DAVIES: "Chapter 5. ActiveMQ message storage", pages: 96 - 116, XP009540394 *
ANONYMOUS RED: "Red Hat AMQ 6.3 Configuring Broker Persistence", RED HAT, 23 October 2020 (2020-10-23), XP055976718, Retrieved from the Internet <URL:https://access.redhat.com/documentation/zh-cn/red_hat_amq/6.3/pdf/configuring_broker_persistence/red_hat_amq-6.3-configuring_broker_persistence-en-us.pdf> [retrieved on 20221101] *

Also Published As

Publication number Publication date
CN112965839B (en) 2024-01-05
CN112965839A (en) 2021-06-15

Similar Documents

Publication Publication Date Title
WO2022211724A1 (en) Method and apparatus for transmitting messages, and device and storage medium thereof
CN107197015B (en) Message processing method and device based on message queue system
CN111212100B (en) Synchronization method and system of message queue publish and subscribe
US9160699B2 (en) Client responsibilities in messaging systems
CN107613529B (en) Message processing method and base station
CN103493449A (en) Effective circuits in packet-switched networks
EP2830269A1 (en) Message processing method and device
CN112148644B (en) Method, apparatus and computer program product for processing input/output requests
CN111475759A (en) Message pushing platform, method, device, server and storage medium
CN116661705B (en) Data management method, system, electronic equipment and storage medium based on kafka
CN109726024A (en) A kind of message delay delivering method, device and equipment
CN111416823A (en) Data transmission method and device
CN112486888A (en) Market data transmission method, device, equipment and medium
CN111984198A (en) Message queue implementation method and device and electronic equipment
CN114500546B (en) Communication message sending method, device and equipment based on load balancing cluster
US9268621B2 (en) Reducing latency in multicast traffic reception
CN109032821B (en) Automatic driving subject message processing method, device, equipment and storage medium
CN114827049A (en) Accumulated data consumption method based on kafka, terminal equipment and storage medium
CN114186163A (en) An application layer network data caching method
WO2024183581A1 (en) Io data processing method and apparatus, device, and medium
CN115460152A (en) Method, system, storage medium and electronic device for controlling multicast message
CN117909087B (en) Data processing method and device, central processing unit and electronic equipment
CN117675720B (en) Message transmission method and device, electronic equipment and storage medium
CN118331498A (en) Data synchronization method and device, storage medium and electronic device
CN110968641B (en) Data writing control method and device and electronic equipment

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: 22781761

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: 22781761

Country of ref document: EP

Kind code of ref document: A1