WO2020238365A1 - Message consumption method, apparatus and device, and computer storage medium - Google Patents

Message consumption method, apparatus and device, and computer storage medium Download PDF

Info

Publication number
WO2020238365A1
WO2020238365A1 PCT/CN2020/080930 CN2020080930W WO2020238365A1 WO 2020238365 A1 WO2020238365 A1 WO 2020238365A1 CN 2020080930 W CN2020080930 W CN 2020080930W WO 2020238365 A1 WO2020238365 A1 WO 2020238365A1
Authority
WO
WIPO (PCT)
Prior art keywords
message
thread
consumption
node
queue
Prior art date
Application number
PCT/CN2020/080930
Other languages
French (fr)
Chinese (zh)
Inventor
黄山
尹强
王和平
刘有
杨峙岳
邸帅
卢道和
Original Assignee
深圳前海微众银行股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳前海微众银行股份有限公司 filed Critical 深圳前海微众银行股份有限公司
Publication of WO2020238365A1 publication Critical patent/WO2020238365A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/51Discovery or management thereof, e.g. service location protocol [SLP] or web services
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • This application relates to the field of big data technology of financial technology (Fintech), in particular to message consumption methods, devices, equipment and computer storage media.
  • Single-threaded consumption uses a single thread to monitor the message queue. Once the consumer thread obtains a new message, it needs to complete the delivery of the message to all locals. The next message can be consumed only after the process of other services, but this method has serious defects in performance.
  • Multi-threaded consumption uses multiple threads to monitor the same message queue at the same time. As long as a new message appears in the queue, there will be a random thread to obtain it, and then independently complete the delivery process to other local services, but this method cannot guarantee that the message is consumed It is not applicable in scenarios where the order of message state migration is required, which has a great impact on the available range of message consumption and makes the available range smaller. Therefore, how to achieve orderly consumption of messages with high concurrency and high availability has become a technical problem to be solved urgently.
  • the main purpose of this application is to propose a message consumption method, device, equipment, and computer storage medium, aiming to solve the technical problem of how to achieve orderly consumption of messages with high concurrency and availability.
  • this application provides a message consumption method, which includes the following steps:
  • the current message is delivered to the target thread for consumption until the traversal of messages in the new message queue is completed.
  • the present application also provides a message consumption device, the message consumption device including:
  • the obtaining module is used to obtain the target node in the zookeeper service registration directory, and determine whether there is a new message queue monitored for the first time in each of the message queues based on the target node monitoring a preset number of message queues;
  • the determining module is configured to, if there is a new message queue monitored for the first time, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm;
  • the delivery module is used to deliver the current message to the target thread for consumption until the message traversal in the new message queue is completed.
  • the present application also provides a message consumption device, the message consumption device comprising: a memory, a processor, and computer-readable instructions stored on the memory and running on the processor, When the computer-readable instructions are executed by the processor, the steps of the message consumption method described above are implemented.
  • the present application also provides a computer storage medium having computer readable instructions stored thereon, and when the computer readable instructions are executed by a processor, the above message consumption method is implemented. step.
  • This application obtains the target node in the zookeeper's service registration directory and monitors a preset number of message queues based on the target node to determine whether there is a new message queue monitored for the first time in each of the message queues; if there is a new message queue monitored for the first time Message queue, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm; deliver the current message to the target thread Consumption is performed until the traversal of the messages in the new message queue is completed.
  • the messages in the new message queue will be traversed and consumed sequentially, thereby ensuring the orderly consumption of messages .
  • the order in which the messages are consumed is consistent with the order in the queue, and since the target thread is determined according to the message, and then the message is passed to the target thread for consumption, it also achieves orderly consumption of messages with high concurrency and high availability Effect.
  • FIG. 1 is a schematic diagram of a device structure of a hardware operating environment involved in a solution of an embodiment of the present application
  • FIG. 3 is a schematic diagram of device modules of the message consumption device of this application.
  • Figure 4 is a schematic diagram of the node structure of zookeeper in the message consumption method of this application.
  • Figure 5 is a flow chart of message flow in the message consumption method of this application.
  • FIG. 1 is a schematic diagram of the device structure of the hardware operating environment involved in the solution of the embodiment of the present application.
  • the message consumption device in the embodiment of the present application may be a PC or a server device, on which a Java virtual machine runs.
  • the message consumption device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002.
  • the communication bus 1002 is used to implement connection and communication between these components.
  • the user interface 1003 may include a display screen (Display) and an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface.
  • the network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).
  • the memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a magnetic disk memory.
  • the memory 1005 may also be a storage device independent of the foregoing processor 1001.
  • FIG. 1 does not constitute a limitation on the device, and may include more or fewer components than those shown in the figure, or a combination of certain components, or different component arrangements.
  • a memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and computer readable instructions.
  • the network interface 1004 is mainly used to connect to a back-end server and communicate with the back-end server;
  • the user interface 1003 is mainly used to connect to a client (user side) and communicate with the client;
  • the processor 1001 can be used to call computer-readable instructions stored in the memory 1005 and perform operations in the following message consumption method.
  • FIG. 2 is a schematic flowchart of a first embodiment of a message consumption method according to this application.
  • the method includes:
  • Step S10 Obtain a target node in the service registration directory of the distributed coordination service zookeeper, and determine whether there is a new message queue monitored for the first time in each of the message queues based on the target node monitoring a preset number of message queues;
  • Zookeeper distributed coordination service
  • Distributed applications can implement functions such as data publishing/subscription, load balancing, naming services, distributed coordination/notification, cluster management, Master election, distributed locks, and distributed queues based on Zookeeper.
  • the message queue can be responsible for the orderly storage of messages for the storage mechanism.
  • the new message queue can be a message queue that has not been monitored by the message consumer corresponding to the temporary node before the current moment, and the message consumer can be used as a client to obtain messages from the message server, and the message server is used as a server to provide core message services .
  • the target node can be a node representing itself created by the message consumer under the zookeeper's service registration directory, and there can be many types of target nodes. In this embodiment, only the target node is a temporary node for illustration, but not The representative target node is limited to one type of temporary node.
  • a directory is established under zookeeper as a message queue, and a monitoring mechanism provided by zookeeper is used to implement a message broadcasting mechanism.
  • each message consumer will establish a temporary node (that is, the target node) on behalf of itself in the zookeeper's service registration directory during the initialization phase, so you need to first obtain the temporary node in the zookeeper's service registration directory (the temporary node is in the message Consumers will be automatically deleted after losing connection with zookeeper), and according to the temporary node, they will monitor a preset number of message queues (any number set by the user in advance, which can be one or multiple) to determine which ones are being monitored.
  • the message consumer will obtain all the existing messages in the queue and consume them in order. If there is no new message queue monitored for the first time, it will continue to detect whether there are new message node generations in the monitored message queue, and perform different operations according to the detection results.
  • each temporary node can simultaneously monitor their corresponding message queues.
  • each temporary node can simultaneously monitor their corresponding message queues.
  • FIG 4 when there are three temporary nodes in the zookeeper's service registration directory, namely service 1, service 2, and service 3, and there are two message queues, namely queue 1 and queue 2, in Queue 1 includes message 1, message 2, message 3, and message 4, and queue 2 also includes message 1, message 2, message 3, and message 4.
  • queue 1 and queue 2 Assuming that both service 1 and service 2 need to listen to message 1 in queue 1, service 1 and service 2 can simultaneously obtain message 1 in queue 1 for consumption, and after consumption is completed, it will be generated in the child node under message 1 Temporary child node service 1 and service 2.
  • service 2 not only monitors message 1 in queue 1, but also monitors message 2 in queue 1 and message 1 in queue 2. Similarly, when message consumption is completed After that, temporary child node service 1 is generated in the child nodes of message 2 in queue 1 and message 1 in queue 2 respectively.
  • the nodes in zookeeper can be divided into four types of nodes, namely persistent nodes, persistent sequential nodes, temporary nodes, and temporary sequential nodes. Among them, after the persistent node is created, it will always exist until there is a delete operation to actively clear the node. In this embodiment, the directory where the message queue is located can use this node.
  • the basic characteristics of persistent sequential nodes are the same as those of persistent nodes.
  • the additional characteristic of persistent sequential nodes is that each parent node maintains a sequence for its first-level child nodes, and records the creation of each child node In this embodiment, this node can be used to carry the message body, and use its natural order to realize the orderly storage of messages in the queue.
  • the message body can be used as a carrier to carry the message.
  • the content is generally a data packet encoded according to the protocol.
  • the temporary node is automatically deleted after the client loses the connection with the zookeeper.
  • the automatic removal function of this node can be used to ensure that abnormal consumers will not affect the cleaning of messages and reduce the accumulation of messages.
  • the basic characteristics of the temporary sequence node are the same as the temporary node.
  • the additional feature of the temporary sequence node is that each parent node maintains a sequence for its first-level child nodes, and records the creation of each child node
  • this node can be used to implement distributed locks.
  • the message producer that is, the client is responsible for transmitting messages to the message server
  • Step S20 If there is a new message queue monitored for the first time, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm;
  • the current message can be a message being traversed in the new message queue.
  • a thread can be the smallest unit that the operating system can perform operation scheduling. When it is judged that there is a message queue that is monitored for the first time, you can traverse each message in the new message queue in turn, and obtain the current message currently traversed in each message, and then determine the current message corresponding to the preset feature recognition algorithm The target thread. It should be noted that if there are two or more new message queues that are monitored for the first time, each new message queue can be traversed separately at the same time to consume messages.
  • the feature recognition algorithm is to ensure that messages of the same category can be distributed locally to the same thread for orderly consumption.
  • users can select some fields in the message as the basis for feature recognition. If the values of these fields are consistent, they can be considered as the same type of message, which means that each type of message needs to be given a guarantee Numbers that will not be repeated are used as characteristic information.
  • the message consumer receives the message, it will read the characteristic information, and perform the residual operation according to the capacity of the local consumption thread pool, and put the message into the thread marked with the residual result.
  • the feature recognition algorithm will be combined with the current abnormal monitoring results of the thread pool. Under the premise that the thread processing sequence is understood and synchronized, the thread mark is adjusted to prevent the peak consumption of a certain type of message from being too long.
  • step S30 the current message is delivered to the target thread for consumption until the traversal of messages in the new message queue is completed.
  • the current message can be directly passed to the target thread for consumption, and when the current message is consumed through the target thread, the message consumer will have a separate monitoring thread to poll the distribution thread Robustness. If a thread is found to be in an abnormal state, the standby thread will be activated immediately to ensure the stability of consumption. And after the current message is consumed in the target thread, it will continue to traverse each message in the new message queue until the traversal of each message is completed.
  • a message producer for example, a business party that has business interactions with financial institutions such as banks, where the business includes but is not limited to loan business, deposit business, etc.
  • a message queue When the message queue sends a message, it will trigger the zookeeper's monitoring mechanism. Zookeeper will send a notification to all message consumers listening to the directory. After receiving the notification, the message consumer (such as a bank and other financial institutions) will respond according to the content of the notification. Get the message in the message node.
  • the message consumer manages all the threads responsible for local distribution of messages through an ordered thread pool, when receiving a message, it will analyze the characteristics of the message according to the feature recognition algorithm, and combine the size of the thread pool. Determine which distribution thread the message should enter to ensure that messages with the same characteristics can always be consumed in an orderly manner.
  • each message node is periodically detected in zookeeper, and after it is determined that a message node has been consumed by all message consumers, the message in the message node can be cleaned up.
  • the target node in the zookeeper's service registration directory by acquiring the target node in the zookeeper's service registration directory, and monitoring a preset number of message queues based on the target node, it is determined whether there is a new message queue monitored for the first time in each of the message queues; For the new message queue, the messages in the new message queue are sequentially traversed, the current message currently traversed is obtained, and the target thread corresponding to the current message is determined based on the preset feature recognition algorithm; the current message is delivered to the target The thread consumes until the traversal of the messages in the new message queue is completed.
  • the messages in the new message queue will be traversed and consumed sequentially, thereby ensuring the orderly consumption of messages .
  • the order in which the messages are consumed is consistent with the order in the queue, and since the target thread is determined according to the message, and then the message is passed to the target thread for consumption, it also achieves orderly consumption of messages with high concurrency and high availability Effect.
  • a second embodiment of the message consumption method of this application is proposed.
  • This embodiment is a refinement of the step S20 of the first embodiment of the present application.
  • the step of determining the target thread corresponding to the current message based on a preset feature recognition algorithm includes:
  • Step S21 receiving feature information corresponding to the current message at the top-level interface corresponding to the current message, and identifying the feature information based on a preset feature recognition algorithm;
  • the user-defined feature information corresponding to the current message can be received in the top-level interface corresponding to the current message, and when the user defines the message, some fields in the message can be selected as the basis for feature identification, and the values of these fields can be used as feature information.
  • the feature information in the current message can be identified and restored through the preset feature recognition algorithm, so as to determine which thread the message should be consumed by the feature information, and to ensure that messages with the same feature must have Ordered to be consumed.
  • Step S22 Determine the target thread corresponding to the current message according to the characteristic information.
  • the characteristic information of the same type of messages is the same, and the characteristic information of different types of messages are different, after obtaining the characteristic information corresponding to the current information, you can determine which thread is consuming the characteristic information of the message in the thread pool The characteristic information of the current message is the same, that is, the target thread is determined.
  • the characteristic information of the current message is acquired according to the preset characteristic recognition algorithm, and the target thread is determined according to the characteristic information, thereby ensuring that the current message acquires a suitable thread for consumption and guarantees the efficiency of message consumption.
  • the step of determining the target thread corresponding to the current message according to the characteristic information includes:
  • Step S221 Obtain a thread pool corresponding to the target node, perform a remainder operation according to the capacity of the thread pool and the characteristic information, acquire a first thread with a remainder result mark in the thread pool, and detect all State whether the first thread is in an abnormal state;
  • the thread pool can be a collection of all threads. After obtaining the characteristic information corresponding to the current message, it is also necessary to obtain the thread pool corresponding to the target node, and determine the capacity of the thread pool, and then perform the remainder operation according to the capacity and characteristic information of the thread pool to determine which thread in the thread pool.
  • the characteristic information of the consumed message is the same as the characteristic information of the current message, and the capacity is the largest, so it can be used as the first thread with the remainder result mark. And after acquiring the first thread, it is also necessary to check whether the first thread is in an abnormal state (that is, to check whether the first thread can normally perform the operation of consuming messages), and perform different operations according to the check result.
  • Step S222 if the first thread is in an abnormal state, enable the standby thread in the thread pool, and use the standby thread as the target thread corresponding to the current message;
  • the emergency mechanism When the first thread is found to be in an abnormal state after judgment, the emergency mechanism will be triggered.
  • the mechanism will use the pre-initialized backup thread to replace the abnormal thread, and roll back the local state according to the abnormal scope, and then continue to consume.
  • the thread is the target thread corresponding to the current message. It should be noted that in this embodiment, each step of message consumption is monitored. Once a link fails, times out, or the throughput is lower than the threshold, the emergency mechanism will be triggered. It is not limited to the detection of the first step. Triggered when a thread is in an abnormal state.
  • Step S223 If the first thread is in a normal state, use the first thread as the target thread corresponding to the current message.
  • the first thread When the first thread is found to be in a normal state after judgment, the first thread can be directly used as the target thread corresponding to the current message, and the current message is delivered to the target thread for consumption.
  • step S10 of the first embodiment of the present application each location is determined After the steps of whether there is a new message queue monitored for the first time in the message queue, include:
  • Step S50 if there is no new message queue monitored for the first time, detect whether there is a new message node in each of the message queues;
  • Step S60 If there is a new message node, obtain the new message in the new message node, and deliver the new message to the second thread corresponding to the new message node for consumption.
  • Zookeeper When it is judged that a new message node is generated, the monitoring mechanism of zookeeper will be triggered. Zookeeper will send a notification to all consumers who monitor the message queue where the new message node is located. After the message consumer receives the notification, it will follow The content of the notification pulls the new message in the new message node from zookeeper, calculates and determines the second thread corresponding to the new message node through a preset feature recognition algorithm, and delivers the new message to the second thread for consumption.
  • the new message may be a message carried by the new message node.
  • the second thread may be the thread used by the new message to be consumed.
  • the new message is directly obtained and consumed through the second thread, thereby ensuring the efficiency of message consumption.
  • the step of delivering the new message to the second thread corresponding to the new message for consumption it includes:
  • Step S70 Obtain the total message queue in zookeeper, and periodically determine whether there is a consumed message node whose consumption is completed in each message node in the total message queue, wherein the total message queue includes a message queue;
  • the total message queue can be all message queues in zookeeper.
  • the preset time period can be any time period set by the user.
  • the consumed message node may be a message node where the message has been consumed by each message consumer.
  • User self-definition is when users of middleware define messages, they can assign status to the message by inheriting interface fields.
  • the automatic identification of middleware is to actively analyze the field value of the same type of message in the process of message cleaning to determine whether the message has been merged by other messages.
  • the information carried by other messages is merged, it intelligently judges the status information of the message. To ensure that even if the user-defined status information has errors, it can still be corrected to maintain the effectiveness of message cleaning. Among them, the messages in the transition state will be cleaned up in time after confirming that they are completely consumed. Therefore, it is necessary to determine whether each message node is a transition message that does not need to be persisted. If it is judged that there is a message node as a transition message, it will be compared. If the temporary child node under the message node and the temporary node under the service registration directory are consistent, it proves that the message in the message node has been consumed by all message consumers, and it can be considered as each message node in the total message queue.
  • the temporary child node may be a temporary child node that the message consumer creates under the message node after receiving the message in the message node, which represents itself, as a basis for the message to be delivered.
  • Step S80 if it exists, extract and save important information in the consumed message node, and clear the consumed message node in the total message queue.
  • the message in the message node When it is judged that there is a consumed message node in the total message queue, that is, it can be consumed by all message consumers listening to the message node by default. At this time, the message in the message node is in a transition state, then the transition The important information in the message is extracted, and the important information can be stored in the persistent state according to the message merging mechanism in zookeeper, so that when the user wants to view the important information later, he can query it in time and conveniently. After extracting and saving When the important information in the message node has been consumed, the consumed message node can be cleaned up. Among them, if there is no persistent state message in zookeeper, you can create a persistent node by yourself to save important information. When it is found after judgment that the message node in the total message queue has not been consumed, the message in the message node is kept unchanged.
  • step S30 of the first embodiment of this application the current message is transferred to all After the steps for the target thread to consume, include:
  • Step A10 detecting whether the current message is successfully consumed in the target thread
  • the current message When the current message is passed to the target thread for consumption, it is also necessary to check whether the current message is successfully consumed in the target thread. If the consumption is successful, the next message consumption will be executed. If the consumption is not successful, the recovery mechanism will be triggered to compensate consumption.
  • Step A20 If the current message is not successfully consumed in the target thread, obtain the version value corresponding to the current message, and compensate the consumption according to the version value.
  • the consumption is compensated until the consumption is successful, thereby avoiding the influence of the consumption failure on the entire system logic.
  • the step of obtaining the version value corresponding to the current message and compensating consumption according to the version value includes:
  • Step A21 Obtain the queue version value of the current message in the message queue and the local version value of the current message in the zookeeper, and calculate the difference between the local version value and the queue version value Whether the difference is greater than the preset value;
  • the version value includes the local version value and the queue version value.
  • the message consumer will record the version value of the current message queue after each message consumption, and before each message consumption, it will also compare the local version value in zookeeper with the version value in the message queue. If two are found If the difference between the two is greater than the preset value, a compensation operation is performed, and if the difference between the two is less than or equal to the preset value, the current message consumption operation is continued.
  • the preset value can be any value set by the user, such as 1.
  • Step A22 If the difference between the local version value and the queue version value is greater than a preset value, the current message is compensated for consumption according to the difference.
  • the number of messages with errors will be calculated based on the difference, and the consumption will be compensated until the consumption is successful.
  • the present application also provides a message consumption device.
  • the message consumption device includes:
  • the obtaining module is used to obtain the target node in the zookeeper service registration directory, and determine whether there is a new message queue monitored for the first time in each of the message queues based on the target node monitoring a preset number of message queues;
  • the determining module is configured to, if there is a new message queue monitored for the first time, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm;
  • the delivery module is used to deliver the current message to the target thread for consumption until the message traversal in the new message queue is completed.
  • the determining module is also used for:
  • the determining module is also used for:
  • the first thread is in a normal state, use the first thread as the target thread corresponding to the current message.
  • the message consumption device further includes:
  • the new message in the new message node is acquired, and the new message is delivered to the second thread corresponding to the new message node for consumption.
  • the message consumption device further includes:
  • the message consumption device further includes:
  • the description version value corresponding to the current message is obtained, and the consumption is compensated according to the version value.
  • the version value includes a local version value and a queue version value
  • the message consumption device further includes:
  • the current message is compensated for consumption according to the difference.
  • the present application also provides a computer storage medium, which may be a non-volatile readable storage medium.
  • the computer storage medium of the present application stores computer-readable instructions, and the computer-readable instructions implement the steps of the message consumption method described above when the computer-readable instructions are executed by the processor.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)
  • Debugging And Monitoring (AREA)
  • Financial Or Insurance-Related Operations Such As Payment And Settlement (AREA)

Abstract

Disclosed is a message consumption method, relating to the field of fintech. The method comprises: acquiring a target node in a service registration directory of a distributed coordination service ZooKeeper, and monitoring, on the basis of the target node, a preset number of message queues to determine whether the message queues include a new message queue monitored for the first time; if there is a new message queue monitored for the first time, traversing messages in the new message queue in sequence, acquiring a current message traversed currently, and determining, on the basis of a preset feature recognition algorithm, a target thread corresponding to the current message; and transmitting the current message to the target thread for consumption until the messages in the new message queue are all traversed. Further disclosed are a message consumption apparatus and device, and a computer storage medium.

Description

消息消费方法、装置、设备及计算机存储介质Message consumption method, device, equipment and computer storage medium
本申请要求于2019年5月31日提交中国专利局、申请号为201910479100.X、发明名称为“消息消费方法、装置、设备及计算机存储介质”的中国专利申请的优先权,其全部内容通过引用结合在申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office, the application number is 201910479100.X, and the invention title is "message consumption methods, devices, equipment, and computer storage media" on May 31, 2019. The reference is incorporated in the application.
技术领域Technical field
本申请涉及金融科技(Fintech)的大数据技术领域,尤其涉及消息消费方法、装置、设备及计算机存储介质。This application relates to the field of big data technology of financial technology (Fintech), in particular to message consumption methods, devices, equipment and computer storage media.
背景技术Background technique
随着计算机技术的发展,越来越多的技术(大数据、分布式、区块链Blockchain、人工智能等)应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变,但由于金融行业的安全性、实时性要求,也对技术提出了更高的要求。而目前在大数据统计过程中,针对大数据量的数据进行消息的产生、消息的消费,其中,消息的产生是由消息生产者将消息传输给消息服务器的,消息的消费是由消费者线程对消息服务器的消息进行的消费操作。With the development of computer technology, more and more technologies (big data, distributed, blockchain, artificial intelligence, etc.) are applied in the financial field. The traditional financial industry is gradually transforming to Fintech. However, due to financial The industry's security and real-time requirements also place higher requirements on technology. At present, in the big data statistics process, messages are generated and consumed for large amounts of data. Among them, the generation of messages is transmitted by the message producer to the message server, and the consumption of messages is by the consumer thread The consumption operation of the message of the message server.
在消息的消费过程中,现有技术一般存在单线程消费和多线程消费,单线程消费是采用单一线程监听消息队列,消费线程一旦获取到一个新的消息,需要完成将这个消息投递到所有本地其它服务的过程后,才能进行下一个消息的消费,但是这个方式在性能方面存在严重的缺陷。多线程消费是采用多线程同时监听同一个消息队列,只要队列中出现新的消息,就会有随机的线程去获取,进而独立完成向本地其它服务的投递过程,但是这个方式无法保障消息被消费的有序性,且在对消息状态迁移的有序性有需求的场景下无法适用,对消息消费的可用范围造成很大的影响,使得可用范围变小。因此,如何实现高并发高可用的消息有序消费成为了目前亟待解决的技术问题。In the message consumption process, the prior art generally has single-threaded consumption and multi-threaded consumption. Single-threaded consumption uses a single thread to monitor the message queue. Once the consumer thread obtains a new message, it needs to complete the delivery of the message to all locals. The next message can be consumed only after the process of other services, but this method has serious defects in performance. Multi-threaded consumption uses multiple threads to monitor the same message queue at the same time. As long as a new message appears in the queue, there will be a random thread to obtain it, and then independently complete the delivery process to other local services, but this method cannot guarantee that the message is consumed It is not applicable in scenarios where the order of message state migration is required, which has a great impact on the available range of message consumption and makes the available range smaller. Therefore, how to achieve orderly consumption of messages with high concurrency and high availability has become a technical problem to be solved urgently.
发明概述Summary of the invention
技术问题technical problem
问题的解决方案The solution to the problem
技术解决方案Technical solutions
本申请的主要目的在于提出一种消息消费方法、装置、设备及计算机存储介质,旨在解决如何实现高并发高可用的消息有序消费的技术问题。The main purpose of this application is to propose a message consumption method, device, equipment, and computer storage medium, aiming to solve the technical problem of how to achieve orderly consumption of messages with high concurrency and availability.
为实现上述目的,本申请提供一种消息消费方法,所述消息消费方法包括如下步骤:In order to achieve the above objective, this application provides a message consumption method, which includes the following steps:
获取分布式协调服务zookeeper的服务注册目录中的目标节点,并基于所述目标节点监听预设数量的消息队列,确定各所述消息队列中是否存在首次监听的新消息队列;Obtain the target node in the service registration directory of the distributed coordination service zookeeper, and based on the target node monitor a preset number of message queues, determine whether there is a new message queue monitored for the first time in each of the message queues;
若存在首次监听的新消息队列,则依次遍历所述新消息队列中的消息,获取当前遍历的当前消息,并基于预设特征识别算法确定所述当前消息对应的目标线程;If there is a new message queue monitored for the first time, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm;
将所述当前消息传递至所述目标线程进行消费,直至所述新消息队列中的消息遍历完成。The current message is delivered to the target thread for consumption until the traversal of messages in the new message queue is completed.
此外,为实现上述目的,本申请还提供一种消息消费装置,所述消息消费装置包括:In addition, in order to achieve the above objective, the present application also provides a message consumption device, the message consumption device including:
获取模块,用于获取zookeeper服务注册目录中的目标节点,并基于所述目标节点监听预设数量的消息队列,确定各所述消息队列中是否存在首次监听的新消息队列;The obtaining module is used to obtain the target node in the zookeeper service registration directory, and determine whether there is a new message queue monitored for the first time in each of the message queues based on the target node monitoring a preset number of message queues;
确定模块,用于若存在首次监听的新消息队列,则依次遍历所述新消息队列中的消息,获取当前遍历的当前消息,并基于预设特征识别算法确定所述当前消息对应的目标线程;The determining module is configured to, if there is a new message queue monitored for the first time, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm;
传递模块,用于将所述当前消息传递至所述目标线程进行消费,直至所述新消息队列中的消息遍历完成。The delivery module is used to deliver the current message to the target thread for consumption until the message traversal in the new message queue is completed.
此外,为实现上述目的,本申请还提供一种消息消费设备,所述消息消费设备包括:存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机可读指令,所述计算机可读指令被所述处理器执行时实现如上所述的消息消费方法的步骤。In addition, in order to achieve the above objective, the present application also provides a message consumption device, the message consumption device comprising: a memory, a processor, and computer-readable instructions stored on the memory and running on the processor, When the computer-readable instructions are executed by the processor, the steps of the message consumption method described above are implemented.
此外,为实现上述目的,本申请还提供一种计算机存储介质,所述计算机存储 介质上存储有计算机可读指令,所述计算机可读指令被处理器执行时实现如上所述的消息消费方法的步骤。In addition, in order to achieve the above objective, the present application also provides a computer storage medium having computer readable instructions stored thereon, and when the computer readable instructions are executed by a processor, the above message consumption method is implemented. step.
本申请通过获取zookeeper的服务注册目录中的目标节点,并基于所述目标节点监听预设数量的消息队列,确定各所述消息队列中是否存在首次监听的新消息队列;若存在首次监听的新消息队列,则依次遍历所述新消息队列中的消息,获取当前遍历的当前消息,并基于预设特征识别算法确定所述当前消息对应的目标线程;将所述当前消息传递至所述目标线程进行消费,直至所述新消息队列中的消息遍历完成。通过根据zookeeper中的目标节点来监听预设数量的消息队列,并在发现存在首次监听的新消息队列时,会依次对新消息队列中的消息进行遍历消费,从而保障了消息被有序的消费,让消息被消费的顺序与其在队列中的顺序一致,并且由于是先根据消息来确定目标线程,然后将消息传递到目标线程进行消费的,从而也实现了高并发高可用的消息有序消费的效果。This application obtains the target node in the zookeeper's service registration directory and monitors a preset number of message queues based on the target node to determine whether there is a new message queue monitored for the first time in each of the message queues; if there is a new message queue monitored for the first time Message queue, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm; deliver the current message to the target thread Consumption is performed until the traversal of the messages in the new message queue is completed. By monitoring a preset number of message queues according to the target node in zookeeper, and when it finds that there is a new message queue that is monitored for the first time, the messages in the new message queue will be traversed and consumed sequentially, thereby ensuring the orderly consumption of messages , The order in which the messages are consumed is consistent with the order in the queue, and since the target thread is determined according to the message, and then the message is passed to the target thread for consumption, it also achieves orderly consumption of messages with high concurrency and high availability Effect.
发明的有益效果The beneficial effects of the invention
对附图的简要说明Brief description of the drawings
附图说明Description of the drawings
图1是本申请实施例方案涉及的硬件运行环境的设备结构示意图;FIG. 1 is a schematic diagram of a device structure of a hardware operating environment involved in a solution of an embodiment of the present application;
图2为本申请消息消费方法第一实施例的流程示意图;2 is a schematic flowchart of the first embodiment of the message consumption method of this application;
图3为本申请消息消费装置的装置模块示意图;FIG. 3 is a schematic diagram of device modules of the message consumption device of this application;
图4为本申请消息消费方法中zookeeper的节点结构示意图;Figure 4 is a schematic diagram of the node structure of zookeeper in the message consumption method of this application;
图5为本申请消息消费方法中消息流转流程图。Figure 5 is a flow chart of message flow in the message consumption method of this application.
本申请目的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The realization of the purpose, functional characteristics and advantages of the application will be further described in conjunction with the embodiments and with reference to the accompanying drawings.
发明实施例Invention embodiment
本发明的实施方式Embodiments of the invention
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。It should be understood that the specific embodiments described here are only used to explain the application, and are not used to limit the application.
如图1所示,图1是本申请实施例方案涉及的硬件运行环境的设备结构示意图。As shown in FIG. 1, FIG. 1 is a schematic diagram of the device structure of the hardware operating environment involved in the solution of the embodiment of the present application.
本申请实施例消息消费设备可以是PC机或服务器设备,其上运行有Java虚拟机 。The message consumption device in the embodiment of the present application may be a PC or a server device, on which a Java virtual machine runs.
如图1所示,该消息消费设备可以包括:处理器1001,例如CPU,网络接口1004,用户接口1003,存储器1005,通信总线1002。其中,通信总线1002用于实现这些组件之间的连接通信。用户接口1003可以包括显示屏(Display)、输入单元比如键盘(Keyboard),可选用户接口1003还可以包括标准的有线接口、无线接口。网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI接口)。存储器1005可以是高速RAM存储器,也可以是稳定的存储器(non-volatilememory),例如磁盘存储器。存储器1005可选的还可以是独立于前述处理器1001的存储装置。As shown in FIG. 1, the message consumption device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to implement connection and communication between these components. The user interface 1003 may include a display screen (Display) and an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a magnetic disk memory. Optionally, the memory 1005 may also be a storage device independent of the foregoing processor 1001.
本领域技术人员可以理解,图1中示出的设备结构并不构成对设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。Those skilled in the art can understand that the structure of the device shown in FIG. 1 does not constitute a limitation on the device, and may include more or fewer components than those shown in the figure, or a combination of certain components, or different component arrangements.
如图1所示,作为一种计算机存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及计算机可读指令。As shown in FIG. 1, a memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and computer readable instructions.
在图1所示的设备中,网络接口1004主要用于连接后台服务器,与后台服务器进行数据通信;用户接口1003主要用于连接客户端(用户端),与客户端进行数据通信;而处理器1001可以用于调用存储器1005中存储的计算机可读指令,并执行下述消息消费方法中的操作。In the device shown in FIG. 1, the network interface 1004 is mainly used to connect to a back-end server and communicate with the back-end server; the user interface 1003 is mainly used to connect to a client (user side) and communicate with the client; and the processor 1001 can be used to call computer-readable instructions stored in the memory 1005 and perform operations in the following message consumption method.
基于上述硬件结构,提出本申请消息消费方法实施例。Based on the above hardware structure, an embodiment of the message consumption method of this application is proposed.
参照图2,图2为本申请消息消费方法第一实施例的流程示意图,所述方法包括:Referring to FIG. 2, FIG. 2 is a schematic flowchart of a first embodiment of a message consumption method according to this application. The method includes:
步骤S10,获取分布式协调服务zookeeper的服务注册目录中的目标节点,并基于所述目标节点监听预设数量的消息队列,确定各所述消息队列中是否存在首次监听的新消息队列;Step S10: Obtain a target node in the service registration directory of the distributed coordination service zookeeper, and determine whether there is a new message queue monitored for the first time in each of the message queues based on the target node monitoring a preset number of message queues;
Zookeeper(分布式协调服务),即一个开源的分布式协调服务。分布式应用程序可以基于Zookeeper实现诸如数据发布/订阅、负载均衡、命名服务、分布式协调/通知、集群管理、Master选举、分布式锁和分布式队列等功能。消息队列可以为存储机制负责消息的有序存放。新消息队列可以是在当前时刻之前没有被临时节点对应的消息消费者所监听的消息队列,而消息消费者则可以作为客 户端负责从消息服务器获取消息,消息服务器是作为服务端提供消息核心服务。目标节点可以是消息消费者在zookeeper的服务注册目录下创建的代表自身的节点,并且目标节点的类型可以有多种,在本实施例中仅以目标节点为临时节点为例进行说明,但不代表目标节点只局限于临时节点这一种类型的节点。Zookeeper (distributed coordination service), which is an open source distributed coordination service. Distributed applications can implement functions such as data publishing/subscription, load balancing, naming services, distributed coordination/notification, cluster management, Master election, distributed locks, and distributed queues based on Zookeeper. The message queue can be responsible for the orderly storage of messages for the storage mechanism. The new message queue can be a message queue that has not been monitored by the message consumer corresponding to the temporary node before the current moment, and the message consumer can be used as a client to obtain messages from the message server, and the message server is used as a server to provide core message services . The target node can be a node representing itself created by the message consumer under the zookeeper's service registration directory, and there can be many types of target nodes. In this embodiment, only the target node is a temporary node for illustration, but not The representative target node is limited to one type of temporary node.
本实施例通过在zookeeper下建立目录来作为消息队列,并利用zookeeper提供的监听机制来实现消息的广播机制。并且每个消息消费者在初始化阶段,均会在zookeeper的服务注册目录下建立一个代表自身的临时节点(即目标节点),因此需要先获取zookeeper的服务注册目录中的临时节点(临时节点在消息消费者与zookeeper失去联接后会自动删除),并根据该临时节点来监听预设数量(用户提前设置的任意数量,可以是一个,也可以是多个)的消息队列,以确定在监听的各个消息队列中是否存在首次监听的新消息队列,若存在首次监听的新消息队列时,则消息消费者会获取该队列中现存的所有消息并按顺序进行消费。若不存在首次监听的新消息队列,则会继续检测在被监听的消息队列中是否存在新的消息节点生成,并根据检测结果执行不同的操作。In this embodiment, a directory is established under zookeeper as a message queue, and a monitoring mechanism provided by zookeeper is used to implement a message broadcasting mechanism. And each message consumer will establish a temporary node (that is, the target node) on behalf of itself in the zookeeper's service registration directory during the initialization phase, so you need to first obtain the temporary node in the zookeeper's service registration directory (the temporary node is in the message Consumers will be automatically deleted after losing connection with zookeeper), and according to the temporary node, they will monitor a preset number of message queues (any number set by the user in advance, which can be one or multiple) to determine which ones are being monitored. Whether there is a new message queue that is monitored for the first time in the message queue, if there is a new message queue that is monitored for the first time, the message consumer will obtain all the existing messages in the queue and consume them in order. If there is no new message queue monitored for the first time, it will continue to detect whether there are new message node generations in the monitored message queue, and perform different operations according to the detection results.
其中,当获取到的临时节点存在多个时,则可以分别根据各个临时节点来监听不同的消息队列,也就是可以同时让各个临时节点监听各自对应的消息队列。例如,如图4所示,当在zookeeper的服务注册目录中的临时节点存在3个时,即服务1、服务2、服务3,并且消息队列存在两个时,即队列1和队列2,在队列1中包括消息1、消息2、消息3和消息4,在队列2中同样也包括有消息1、消息2、消息3和消息4。假设服务1和服务2均需要监听队列1中的消息1时,可以让服务1和服务2同时获取队列1中的消息1进行消费,并在消费完成后,会在消息1下面的子节点生成临时子节点服务1和服务2,假设服务2除了在队列1中的消息1进行监听外,还对队列1中的消息2和队列2中的消息1进行监听时,同样的,在消息消费完成后,分别在队列1中的消息2和队列2的消息1的子节点生成临时子节点服务1。Among them, when there are multiple temporary nodes obtained, different message queues can be monitored respectively according to each temporary node, that is, each temporary node can simultaneously monitor their corresponding message queues. For example, as shown in Figure 4, when there are three temporary nodes in the zookeeper's service registration directory, namely service 1, service 2, and service 3, and there are two message queues, namely queue 1 and queue 2, in Queue 1 includes message 1, message 2, message 3, and message 4, and queue 2 also includes message 1, message 2, message 3, and message 4. Assuming that both service 1 and service 2 need to listen to message 1 in queue 1, service 1 and service 2 can simultaneously obtain message 1 in queue 1 for consumption, and after consumption is completed, it will be generated in the child node under message 1 Temporary child node service 1 and service 2. Assume that service 2 not only monitors message 1 in queue 1, but also monitors message 2 in queue 1 and message 1 in queue 2. Similarly, when message consumption is completed After that, temporary child node service 1 is generated in the child nodes of message 2 in queue 1 and message 1 in queue 2 respectively.
需要说明的是,在zookeeper中的节点可以划分为四种节点类型,分别是持久节点、持久顺序节点、临时节点和临时顺序节点。其中,持久节点在创建后,会一直存在,直到有删除操作来主动清除这个节点,而在本实施例中,消息队列 所在的目录就可以采用此节点。持久顺序节点的基本特性和持久节点是一致的,相对于持久节点,持久顺序节点额外的特性是每个父节点会为他的第一级子节点维护一份时序,会记录每个子节点创建的先后顺序,而在本实施例中可以利用此节点,实现消息体的承载,并利用其天然的有序性来实现消息在队列中的有序存放,其中,消息体可以是作为载体承载消息的内容,一般为根据协议进行编码的数据包。临时节点在客户端和zookeeper失去连接后会自动删除,在本实施例中可以利用此节点的自动清除功能,来保证发生异常的消费者不会影响消息的清理,减少消息的堆积。临时顺序节点的基本特性和临时节点是一致的,相对于临时节点,临时顺序节点额外的特性是每个父节会为他的第一级子节点维护一份时序,会记录每个子节点创建的先后顺序,在本实施例中可以利用该节点来实现分布式的锁,消息生产者(即为客户端负责将消息传输给消息服务器)能够通过创建这种节点来实现对同一个锁的排队机制,并在锁获得释放的时候被实时通知。It should be noted that the nodes in zookeeper can be divided into four types of nodes, namely persistent nodes, persistent sequential nodes, temporary nodes, and temporary sequential nodes. Among them, after the persistent node is created, it will always exist until there is a delete operation to actively clear the node. In this embodiment, the directory where the message queue is located can use this node. The basic characteristics of persistent sequential nodes are the same as those of persistent nodes. Compared with persistent nodes, the additional characteristic of persistent sequential nodes is that each parent node maintains a sequence for its first-level child nodes, and records the creation of each child node In this embodiment, this node can be used to carry the message body, and use its natural order to realize the orderly storage of messages in the queue. The message body can be used as a carrier to carry the message. The content is generally a data packet encoded according to the protocol. The temporary node is automatically deleted after the client loses the connection with the zookeeper. In this embodiment, the automatic removal function of this node can be used to ensure that abnormal consumers will not affect the cleaning of messages and reduce the accumulation of messages. The basic characteristics of the temporary sequence node are the same as the temporary node. Compared with the temporary node, the additional feature of the temporary sequence node is that each parent node maintains a sequence for its first-level child nodes, and records the creation of each child node In order, in this embodiment, this node can be used to implement distributed locks. The message producer (that is, the client is responsible for transmitting messages to the message server) can create this kind of node to realize the queuing mechanism for the same lock , And be notified in real time when the lock is released.
步骤S20,若存在首次监听的新消息队列,则依次遍历所述新消息队列中的消息,获取当前遍历的当前消息,并基于预设特征识别算法确定所述当前消息对应的目标线程;Step S20: If there is a new message queue monitored for the first time, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm;
当前消息可以是新消息队列中正在遍历的消息。线程可以是操作系统能够进行运算调度的最小单位。当经过判断发现存在首次监听的消息队列时,则可以依次遍历新消息队列中的各个消息,并在各个消息中获取当前遍历的当前消息,然后在根据预设的特征识别算法来确定当前消息对应的目标线程。需要说明的是,若存在首次监听的新消息队列存在两个及两个以上时,则可以同时对各个新消息队列分别进行遍历,以进行消息的消费。The current message can be a message being traversed in the new message queue. A thread can be the smallest unit that the operating system can perform operation scheduling. When it is judged that there is a message queue that is monitored for the first time, you can traverse each message in the new message queue in turn, and obtain the current message currently traversed in each message, and then determine the current message corresponding to the preset feature recognition algorithm The target thread. It should be noted that if there are two or more new message queues that are monitored for the first time, each new message queue can be traversed separately at the same time to consume messages.
其中,特征识别算法是为了确保同一类别的消息能够在本地被分发到同一线程进行有序消费。用户在定义消息时,可以选择消息中的部分字段作为特征识别的基础,若这些字段的值是一致的,则可以认为是同一类型的消息,也就是需要对每一种类型的消息赋予一个确保不会重复的数字来作为特征信息。当消息消费者在接收到消息时,将会读取该特征信息,并根据本地消费线程池的容量来做取余操作,将消息置入取余结果标记的线程中。其中,特征识别算法将结 合线程池当前的异常监测结果,在线程处理顺序得懂啊同步的前提下,调整线程的标记,以防止某个种类消息数量达到峰值是消费延时过大。Among them, the feature recognition algorithm is to ensure that messages of the same category can be distributed locally to the same thread for orderly consumption. When users define a message, they can select some fields in the message as the basis for feature recognition. If the values of these fields are consistent, they can be considered as the same type of message, which means that each type of message needs to be given a guarantee Numbers that will not be repeated are used as characteristic information. When the message consumer receives the message, it will read the characteristic information, and perform the residual operation according to the capacity of the local consumption thread pool, and put the message into the thread marked with the residual result. Among them, the feature recognition algorithm will be combined with the current abnormal monitoring results of the thread pool. Under the premise that the thread processing sequence is understood and synchronized, the thread mark is adjusted to prevent the peak consumption of a certain type of message from being too long.
步骤S30,将所述当前消息传递至所述目标线程进行消费,直至所述新消息队列中的消息遍历完成。In step S30, the current message is delivered to the target thread for consumption until the traversal of messages in the new message queue is completed.
当获取到目标线程后,则可以直接将当前消息传递到目标线程以进行消费,并且在当前消息通过目标线程进行消费时,消息消费者会有单独的监控线程,去轮询每个分发线程的健壮性,如果发现某个线程处于异常状态,会立即启用备用线程,从而保证消费的稳定性。并在当前消息在目标线程中消费完成后,会继续对新消息队列中的各个消息进行遍历,直到各个消息遍历完成。When the target thread is obtained, the current message can be directly passed to the target thread for consumption, and when the current message is consumed through the target thread, the message consumer will have a separate monitoring thread to poll the distribution thread Robustness. If a thread is found to be in an abnormal state, the standby thread will be activated immediately to ensure the stability of consumption. And after the current message is consumed in the target thread, it will continue to traverse each message in the new message queue until the traversal of each message is completed.
为了辅助理解对消息的消费,下面进行举例说明。In order to help understand the consumption of messages, an example is given below.
例如,如图5所示,当消息生产者(例如与银行等金融机构有业务交互的业务方,其中,业务包括但不限于贷款业务、存款业务等)在zookeeper的目录下建立消息节点来往对应的消息队列发送消息时,会触发zookeeper的监听机制,zookeeper会向监听该目录的所有消息消费者发送通知,消息消费者(如银行等金融机构)在接收到通知后,会根据通知的内容来获取消息节点中的消息。其中,由于消息消费者是通过一个有序的线程池管理所有负责本地分发消息的线程,因此,在收到消息时,会根据特征识别算法来解析该消息的特征,并结合线程池的大小,判定该消息应当进入哪个分发线程,以保证特征相同的消息总能被有序的消费。并且消息消费者会有单独的监控线路来检测每个分发线程,假设线程池中存在消费线程1、消费线程2、消费线程3和消费线程4,并且此时消息消费者通过监控器监测线程池中各个消费线程,以后获取监测信息,并根据监测信息发现消费线程4处于异常状态时,会立即启用备用线程,也就是在备用线程1和备用线程2中选择备用线程1和消费线程4进行异常切换。其中,在zookeeper中会定时对各个消息节点进行检测,并在确定有消息节点已被所有消息消费者消费后,则可以对该消息节点中的消息进行消息清理。For example, as shown in Figure 5, when a message producer (for example, a business party that has business interactions with financial institutions such as banks, where the business includes but is not limited to loan business, deposit business, etc.) establishes the correspondence between message nodes under the zookeeper directory When the message queue sends a message, it will trigger the zookeeper's monitoring mechanism. Zookeeper will send a notification to all message consumers listening to the directory. After receiving the notification, the message consumer (such as a bank and other financial institutions) will respond according to the content of the notification. Get the message in the message node. Among them, because the message consumer manages all the threads responsible for local distribution of messages through an ordered thread pool, when receiving a message, it will analyze the characteristics of the message according to the feature recognition algorithm, and combine the size of the thread pool. Determine which distribution thread the message should enter to ensure that messages with the same characteristics can always be consumed in an orderly manner. And the message consumer will have a separate monitoring line to detect each distribution thread, assuming that there are consumer thread 1, consumer thread 2, consumer thread 3 and consumer thread 4 in the thread pool, and the message consumer monitors the thread pool through the monitor at this time Each consumer thread in the consuming thread will obtain monitoring information in the future, and when the consuming thread 4 is found to be in an abnormal state based on the monitoring information, the backup thread will be activated immediately, that is, the backup thread 1 and the consuming thread 4 are selected for exceptions in the backup thread 1 and the backup thread 2. Switch. Among them, each message node is periodically detected in zookeeper, and after it is determined that a message node has been consumed by all message consumers, the message in the message node can be cleaned up.
本实施例通过获取zookeeper的服务注册目录中的目标节点,并基于所述目标节点监听预设数量的消息队列,确定各所述消息队列中是否存在首次监听的新消息队列;若存在首次监听的新消息队列,则依次遍历所述新消息队列中的消息 ,获取当前遍历的当前消息,并基于预设特征识别算法确定所述当前消息对应的目标线程;将所述当前消息传递至所述目标线程进行消费,直至所述新消息队列中的消息遍历完成。通过根据zookeeper中的目标节点来监听预设数量的消息队列,并在发现存在首次监听的新消息队列时,会依次对新消息队列中的消息进行遍历消费,从而保障了消息被有序的消费,让消息被消费的顺序与其在队列中的顺序一致,并且由于是先根据消息来确定目标线程,然后将消息传递到目标线程进行消费的,从而也实现了高并发高可用的消息有序消费的效果。In this embodiment, by acquiring the target node in the zookeeper's service registration directory, and monitoring a preset number of message queues based on the target node, it is determined whether there is a new message queue monitored for the first time in each of the message queues; For the new message queue, the messages in the new message queue are sequentially traversed, the current message currently traversed is obtained, and the target thread corresponding to the current message is determined based on the preset feature recognition algorithm; the current message is delivered to the target The thread consumes until the traversal of the messages in the new message queue is completed. By monitoring a preset number of message queues according to the target node in zookeeper, and when it finds that there is a new message queue that is monitored for the first time, the messages in the new message queue will be traversed and consumed sequentially, thereby ensuring the orderly consumption of messages , The order in which the messages are consumed is consistent with the order in the queue, and since the target thread is determined according to the message, and then the message is passed to the target thread for consumption, it also achieves orderly consumption of messages with high concurrency and high availability Effect.
进一步地,基于本申请消息消费方法第一实施例,提出本申请消息消费方法第二实施例。本实施例是本申请第一实施例的步骤S20,基于预设特征识别算法确定所述当前消息对应的目标线程的步骤的细化,包括:Further, based on the first embodiment of the message consumption method of this application, a second embodiment of the message consumption method of this application is proposed. This embodiment is a refinement of the step S20 of the first embodiment of the present application. The step of determining the target thread corresponding to the current message based on a preset feature recognition algorithm includes:
步骤S21,在所述当前消息对应的顶层接口接收所述当前消息对应的特征信息,并基于预设特征识别算法识别所述特征信息;Step S21, receiving feature information corresponding to the current message at the top-level interface corresponding to the current message, and identifying the feature information based on a preset feature recognition algorithm;
在当前消息对应的顶层接口中可以接收用户定义的当前消息对应的特征信息,并在用户定义消息时,可以选择消息中的部分字段作为特征识别的基础,这些字段的值可以作为特征信息。在消息消费者接收到当前消息时,可以通过预设特征识别算法来识别还原当前消息中的特征信息,以便根据该特征信息来确定该消息应该被哪个线程消费,保证具有相同特征的消息必定有序的被消费。The user-defined feature information corresponding to the current message can be received in the top-level interface corresponding to the current message, and when the user defines the message, some fields in the message can be selected as the basis for feature identification, and the values of these fields can be used as feature information. When the message consumer receives the current message, the feature information in the current message can be identified and restored through the preset feature recognition algorithm, so as to determine which thread the message should be consumed by the feature information, and to ensure that messages with the same feature must have Ordered to be consumed.
步骤S22,根据所述特征信息确定所述当前消息对应的目标线程。Step S22: Determine the target thread corresponding to the current message according to the characteristic information.
由于同一类型的消息的特征信息是相同的,不同类型的消息的特征信息是不同的,因此可以在获取到当前信息对应的特征信息后,可以在线程池中确定哪个线程消耗的消息的特征信息和当前消息的特征信息相同,即确定目标线程。Since the characteristic information of the same type of messages is the same, and the characteristic information of different types of messages are different, after obtaining the characteristic information corresponding to the current information, you can determine which thread is consuming the characteristic information of the message in the thread pool The characteristic information of the current message is the same, that is, the target thread is determined.
在本实施例中,通过根据预设特征识别算法获取当前消息的特征信息,并根据特征信息确定目标线程,从而保障了当前消息获取到合适的线程进行消费,保障了消息消费的效率。In this embodiment, the characteristic information of the current message is acquired according to the preset characteristic recognition algorithm, and the target thread is determined according to the characteristic information, thereby ensuring that the current message acquires a suitable thread for consumption and guarantees the efficiency of message consumption.
具体地,根据所述特征信息确定所述当前消息对应的目标线程的步骤,包括:Specifically, the step of determining the target thread corresponding to the current message according to the characteristic information includes:
步骤S221,获取所述目标节点对应的线程池,根据所述线程池的容量和所述特征信息做取余操作,在所述线程池中获取具有取余结果标记的第一线程,并检测所述第一线程是否处于异常状态;Step S221: Obtain a thread pool corresponding to the target node, perform a remainder operation according to the capacity of the thread pool and the characteristic information, acquire a first thread with a remainder result mark in the thread pool, and detect all State whether the first thread is in an abnormal state;
线程池可以是具有所有线程的集合。在获取到当前消息对应的特征信息后,还需要获取目标节点对应的线程池,并确定线程池的容量,再根据线程池的容量和特征信息做取余操作,以确定线程池中哪条线程消耗的消息的特征信息和当前消息的特征信息相同,且容量最大,则可以将其作为具有取余结果标记的第一线程。并在获取到第一线程后,还需要检查确定第一线程是否处于异常状态(也就是检查第一线程能不能正常地进行消耗消息的操作),并根据检查结果执行不同的操作。The thread pool can be a collection of all threads. After obtaining the characteristic information corresponding to the current message, it is also necessary to obtain the thread pool corresponding to the target node, and determine the capacity of the thread pool, and then perform the remainder operation according to the capacity and characteristic information of the thread pool to determine which thread in the thread pool The characteristic information of the consumed message is the same as the characteristic information of the current message, and the capacity is the largest, so it can be used as the first thread with the remainder result mark. And after acquiring the first thread, it is also necessary to check whether the first thread is in an abnormal state (that is, to check whether the first thread can normally perform the operation of consuming messages), and perform different operations according to the check result.
步骤S222,若所述第一线程处于异常状态,则启用所述线程池中的备用线程,并将所述备用线程作为所述当前消息对应的目标线程;Step S222, if the first thread is in an abnormal state, enable the standby thread in the thread pool, and use the standby thread as the target thread corresponding to the current message;
当经过判断发现第一线程处于异常状态时,则会触发应急机制,该机制回使用提前初始化的备用线程替换异常线程,并根据异常范围回滚本地状态,再继续进行消费,此时替换的备用线程就是当前消息对应的目标线程。需要说明的是,在本实施例中,消息消费的每个步骤均回受到监控,一旦有某个环节失败、超时或吞吐量低于阈值,均会触发应急机制,不局限于在检测到第一线程处于异常状态时才触发。When the first thread is found to be in an abnormal state after judgment, the emergency mechanism will be triggered. The mechanism will use the pre-initialized backup thread to replace the abnormal thread, and roll back the local state according to the abnormal scope, and then continue to consume. The thread is the target thread corresponding to the current message. It should be noted that in this embodiment, each step of message consumption is monitored. Once a link fails, times out, or the throughput is lower than the threshold, the emergency mechanism will be triggered. It is not limited to the detection of the first step. Triggered when a thread is in an abnormal state.
步骤S223,若所述第一线程处于正常状态,则将所述第一线程作为所述当前消息对应的目标线程。Step S223: If the first thread is in a normal state, use the first thread as the target thread corresponding to the current message.
当经过判断发现第一线程处于正常状态时,则可以直接将第一线程作为当前消息对应的目标线程,将当前消息传递到目标线程进行消费。When the first thread is found to be in a normal state after judgment, the first thread can be directly used as the target thread corresponding to the current message, and the current message is delivered to the target thread for consumption.
在本实施例中,通过在确定第一线程后,检测第一线程是否处于异常状态,并根据不同的检测结果执行不同的操作,从而保障了消息消费的稳定性。In this embodiment, after the first thread is determined, whether the first thread is in an abnormal state is detected, and different operations are performed according to different detection results, thereby ensuring the stability of message consumption.
进一步地,在本申请第一至第二实施例任意一个的基础上,提出了本申请消息消费方法的第三实施例,本实施例是在本申请第一实施例的步骤S10,确定各所述消息队列中是否存在首次监听的新消息队列的步骤之后,包括:Further, on the basis of any one of the first to second embodiments of the present application, a third embodiment of the message consumption method of the present application is proposed. In this embodiment, in step S10 of the first embodiment of the present application, each location is determined After the steps of whether there is a new message queue monitored for the first time in the message queue, include:
步骤S50,若不存在首次监听的新消息队列,则检测各所述消息队列中是否存在新消息节点;Step S50, if there is no new message queue monitored for the first time, detect whether there is a new message node in each of the message queues;
当经过判断发现不存在首次监听的新消息队列时,则需要再次检测各个消息队列中是否存在新消息节点生成,也就是确定是否有消息的生产者在消息队列中 创建新的消息节点,并基于不同的检测结果执行不同的操作。When it is judged that there is no new message queue monitored for the first time, it is necessary to check again whether there is a new message node generation in each message queue, that is, to determine whether there is a message producer to create a new message node in the message queue, and based on Different test results perform different operations.
步骤S60,若存在新消息节点,则获取所述新消息节点中的新消息,并将所述新消息传递至所述新消息节点对应的第二线程进行消费。Step S60: If there is a new message node, obtain the new message in the new message node, and deliver the new message to the second thread corresponding to the new message node for consumption.
当经过判断发现存在新消息节点生成时,则会触发zookeeper的监听机制,zookeeper会向监听该新消息节点所在的消息队列的所有消费者发送通知,消息消费者在收到通知后,将会根据通知的内容从zookeeper拉取新消息节点中的新消息,并通过预设特征识别算法来计算确定新消息节点对应的第二线程,并将新消息传递到第二线程进行消费。其中,新消息可以是新消息节点所携带的消息。第二线程可以是新消息将要进行消费所采用的线程。When it is judged that a new message node is generated, the monitoring mechanism of zookeeper will be triggered. Zookeeper will send a notification to all consumers who monitor the message queue where the new message node is located. After the message consumer receives the notification, it will follow The content of the notification pulls the new message in the new message node from zookeeper, calculates and determines the second thread corresponding to the new message node through a preset feature recognition algorithm, and delivers the new message to the second thread for consumption. Among them, the new message may be a message carried by the new message node. The second thread may be the thread used by the new message to be consumed.
在本实施例中,通过检测是否存在新消息节点生成,并在确定新消息节点生成时,则会直接获取新消息,并通过第二线程进行消费,从而保障了消息消费的效率。In this embodiment, by detecting whether a new message node is generated, and when it is determined that a new message node is generated, the new message is directly obtained and consumed through the second thread, thereby ensuring the efficiency of message consumption.
具体地,将所述新消息传递至所述新消息对应的第二线程进行消费的步骤之后,包括:Specifically, after the step of delivering the new message to the second thread corresponding to the new message for consumption, it includes:
步骤S70,获取zookeeper中的总消息队列,并定时确定所述总消息队列中的各消息节点中,是否存在消费完成的已消费消息节点,其中,所述总消息队列包括消息队列;Step S70: Obtain the total message queue in zookeeper, and periodically determine whether there is a consumed message node whose consumption is completed in each message node in the total message queue, wherein the total message queue includes a message queue;
总消息队列可以是zookeeper中的所有消息队列。预设时间段可以是用户设置的任意时间段。已消费消息节点可以是消息已被各个消息消费者消费完成的消息节点。The total message queue can be all message queues in zookeeper. The preset time period can be any time period set by the user. The consumed message node may be a message node where the message has been consumed by each message consumer.
由于消息的消费不具有强事务性。现有的技术均无法保证消息能够百分百被消费,且消费后失败后无保护措施,这就使得现有技术无法应对对状态同步准确性要求高的场景,而由于消息体本身会提供判断过期与否的状态信息,因此可以将处于过渡状态的消息进行及时清理,并提供消息合并机制,经过期消息中部分重要信息能够被单独抽取并放入持久状态的消息中。Because the consumption of messages is not highly transactional. Existing technologies cannot guarantee that messages can be consumed 100%, and there are no protective measures after consumption failure, which makes the existing technologies unable to cope with scenarios that require high state synchronization accuracy, and the message body itself provides judgments The status information of expired or not, so the messages in the transitional state can be cleaned up in time, and a message merging mechanism is provided. Part of the important information in the elapsed message can be separately extracted and put into the message of the persistent state.
获取zookeeper中的所有消息队列,并在每间隔预设时间段会有定时任务对各个消息队列中的所有消息节点中的消息进行检查,即检查消息的状态性质,在本实施例中通过将消息定义为“起始”、“过渡”和“终止”等状态,以实现对不同性质 的消息的区别对待,而消息状态的识别方式可以通过用户自主定义或者中间件自动识别的方式进行识别。用户自主定义是中间件的用户在定义消息时,可以通过继承接口字段的方式来为消息赋予状态。而中间件自动识别是在消息清理的过程中,主动分析同一类消息的字段值,判断该消息是否已经被其它消息合并,若合并了其它消息携带的信息时,智能判断该消息的状态信息,以确保即使用户定义的状态信息有误差的情况下,仍然能得到修正,保持消息清理的有效性。其中,过渡状态的消息,将会在确认被完全消费后及时清理,因此需要确定各个消息节点是否为无需持久化保存的过渡消息,若经过判断发现存在消息节点为过渡消息,则会比对该消息节点下的临时子节点与服务注册目录下的临时节点,若两者一致,则证明该消息节点中的消息已被所有消息消费者消费,也就可以认为总消息队列的各个消息节点中,存在消费完成的已消费消息节点,此时就可以对该消息节点中的消息进清理。其中,临时子节点可以是消息消费者在接收到消息节点中的消息后,在该消息节点下创建的一个代表自身的临时子节点,作为消息已送达的依据。Obtain all the message queues in zookeeper, and there will be a timing task to check the messages in all the message nodes in each message queue at every preset time period, that is, check the status of the message. In this embodiment, the message Defined as "start", "transition", and "terminate" states to achieve differentiated treatment of messages of different natures, and the identification of message states can be identified through user-defined or automatic middleware identification. User self-definition is when users of middleware define messages, they can assign status to the message by inheriting interface fields. The automatic identification of middleware is to actively analyze the field value of the same type of message in the process of message cleaning to determine whether the message has been merged by other messages. If the information carried by other messages is merged, it intelligently judges the status information of the message. To ensure that even if the user-defined status information has errors, it can still be corrected to maintain the effectiveness of message cleaning. Among them, the messages in the transition state will be cleaned up in time after confirming that they are completely consumed. Therefore, it is necessary to determine whether each message node is a transition message that does not need to be persisted. If it is judged that there is a message node as a transition message, it will be compared. If the temporary child node under the message node and the temporary node under the service registration directory are consistent, it proves that the message in the message node has been consumed by all message consumers, and it can be considered as each message node in the total message queue. There is a consumed message node that has completed consumption, and the messages in the message node can be cleaned up at this time. Among them, the temporary child node may be a temporary child node that the message consumer creates under the message node after receiving the message in the message node, which represents itself, as a basis for the message to be delivered.
步骤S80,若存在,则提取所述已消费消息节点中的重要信息进行保存,并清理所述总消息队列中的已消费消息节点。Step S80, if it exists, extract and save important information in the consumed message node, and clear the consumed message node in the total message queue.
当经过判断发现存在总消息队列中的已消费消息节点,也就是可以默认已被所有监听该消息节点的消息消费者所消费,此时该消息节点中的消息就处于过渡状态,则对该过渡消息中的重要消息进行提取,并可以根据zookeeper中的消息合并机制将重要信息保存在持久状态的消息中,以便用户后期想要查看重要信息时,能及时方便地查询到,在提取并保存完已消费消息节点中的重要信息时,可以清理该已消费消息节点。其中,若在zookeeper中不存在持久状态的消息,则可以自行创建一个持久节点,以便保存重要信息。当经过判断发现存在总消息队列中的消息节点未被消费完成时,则继续保持消息节点中的消息不变。When it is judged that there is a consumed message node in the total message queue, that is, it can be consumed by all message consumers listening to the message node by default. At this time, the message in the message node is in a transition state, then the transition The important information in the message is extracted, and the important information can be stored in the persistent state according to the message merging mechanism in zookeeper, so that when the user wants to view the important information later, he can query it in time and conveniently. After extracting and saving When the important information in the message node has been consumed, the consumed message node can be cleaned up. Among them, if there is no persistent state message in zookeeper, you can create a persistent node by yourself to save important information. When it is found after judgment that the message node in the total message queue has not been consumed, the message in the message node is kept unchanged.
在本实施例中,通过检测总消息队列中是否存在已消费消息节点,若存在,则对该已消费消息节点进行清理,从而提高了消息清理的效率,提高了用户的使用体验感。In this embodiment, by detecting whether there is a consumed message node in the total message queue, and if there is, the consumed message node is cleaned up, thereby improving the efficiency of message cleanup and improving the user experience.
进一步地,在本申请第一实施例的基础上,提出了本申请消息消费方法的第四 实施例,本实施例是在本申请第一实施例的步骤S30,将所述当前消息传递至所述目标线程进行消费的步骤之后,包括:Further, on the basis of the first embodiment of this application, a fourth embodiment of the message consumption method of this application is proposed. In this embodiment, in step S30 of the first embodiment of this application, the current message is transferred to all After the steps for the target thread to consume, include:
步骤A10,检测所述当前消息在所述目标线程中是否消费成功;Step A10, detecting whether the current message is successfully consumed in the target thread;
当将当前消息传递到目标线程进行消费后,还需要检查当前消息在目标线程中是否消费成功,若消费成功,则执行下一个消息的消费,若未消费成功,则会触发恢复机制,进行补偿消费。When the current message is passed to the target thread for consumption, it is also necessary to check whether the current message is successfully consumed in the target thread. If the consumption is successful, the next message consumption will be executed. If the consumption is not successful, the recovery mechanism will be triggered to compensate consumption.
步骤A20,若所述当前消息在所述目标线程中未消费成功,则获取所述当前消息对应的version值,并根据所述version值进行补偿消费。Step A20: If the current message is not successfully consumed in the target thread, obtain the version value corresponding to the current message, and compensate the consumption according to the version value.
当经过判断发现当前消息在目标线程中未消费成功,则会启动消息消费失败后的恢复机制,由于每个消费队列的目录节点均有一个version(描述)值,并当消息队列中的消息产生变化时,zookeeper自身的机制会对消费队列目录节点的version值做增量操作。因此可以先获取当前消息对应的version值,再根据version值来计算出错失的消息数量,从而进行补偿消费,直到消费成功。When it is judged that the current message is not successfully consumed in the target thread, it will start the recovery mechanism after the message consumption failed, because each directory node of the consumption queue has a version (description) value, and when the message in the message queue is generated When it changes, zookeeper's own mechanism will increment the version value of the consumption queue directory node. Therefore, you can first obtain the version value corresponding to the current message, and then calculate the number of messages with errors based on the version value to compensate for consumption until the consumption is successful.
在本实施例中,通过检测当前消息是否消费成功,并在消费未成功时,进行补偿消费,直到消费成功,从而避免了消费失败对整个系统逻辑的影响。In this embodiment, by detecting whether the consumption of the current message is successful, and when the consumption is unsuccessful, the consumption is compensated until the consumption is successful, thereby avoiding the influence of the consumption failure on the entire system logic.
具体地,获取所述当前消息对应的version值,并根据所述version值进行补偿消费的步骤包括:Specifically, the step of obtaining the version value corresponding to the current message and compensating consumption according to the version value includes:
步骤A21,获取所述当前消息在所述消息队列中的队列version值,和所述当前消息在所述zookeeper中的本地version值,并计算所述本地version值和所述队列version值之间的差值是否大于预设值;Step A21: Obtain the queue version value of the current message in the message queue and the local version value of the current message in the zookeeper, and calculate the difference between the local version value and the queue version value Whether the difference is greater than the preset value;
在本实施例中,version值包括本地version值和队列version值。In this embodiment, the version value includes the local version value and the queue version value.
消息消费者在每次消费消息后,均会记录当前消息队列的version值,并且在每次消费消息前,也会将zookeeper中的本地version值和消息队列中的version值进行比较,若发现两者之间的差值大于预设值,则进行补偿操作,若两者之间的差值小于或等于预设值,则继续当前的消息消费操作。其中,预设值可以是用户设置的任意值,如1。The message consumer will record the version value of the current message queue after each message consumption, and before each message consumption, it will also compare the local version value in zookeeper with the version value in the message queue. If two are found If the difference between the two is greater than the preset value, a compensation operation is performed, and if the difference between the two is less than or equal to the preset value, the current message consumption operation is continued. Among them, the preset value can be any value set by the user, such as 1.
步骤A22,若所述本地version值和所述队列version值之间的差值大于预设值,则根据所述差值对所述当前消息进行补偿消费。Step A22: If the difference between the local version value and the queue version value is greater than a preset value, the current message is compensated for consumption according to the difference.
当经过判断发现本地version值和队列version值之间的差值大于预设值时,就会根据该差值来推算出错失的消息数量,并进行补偿消费,直到消费成功。When it is judged that the difference between the local version value and the queue version value is greater than the preset value, the number of messages with errors will be calculated based on the difference, and the consumption will be compensated until the consumption is successful.
在本实施例中,通过计算本地version值和队列version值之间的差值是否大于预设值,并在差值大于预设值时,进行补偿消费,从而提高了消息消费的成功率。In this embodiment, by calculating whether the difference between the local version value and the queue version value is greater than a preset value, and when the difference is greater than the preset value, compensation consumption is performed, thereby increasing the success rate of message consumption.
本申请还提供一种消息消费装置,参照图3,所述消息消费装置包括:The present application also provides a message consumption device. Referring to FIG. 3, the message consumption device includes:
获取模块,用于获取zookeeper服务注册目录中的目标节点,并基于所述目标节点监听预设数量的消息队列,确定各所述消息队列中是否存在首次监听的新消息队列;The obtaining module is used to obtain the target node in the zookeeper service registration directory, and determine whether there is a new message queue monitored for the first time in each of the message queues based on the target node monitoring a preset number of message queues;
确定模块,用于若存在首次监听的新消息队列,则依次遍历所述新消息队列中的消息,获取当前遍历的当前消息,并基于预设特征识别算法确定所述当前消息对应的目标线程;The determining module is configured to, if there is a new message queue monitored for the first time, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm;
传递模块,用于将所述当前消息传递至所述目标线程进行消费,直至所述新消息队列中的消息遍历完成。The delivery module is used to deliver the current message to the target thread for consumption until the message traversal in the new message queue is completed.
进一步地,所述确定模块,还用于:Further, the determining module is also used for:
在所述当前消息对应的顶层接口接收所述当前消息对应的特征信息,并基于预设特征识别算法识别所述特征信息;Receiving the feature information corresponding to the current message at the top-level interface corresponding to the current message, and identifying the feature information based on a preset feature recognition algorithm;
根据所述特征信息确定所述当前消息对应的目标线程。Determine the target thread corresponding to the current message according to the characteristic information.
进一步地,所述确定模块,还用于:Further, the determining module is also used for:
获取所述目标节点对应的线程池,根据所述线程池的容量和所述特征信息做取余操作,在所述线程池中获取具有取余结果标记的第一线程,并检测所述第一线程是否处于异常状态;Obtain the thread pool corresponding to the target node, perform the remainder operation according to the capacity of the thread pool and the characteristic information, acquire the first thread with the remainder result mark in the thread pool, and detect the first thread Whether the thread is in an abnormal state;
若所述第一线程处于异常状态,则启用所述线程池中的备用线程,并将所述备用线程作为所述当前消息对应的目标线程;If the first thread is in an abnormal state, enable the standby thread in the thread pool, and use the standby thread as the target thread corresponding to the current message;
若所述第一线程处于正常状态,则将所述第一线程作为所述当前消息对应的目标线程。If the first thread is in a normal state, use the first thread as the target thread corresponding to the current message.
进一步地,所述消息消费装置,还包括:Further, the message consumption device further includes:
若不存在首次监听的新消息队列,则检测各所述消息队列中是否存在新消息节 点;If there is no new message queue monitored for the first time, detecting whether there is a new message node in each of the message queues;
若存在新消息节点,则获取所述新消息节点中的新消息,并将所述新消息传递至所述新消息节点对应的第二线程进行消费。If there is a new message node, the new message in the new message node is acquired, and the new message is delivered to the second thread corresponding to the new message node for consumption.
进一步地,所述消息消费装置,还包括:Further, the message consumption device further includes:
获取zookeeper中的总消息队列,并定时确定所述总消息队列中的各消息节点中,是否存在消费完成的已消费节点,其中,所述总消息队列包括消息队列;Acquire the total message queue in zookeeper, and periodically determine whether there is a consumed node whose consumption has been completed among each message node in the total message queue, where the total message queue includes a message queue;
若存在,则提取所述已消费消息节点中的重要信息进行保存,并清理所述总消息队列中的已消费消息节点。If it exists, extract and save important information in the consumed message node, and clean up the consumed message node in the total message queue.
进一步地,所述消息消费装置,还包括:Further, the message consumption device further includes:
检测所述当前消息在所述目标线程中是否消费成功;Detecting whether the current message is successfully consumed in the target thread;
若所述当前消息在所述目标线程中未消费成功,则获取所述当前消息对应的描述version值,并根据所述version值进行补偿消费。If the current message is not successfully consumed in the target thread, the description version value corresponding to the current message is obtained, and the consumption is compensated according to the version value.
进一步地,所述version值包括本地version值和队列version值,所述消息消费装置,还包括:Further, the version value includes a local version value and a queue version value, and the message consumption device further includes:
获取所述当前消息在所述消息队列中的队列version值,和所述当前消息在所述zookeeper中的本地version值,并计算所述本地version值和所述队列version值之间的差值是否大于预设值;Obtain the queue version value of the current message in the message queue and the local version value of the current message in the zookeeper, and calculate whether the difference between the local version value and the queue version value is Greater than the preset value;
若所述本地version值和所述队列version值之间的差值大于预设值,则根据所述差值对所述当前消息进行补偿消费。If the difference between the local version value and the queue version value is greater than a preset value, the current message is compensated for consumption according to the difference.
上述各程序模块所执行的方法可参照本申请消息消费方法各个实施例,此处不再赘述。For the method executed by the above-mentioned program modules, please refer to each embodiment of the message consumption method of this application, which will not be repeated here.
本申请还提供一种计算机存储介质,所述计算机存储介质可以为非易失性可读存储介质。The present application also provides a computer storage medium, which may be a non-volatile readable storage medium.
本申请计算机存储介质上存储有计算机可读指令,所述计算机可读指令被处理器执行时实现如上所述的消息消费方法的步骤。The computer storage medium of the present application stores computer-readable instructions, and the computer-readable instructions implement the steps of the message consumption method described above when the computer-readable instructions are executed by the processor.
其中,在所述处理器上运行的计算机可读指令被执行时所实现的方法可参照本申请消息消费方法各个实施例,此处不再赘述。For the method implemented when the computer-readable instruction running on the processor is executed, please refer to each embodiment of the message consumption method of the present application, which will not be repeated here.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖 非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者系统不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者系统所固有的要素。在没有更多限制的情况下,由语句“包括一个......”限定的要素,并不排除在包括该要素的过程、方法、物品或者系统中还存在另外的相同要素。It should be noted that in this article, the terms "include", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements not only includes those elements, It also includes other elements that are not explicitly listed, or elements inherent to the process, method, article, or system. If there are no more restrictions, the element defined by the sentence "including a..." does not exclude the existence of other identical elements in the process, method, article or system that includes the element.
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。The serial numbers of the foregoing embodiments of the present application are only for description, and do not represent the advantages and disadvantages of the embodiments.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,空调器,或者网络设备等)执行本申请各个实施例所述的方法。Through the description of the above embodiments, those skilled in the art can clearly understand that the method of the above embodiments can be implemented by means of software plus the necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is better.的实施方式。 Based on this understanding, the technical solution of this application essentially or the part that contributes to the existing technology can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as ROM/RAM) as described above. , Magnetic disk, optical disk), including several instructions to make a terminal device (can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) execute the method described in each embodiment of the present application.
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。The above are only preferred embodiments of this application, and do not limit the scope of this application. Any equivalent structure or equivalent process transformation made using the content of the description and drawings of this application, or directly or indirectly used in other related technical fields , The same reason is included in the scope of patent protection of this application.

Claims (20)

  1. 一种消息消费方法,其中,所述消息消费方法包括如下步骤:A message consumption method, wherein the message consumption method includes the following steps:
    获取分布式协调服务zookeeper的服务注册目录中的目标节点,并基于所述目标节点监听预设数量的消息队列,确定各所述消息队列中是否存在首次监听的新消息队列;Obtain the target node in the service registration directory of the distributed coordination service zookeeper, and based on the target node monitor a preset number of message queues, determine whether there is a new message queue monitored for the first time in each of the message queues;
    若存在首次监听的新消息队列,则依次遍历所述新消息队列中的消息,获取当前遍历的当前消息,并基于预设特征识别算法确定所述当前消息对应的目标线程;If there is a new message queue monitored for the first time, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm;
    将所述当前消息传递至所述目标线程进行消费,直至所述新消息队列中的消息遍历完成。The current message is delivered to the target thread for consumption until the traversal of messages in the new message queue is completed.
  2. 如权利要求1所述的消息消费方法,其特征在于其中,所述基于预设特征识别算法确定所述当前消息对应的目标线程的步骤,包括:The message consumption method according to claim 1, wherein the step of determining the target thread corresponding to the current message based on a preset feature recognition algorithm comprises:
    在所述当前消息对应的顶层接口接收所述当前消息对应的特征信息,并基于预设特征识别算法识别所述特征信息;Receiving the feature information corresponding to the current message at the top-level interface corresponding to the current message, and identifying the feature information based on a preset feature recognition algorithm;
    根据所述特征信息确定所述当前消息对应的目标线程。Determine the target thread corresponding to the current message according to the characteristic information.
  3. 如权利要求2所述的消息消费方法,其中,所述根据所述特征信息确定所述当前消息对应的目标线程的步骤,包括:3. The message consumption method of claim 2, wherein the step of determining the target thread corresponding to the current message according to the characteristic information comprises:
    获取所述目标节点对应的线程池,根据所述线程池的容量和所述特征信息做取余操作,在所述线程池中获取具有取余结果标记的第一线程,并检测所述第一线程是否处于异常状态;Obtain the thread pool corresponding to the target node, perform the remainder operation according to the capacity of the thread pool and the characteristic information, acquire the first thread with the remainder result mark in the thread pool, and detect the first thread Whether the thread is in an abnormal state;
    若所述第一线程处于异常状态,则启用所述线程池中的备用线程,并将所述备用线程作为所述当前消息对应的目标线程;If the first thread is in an abnormal state, enable the standby thread in the thread pool, and use the standby thread as the target thread corresponding to the current message;
    若所述第一线程处于正常状态,则将所述第一线程作为所述当前消息对应的目标线程。If the first thread is in a normal state, use the first thread as the target thread corresponding to the current message.
  4. 如权利要求1所述的消息消费方法,其中,所述确定各所述消息队列中是否存在首次监听的新消息队列的步骤之后,包括:5. The message consumption method according to claim 1, wherein after the step of determining whether there is a new message queue monitored for the first time in each of the message queues, the method comprises:
    若不存在首次监听的新消息队列,则检测各所述消息队列中是否 存在新消息节点;If there is no new message queue monitored for the first time, detecting whether there is a new message node in each of the message queues;
    若存在新消息节点,则获取所述新消息节点中的新消息,并将所述新消息传递至所述新消息节点对应的第二线程进行消费。If there is a new message node, the new message in the new message node is acquired, and the new message is delivered to the second thread corresponding to the new message node for consumption.
  5. 如权利要求4所述的消息消费方法,其中,所述将所述新消息传递至所述新消息对应的第二线程进行消费的步骤之后,包括:The message consumption method according to claim 4, wherein after the step of delivering the new message to the second thread corresponding to the new message for consumption, the method comprises:
    获取zookeeper中的总消息队列,并定时确定所述总消息队列的各消息节点中,是否存在消费完成的已消费消息节点,其中,所述总消息队列包括消息队列;Acquire the total message queue in zookeeper, and periodically determine whether there is a consumed message node whose consumption is completed in each message node of the total message queue, wherein the total message queue includes a message queue;
    若存在,则提取所述已消费消息节点中的重要信息进行保存,并清理所述总消息队列中的已消费消息节点。If it exists, extract and save important information in the consumed message node, and clean up the consumed message node in the total message queue.
  6. 如权利要求1所述的消息消费方法,其中,所述将所述当前消息传递至所述目标线程进行消费的步骤之后,包括:The message consumption method according to claim 1, wherein after the step of passing the current message to the target thread for consumption, it comprises:
    检测所述当前消息在所述目标线程中是否消费成功;Detecting whether the current message is successfully consumed in the target thread;
    若所述当前消息在所述目标线程中未消费成功,则获取所述当前消息对应的描述version值,并根据所述version值进行补偿消费。If the current message is not successfully consumed in the target thread, the description version value corresponding to the current message is obtained, and the consumption is compensated according to the version value.
  7. 如权利要求6所述的消息消费方法,其中,所述version值包括本地version值和队列version值,8. The message consumption method of claim 6, wherein the version value includes a local version value and a queue version value,
    所述获取所述当前消息对应的version值,并根据所述version值进行补偿消费的步骤包括:The step of obtaining the version value corresponding to the current message and compensating consumption according to the version value includes:
    获取所述当前消息在所述消息队列中的队列version值,和所述当前消息在所述zookeeper中的本地version值,并计算所述本地version值和所述队列version值之间的差值是否大于预设值;Obtain the queue version value of the current message in the message queue and the local version value of the current message in the zookeeper, and calculate whether the difference between the local version value and the queue version value is Greater than the preset value;
    若所述本地version值和所述队列version值之间的差值大于预设值,则根据所述差值对所述当前消息进行补偿消费。If the difference between the local version value and the queue version value is greater than a preset value, the current message is compensated for consumption according to the difference.
  8. 一种消息消费装置,其中,所述消息消费装置包括:A message consumption device, wherein the message consumption device includes:
    获取模块,用于获取zookeeper服务注册目录中的目标节点,并基于所述目标节点监听预设数量的消息队列,确定各所述消息队列中是否存在首次监听的新消息队列;The obtaining module is used to obtain the target node in the zookeeper service registration directory, and determine whether there is a new message queue monitored for the first time in each of the message queues based on the target node monitoring a preset number of message queues;
    确定模块,用于若存在首次监听的新消息队列,则依次遍历所述新消息队列中的消息,获取当前遍历的当前消息,并基于预设特征识别算法确定所述当前消息对应的目标线程;The determining module is configured to, if there is a new message queue monitored for the first time, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm;
    传递模块,用于将所述当前消息传递至所述目标线程进行消费,直至所述新消息队列中的消息遍历完成。The delivery module is used to deliver the current message to the target thread for consumption until the message traversal in the new message queue is completed.
  9. 一种消息消费设备,其中,所述消息消费设备包括:存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机可读指令,所述计算机可读指令被所述处理器执行时实现如下步骤:A message consumption device, wherein the message consumption device includes: a memory, a processor, and computer-readable instructions stored in the memory and capable of running on the processor, and the computer-readable instructions are The processor implements the following steps when executing:
    获取分布式协调服务zookeeper的服务注册目录中的目标节点,并基于所述目标节点监听预设数量的消息队列,确定各所述消息队列中是否存在首次监听的新消息队列;Obtain the target node in the service registration directory of the distributed coordination service zookeeper, and based on the target node monitor a preset number of message queues, determine whether there is a new message queue monitored for the first time in each of the message queues;
    若存在首次监听的新消息队列,则依次遍历所述新消息队列中的消息,获取当前遍历的当前消息,并基于预设特征识别算法确定所述当前消息对应的目标线程;If there is a new message queue monitored for the first time, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm;
    将所述当前消息传递至所述目标线程进行消费,直至所述新消息队列中的消息遍历完成。The current message is delivered to the target thread for consumption until the traversal of messages in the new message queue is completed.
  10. 如权利要求9所述的消息消费设备,其中,所述基于预设特征识别算法确定所述当前消息对应的目标线程的步骤,包括:9. The message consumption device according to claim 9, wherein the step of determining the target thread corresponding to the current message based on a preset feature recognition algorithm comprises:
    在所述当前消息对应的顶层接口接收所述当前消息对应的特征信息,并基于预设特征识别算法识别所述特征信息;Receiving the feature information corresponding to the current message at the top-level interface corresponding to the current message, and identifying the feature information based on a preset feature recognition algorithm;
    根据所述特征信息确定所述当前消息对应的目标线程。Determine the target thread corresponding to the current message according to the characteristic information.
  11. 如权利要求10所述的消息消费设备,其中,所述根据所述特征信息确定所述当前消息对应的目标线程的步骤,包括:10. The message consuming device according to claim 10, wherein the step of determining the target thread corresponding to the current message according to the characteristic information comprises:
    获取所述目标节点对应的线程池,根据所述线程池的容量和所述特征信息做取余操作,在所述线程池中获取具有取余结果标记的第一线程,并检测所述第一线程是否处于异常状态;Obtain the thread pool corresponding to the target node, perform the remainder operation according to the capacity of the thread pool and the characteristic information, acquire the first thread with the remainder result mark in the thread pool, and detect the first thread Whether the thread is in an abnormal state;
    若所述第一线程处于异常状态,则启用所述线程池中的备用线程 ,并将所述备用线程作为所述当前消息对应的目标线程;If the first thread is in an abnormal state, enable the standby thread in the thread pool, and use the standby thread as the target thread corresponding to the current message;
    若所述第一线程处于正常状态,则将所述第一线程作为所述当前消息对应的目标线程。If the first thread is in a normal state, use the first thread as the target thread corresponding to the current message.
  12. 如权利要求9所述的消息消费设备,其中,所述确定各所述消息队列中是否存在首次监听的新消息队列的步骤之后,包括:9. The message consuming device according to claim 9, wherein after the step of determining whether there is a new message queue monitored for the first time in each of the message queues, the method comprises:
    若不存在首次监听的新消息队列,则检测各所述消息队列中是否存在新消息节点;If there is no new message queue monitored for the first time, detecting whether there is a new message node in each of the message queues;
    若存在新消息节点,则获取所述新消息节点中的新消息,并将所述新消息传递至所述新消息节点对应的第二线程进行消费。If there is a new message node, the new message in the new message node is acquired, and the new message is delivered to the second thread corresponding to the new message node for consumption.
  13. 如权利要求12所述的消息消费设备,其中,所述将所述新消息传递至所述新消息对应的第二线程进行消费的步骤之后,包括:The message consumption device according to claim 12, wherein, after the step of delivering the new message to the second thread corresponding to the new message for consumption, it comprises:
    获取zookeeper中的总消息队列,并定时确定所述总消息队列的各消息节点中,是否存在消费完成的已消费消息节点,其中,所述总消息队列包括消息队列;Acquire the total message queue in zookeeper, and periodically determine whether there is a consumed message node whose consumption is completed in each message node of the total message queue, wherein the total message queue includes a message queue;
    若存在,则提取所述已消费消息节点中的重要信息进行保存,并清理所述总消息队列中的已消费消息节点。If it exists, extract and save important information in the consumed message node, and clean up the consumed message node in the total message queue.
  14. 如权利要求9所述的消息消费设备,其中,所述将所述当前消息传递至所述目标线程进行消费的步骤之后,包括:9. The message consumption device according to claim 9, wherein after the step of passing the current message to the target thread for consumption, it comprises:
    检测所述当前消息在所述目标线程中是否消费成功;Detecting whether the current message is successfully consumed in the target thread;
    若所述当前消息在所述目标线程中未消费成功,则获取所述当前消息对应的描述version值,并根据所述version值进行补偿消费。If the current message is not successfully consumed in the target thread, the description version value corresponding to the current message is obtained, and the consumption is compensated according to the version value.
  15. 一种计算机存储介质,其中,所述计算机存储介质上存储有计算机可读指令,所述计算机可读指令被处理器执行时实现如下步骤:A computer storage medium, wherein computer readable instructions are stored on the computer storage medium, and when the computer readable instructions are executed by a processor, the following steps are implemented:
    获取分布式协调服务zookeeper的服务注册目录中的目标节点,并基于所述目标节点监听预设数量的消息队列,确定各所述消息队列中是否存在首次监听的新消息队列;Obtain the target node in the service registration directory of the distributed coordination service zookeeper, and based on the target node monitor a preset number of message queues, determine whether there is a new message queue monitored for the first time in each of the message queues;
    若存在首次监听的新消息队列,则依次遍历所述新消息队列中的 消息,获取当前遍历的当前消息,并基于预设特征识别算法确定所述当前消息对应的目标线程;If there is a new message queue monitored for the first time, sequentially traverse the messages in the new message queue, obtain the current message currently traversed, and determine the target thread corresponding to the current message based on a preset feature recognition algorithm;
    将所述当前消息传递至所述目标线程进行消费,直至所述新消息队列中的消息遍历完成。The current message is delivered to the target thread for consumption until the traversal of messages in the new message queue is completed.
  16. 如权利要求15所述的计算机存储介质,其中,所述基于预设特征识别算法确定所述当前消息对应的目标线程的步骤,包括:15. The computer storage medium of claim 15, wherein the step of determining the target thread corresponding to the current message based on a preset feature recognition algorithm comprises:
    在所述当前消息对应的顶层接口接收所述当前消息对应的特征信息,并基于预设特征识别算法识别所述特征信息;Receiving the feature information corresponding to the current message at the top-level interface corresponding to the current message, and identifying the feature information based on a preset feature recognition algorithm;
    根据所述特征信息确定所述当前消息对应的目标线程。Determine the target thread corresponding to the current message according to the characteristic information.
  17. 如权利要求16所述的计算机存储介质,其中,所述根据所述特征信息确定所述当前消息对应的目标线程的步骤,包括:15. The computer storage medium of claim 16, wherein the step of determining the target thread corresponding to the current message according to the characteristic information comprises:
    获取所述目标节点对应的线程池,根据所述线程池的容量和所述特征信息做取余操作,在所述线程池中获取具有取余结果标记的第一线程,并检测所述第一线程是否处于异常状态;Obtain the thread pool corresponding to the target node, perform the remainder operation according to the capacity of the thread pool and the characteristic information, acquire the first thread with the remainder result mark in the thread pool, and detect the first thread Whether the thread is in an abnormal state;
    若所述第一线程处于异常状态,则启用所述线程池中的备用线程,并将所述备用线程作为所述当前消息对应的目标线程;If the first thread is in an abnormal state, enable the standby thread in the thread pool, and use the standby thread as the target thread corresponding to the current message;
    若所述第一线程处于正常状态,则将所述第一线程作为所述当前消息对应的目标线程。If the first thread is in a normal state, use the first thread as the target thread corresponding to the current message.
  18. 如权利要求15所述的计算机存储介质,其中,所述确定各所述消息队列中是否存在首次监听的新消息队列的步骤之后,包括:15. The computer storage medium according to claim 15, wherein after the step of determining whether there is a new message queue monitored for the first time in each of the message queues, the method comprises:
    若不存在首次监听的新消息队列,则检测各所述消息队列中是否存在新消息节点;If there is no new message queue monitored for the first time, detecting whether there is a new message node in each of the message queues;
    若存在新消息节点,则获取所述新消息节点中的新消息,并将所述新消息传递至所述新消息节点对应的第二线程进行消费。If there is a new message node, the new message in the new message node is acquired, and the new message is delivered to the second thread corresponding to the new message node for consumption.
  19. 如权利要求18所述的计算机存储介质,其中,所述将所述新消息传递至所述新消息对应的第二线程进行消费的步骤之后,包括:18. The computer storage medium according to claim 18, wherein after the step of delivering the new message to the second thread corresponding to the new message for consumption, it comprises:
    获取zookeeper中的总消息队列,并定时确定所述总消息队列的各消息节点中,是否存在消费完成的已消费消息节点,其中,所述 总消息队列包括消息队列;Acquire the total message queue in zookeeper, and periodically determine whether there is a consumed message node whose consumption has been completed in each message node of the total message queue, where the total message queue includes a message queue;
    若存在,则提取所述已消费消息节点中的重要信息进行保存,并清理所述总消息队列中的已消费消息节点。If it exists, extract and save important information in the consumed message node, and clean up the consumed message node in the total message queue.
  20. 如权利要求15所述的计算机存储介质,其中,所述将所述当前消息传递至所述目标线程进行消费的步骤之后,包括:15. The computer storage medium of claim 15, wherein after the step of passing the current message to the target thread for consumption, it comprises:
    检测所述当前消息在所述目标线程中是否消费成功;Detecting whether the current message is successfully consumed in the target thread;
    若所述当前消息在所述目标线程中未消费成功,则获取所述当前消息对应的描述version值,并根据所述version值进行补偿消费。If the current message is not successfully consumed in the target thread, the description version value corresponding to the current message is obtained, and the consumption is compensated according to the version value.
PCT/CN2020/080930 2019-05-31 2020-03-24 Message consumption method, apparatus and device, and computer storage medium WO2020238365A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910479100.XA CN110213371B (en) 2019-05-31 2019-05-31 Message consumption method, device, equipment and computer storage medium
CN201910479100.X 2019-05-31

Publications (1)

Publication Number Publication Date
WO2020238365A1 true WO2020238365A1 (en) 2020-12-03

Family

ID=67790518

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/080930 WO2020238365A1 (en) 2019-05-31 2020-03-24 Message consumption method, apparatus and device, and computer storage medium

Country Status (2)

Country Link
CN (1) CN110213371B (en)
WO (1) WO2020238365A1 (en)

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112613912A (en) * 2020-12-27 2021-04-06 浙江融象数科控股有限公司 Coupon getting system design under high concurrency scene
CN112817745A (en) * 2021-01-14 2021-05-18 内蒙古蒙商消费金融股份有限公司 Task processing method and device
CN112882846A (en) * 2021-02-19 2021-06-01 深圳市云网万店科技有限公司 Data processing method and device of message queue, computer equipment and storage medium
CN113342898A (en) * 2021-06-29 2021-09-03 杭州数梦工场科技有限公司 Data synchronization method and device
CN113515391A (en) * 2021-05-14 2021-10-19 北京字节跳动网络技术有限公司 Message processing method and device, electronic equipment and computer readable storage medium
CN114567664A (en) * 2022-03-04 2022-05-31 苏州浪潮智能科技有限公司 Message processing result monitoring method and device, computer equipment and storage medium
CN115333942A (en) * 2022-08-10 2022-11-11 北京搜房科技发展有限公司 Event retry method and device, storage medium and electronic equipment
CN115865791A (en) * 2023-03-02 2023-03-28 北京天弛网络有限公司 Method, system, medium, and electronic device for path switching of backbone network failure
CN116009465A (en) * 2022-09-08 2023-04-25 上海繁易信息科技股份有限公司 Distributed data acquisition method and related device
CN116108110A (en) * 2023-04-17 2023-05-12 南方电网数字电网研究院有限公司 Kafka message consumption compensation method, system and medium
CN116887222A (en) * 2023-06-28 2023-10-13 赛力斯汽车有限公司 Method, device, equipment and medium for overtime reply of asynchronous interface of vehicle-mounted OTA module
CN117093387A (en) * 2023-10-20 2023-11-21 腾讯科技(深圳)有限公司 Message processing method, device, electronic equipment and storage medium
CN117370457A (en) * 2023-09-26 2024-01-09 浪潮智慧科技有限公司 Multithreading data real-time synchronization method, equipment and medium
CN117608877A (en) * 2023-11-29 2024-02-27 广州方舟信息科技有限公司 Data transmission method, device, equipment and storage medium

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110213371B (en) * 2019-05-31 2023-05-12 深圳前海微众银行股份有限公司 Message consumption method, device, equipment and computer storage medium
CN111078422B (en) * 2019-11-19 2023-09-12 泰康保险集团股份有限公司 Message processing method, message processing device, readable storage medium, and electronic apparatus
CN111784329B (en) * 2020-06-30 2024-04-05 京东科技控股股份有限公司 Service data processing method and device, storage medium and electronic device
CN112711490B (en) * 2021-03-26 2021-07-16 统信软件技术有限公司 Message processing method, computing device and storage medium
CN113010295B (en) * 2021-03-30 2024-06-11 中信银行股份有限公司 Stream computing method, device, equipment and storage medium
CN114490112A (en) * 2021-12-20 2022-05-13 阿里巴巴(中国)有限公司 Message processing method, device and system

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104092767A (en) * 2014-07-21 2014-10-08 北京邮电大学 Posting/subscribing system for adding message queue models and working method thereof
CN106201696A (en) * 2016-07-15 2016-12-07 东软集团股份有限公司 Method and apparatus for thread
US20170242887A1 (en) * 2016-02-24 2017-08-24 Salesforce.Com, Inc. Efficient access scheduling for super scaled stream processing systems
CN108874562A (en) * 2018-06-21 2018-11-23 北京顺丰同城科技有限公司 Distributed high concurrent message queue supplying system
CN109714239A (en) * 2018-12-27 2019-05-03 新华三技术有限公司 A kind of delivery method, VNFM equipment and server managing message
CN110213371A (en) * 2019-05-31 2019-09-06 深圳前海微众银行股份有限公司 Information consumption method, apparatus, equipment and computer storage medium

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10262032B2 (en) * 2016-02-24 2019-04-16 Salesforce.Com, Inc. Cache based efficient access scheduling for super scaled stream processing systems
CN107818484A (en) * 2016-09-14 2018-03-20 北京京东尚科信息技术有限公司 Manage the method and system for rule of making out an invoice
CN108965461A (en) * 2018-08-03 2018-12-07 华数传媒网络有限公司 Service administering method, device and dubbo service system
CN109714409B (en) * 2018-12-21 2021-09-14 优估(上海)信息科技有限公司 Message management method and system

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104092767A (en) * 2014-07-21 2014-10-08 北京邮电大学 Posting/subscribing system for adding message queue models and working method thereof
US20170242887A1 (en) * 2016-02-24 2017-08-24 Salesforce.Com, Inc. Efficient access scheduling for super scaled stream processing systems
CN106201696A (en) * 2016-07-15 2016-12-07 东软集团股份有限公司 Method and apparatus for thread
CN108874562A (en) * 2018-06-21 2018-11-23 北京顺丰同城科技有限公司 Distributed high concurrent message queue supplying system
CN109714239A (en) * 2018-12-27 2019-05-03 新华三技术有限公司 A kind of delivery method, VNFM equipment and server managing message
CN110213371A (en) * 2019-05-31 2019-09-06 深圳前海微众银行股份有限公司 Information consumption method, apparatus, equipment and computer storage medium

Cited By (23)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112613912B (en) * 2020-12-27 2023-06-16 浙江融象数科控股有限公司 Coupon retrieval system design in high concurrency scenarios
CN112613912A (en) * 2020-12-27 2021-04-06 浙江融象数科控股有限公司 Coupon getting system design under high concurrency scene
CN112817745A (en) * 2021-01-14 2021-05-18 内蒙古蒙商消费金融股份有限公司 Task processing method and device
CN112882846B (en) * 2021-02-19 2024-02-09 深圳市云网万店科技有限公司 Data processing method and device for message queue, computer equipment and storage medium
CN112882846A (en) * 2021-02-19 2021-06-01 深圳市云网万店科技有限公司 Data processing method and device of message queue, computer equipment and storage medium
CN113515391A (en) * 2021-05-14 2021-10-19 北京字节跳动网络技术有限公司 Message processing method and device, electronic equipment and computer readable storage medium
CN113342898B (en) * 2021-06-29 2022-10-04 杭州数梦工场科技有限公司 Data synchronization method and device
CN113342898A (en) * 2021-06-29 2021-09-03 杭州数梦工场科技有限公司 Data synchronization method and device
CN114567664A (en) * 2022-03-04 2022-05-31 苏州浪潮智能科技有限公司 Message processing result monitoring method and device, computer equipment and storage medium
CN114567664B (en) * 2022-03-04 2023-08-11 苏州浪潮智能科技有限公司 Message processing result monitoring method, device, computer equipment and storage medium
CN115333942A (en) * 2022-08-10 2022-11-11 北京搜房科技发展有限公司 Event retry method and device, storage medium and electronic equipment
CN115333942B (en) * 2022-08-10 2023-10-27 北京搜房科技发展有限公司 Event retry method and device, storage medium and electronic equipment
CN116009465A (en) * 2022-09-08 2023-04-25 上海繁易信息科技股份有限公司 Distributed data acquisition method and related device
CN116009465B (en) * 2022-09-08 2024-01-30 上海繁易信息科技股份有限公司 Distributed data acquisition method and related device
CN115865791B (en) * 2023-03-02 2023-05-09 北京天弛网络有限公司 Path switching method, system, medium and electronic equipment for backbone network fault
CN115865791A (en) * 2023-03-02 2023-03-28 北京天弛网络有限公司 Method, system, medium, and electronic device for path switching of backbone network failure
CN116108110B (en) * 2023-04-17 2023-08-15 南方电网数字电网研究院有限公司 Kafka message consumption compensation method, system and medium
CN116108110A (en) * 2023-04-17 2023-05-12 南方电网数字电网研究院有限公司 Kafka message consumption compensation method, system and medium
CN116887222A (en) * 2023-06-28 2023-10-13 赛力斯汽车有限公司 Method, device, equipment and medium for overtime reply of asynchronous interface of vehicle-mounted OTA module
CN117370457A (en) * 2023-09-26 2024-01-09 浪潮智慧科技有限公司 Multithreading data real-time synchronization method, equipment and medium
CN117093387A (en) * 2023-10-20 2023-11-21 腾讯科技(深圳)有限公司 Message processing method, device, electronic equipment and storage medium
CN117093387B (en) * 2023-10-20 2024-02-13 腾讯科技(深圳)有限公司 Message processing method, device, electronic equipment and storage medium
CN117608877A (en) * 2023-11-29 2024-02-27 广州方舟信息科技有限公司 Data transmission method, device, equipment and storage medium

Also Published As

Publication number Publication date
CN110213371A (en) 2019-09-06
CN110213371B (en) 2023-05-12

Similar Documents

Publication Publication Date Title
WO2020238365A1 (en) Message consumption method, apparatus and device, and computer storage medium
US10318391B2 (en) Non-blocking listener registration in the presence of data grid nodes joining the cluster
US10122595B2 (en) System and method for supporting service level quorum in a data grid cluster
US8676760B2 (en) Maintaining data integrity in data servers across data centers
Jiménez-Peris et al. Non-intrusive, parallel recovery of replicated data
US9659078B2 (en) System and method for supporting failover during synchronization between clusters in a distributed data grid
CN110071821A (en) Standby node is specified
JP2009531750A (en) Method and system for risk monitoring in online business
CN106506490B (en) A kind of distributed computing control method and distributed computing system
US20080288812A1 (en) Cluster system and an error recovery method thereof
WO2012171349A1 (en) Method, apparatus and system for implementing distributed auto-incrementing counting
US20050193039A1 (en) Fault tolerant mechanism to handle initial load of replicated object in live system
US20140092737A1 (en) Traffic control method and traffic control apparatus
CN112039970A (en) Distributed business lock service method, server, system and storage medium
CN106549796A (en) Resource control method and host node that a kind of firmware space is downloaded
US20120259968A1 (en) Continuous availability between sites at unlimited distances
CN104753987B (en) A kind of distributed conversation management method and system
US20060282524A1 (en) Apparatus, system, and method for facilitating communication between an enterprise information system and a client
CN104734895B (en) Service monitoring system and business monitoring method
WO2017157111A1 (en) Method, device and system for preventing memory data loss
CN111698301A (en) Service management method, device and storage medium for ensuring service continuation
CN113472566A (en) Status monitoring method of union block chain and master node status monitoring system
CN112463514A (en) Monitoring method and device for distributed cache cluster
CN117834376A (en) Distributed alarm system and method based on telegraf acquisition
CN116467115A (en) Resource-based backup and restore system, method 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: 20814700

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

Country of ref document: EP

Kind code of ref document: A1