Message processing method, storage medium and electronic equipment

By periodically obtaining the offset and partition status of the message server, dynamically adjusting the consumer list, and assisting in processing messages in the message accumulation partition, the problem of message accumulation in the message queue is solved, and the message processing efficiency is improved.

CN118733293APending Publication Date: 2024-10-01KE COM (BEIJING) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410764575.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-13
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

When using message queues for communication, the message accumulation problem in the internal partition or all partitions of the message server prevents consumers from consuming messages in time.

Method used

By periodically obtaining the consumption offset and production offset of the target partition in the message server, determine the partition status, add consumers of the partition in the message accumulation state to the first list, and add consumers in the message idle state Go to the second list, and control the consumers in the second list to assist the consumers in the first list to process the messages in the message accumulation partition.

Benefits of technology

It implements message consumers to automatically monitor partition status, and uses idle consumers to assist in processing messages in message accumulation partitions, thereby improving message processing capabilities and solving the problem of message accumulation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733293A_ABST
    Figure CN118733293A_ABST
Patent Text Reader

Abstract

The invention provides a message processing method, a storage medium and electronic equipment, and the method comprises the steps: periodically obtaining the consumption offset and the production offset of at least one target partition in a message server according to a set period; determining a partition state of each target partition in the at least one target partition according to the consumption offset and the production offset; in response to the partition state, indicating that the target partition is in the message accumulation state, adding message consumers of the target partition in the message accumulation state to a first list; and in response to the partition state indicating that the target partition is in the message idle state, adding the message consumer of the target partition in the message idle state to the second list, and controlling the message consumer in the second list to assist the message consumer in the first list in processing the message in the target partition in the message accumulation state. According to the method and the device, the message consumer in the idle state can assist in processing the message in the partition in the message accumulation state.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the fields of computer technology and Internet technology, and in particular to a message processing method, a storage medium and an electronic device. Background Art

[0002] Message queue is an important middleware in distributed systems. It can be used for communication between applications. In the process of using message queue for communication, the producer is responsible for producing messages and sending messages to each partition in the message server. Correspondingly, the consumer can consume the messages in the target partition. In order to ensure the orderly consumption of messages, the messages in a partition are usually pulled and consumed by one consumer.

[0003] When using message queues for communication in related technologies, there is an increase in message traffic, which results in a large number of messages in some or all partitions of the message server, and the corresponding consumers are unable to consume messages in a timely manner, resulting in message accumulation. Summary of the invention

[0004] In order to solve the above technical problems, embodiments of the present disclosure provide a message processing method, a storage medium and an electronic device.

[0005] According to a first aspect of an embodiment of the present disclosure, a message processing method is provided, including:

[0006] According to the set period, periodically obtain the consumption offset and production offset of at least one target partition in the message server;

[0007] Determine a partition state of each target partition in at least one target partition according to the consumption offset and the production offset;

[0008] In response to the partition status indicating that a target partition is in a message accumulation state, adding a message consumer of the target partition in the message accumulation state to a first list;

[0009] In response to the partition status indicating that a target partition is in a message idle state, adding a message consumer of the target partition in the message idle state to a second list;

[0010] The message consumers in the second list are controlled to assist the message consumers in the first list in processing messages in the target partition that are in a message accumulation state.

[0011] In some optional implementations of the present disclosure, controlling the message consumers in the second list to assist the message consumers in the first list in processing messages in the target partition in a message accumulation state includes:

[0012] Reading the first list;

[0013] In response to the first list being not empty, controlling the message consumers in the second list to process the messages in the target partition in a message accumulation state according to the association information of the message consumers in the first list.

[0014] In some further optional implementations of the present disclosure, controlling the message consumers in the second list to assist the message consumers in the first list in processing messages in the target partition in a message accumulation state includes:

[0015] In response to there being only one message consumer in the first list, determining the one message consumer as a target consumer;

[0016] In response to there being more than two message consumers in the first list, selecting a message consumer from the more than two message consumers as a target consumer;

[0017] Acquire and process the to-be-processed message from the pulled message queue of the target consumer, wherein the pulled message queue is determined according to the associated information of the target consumer;

[0018] In response to the pending message being successfully processed, the attribute information of the pending message is stored in a corresponding consumed message queue, and the consumed message queue is determined according to the associated information of the target consumer.

[0019] In some further optional implementations of the present disclosure, after storing the attribute information of the to-be-processed message in the corresponding consumed message queue, the method further includes:

[0020] The target consumer is controlled to return the attribute information of the message to be processed to the corresponding target partition, so that the target partition updates the consumption offset according to the attribute information of the message to be processed.

[0021] In some further optional implementations of the present disclosure, the pulled message queue contains messages pulled by the message consumer from the target partition, and the pulled message queue is stored in a distributed cache system;

[0022] The consumed message queue contains messages obtained and successfully processed by the message consumer from the pulled message queue, and the consumed message queue is stored in the distributed cache system;

[0023] The first list and the second list are stored in a distributed cache system.

[0024] In some further optional implementations of the present disclosure, determining the partition status of each target partition in at least one target partition according to the consumption offset and the production offset includes:

[0025] Calculate the difference between the production offset and the consumption offset of each target partition;

[0026] In response to the difference being greater than a first threshold, determining that the partition state of the corresponding target partition is a message accumulation state;

[0027] In response to the difference being not greater than the first threshold and greater than the second threshold, determining that the partition state of the corresponding target partition is a normal message inventory state;

[0028] In response to the difference being not greater than the second threshold, determining that the partition state of the corresponding target partition is a message idle state.

[0029] In some further optional implementations of the present disclosure, in response to the partition state of the target partition being a message accumulation state, the method further includes:

[0030] Prompt information is generated, where the prompt information is used to prompt a user that the target partition is in a message accumulation state.

[0031] According to a second aspect of an embodiment of the present disclosure, a message processing device is provided, including:

[0032] An acquisition module, used for periodically acquiring a consumption offset and a production offset of at least one target partition in a message server according to a set period;

[0033] A state determination module, configured to determine a partition state of each target partition in at least one target partition according to the consumption offset and the production offset;

[0034] A first adding module, configured to add a message consumer of the target partition in the message accumulation state to a first list in response to the partition state indicating that the target partition is in the message accumulation state;

[0035] A second adding module is used for adding the message consumers of the target partition in the message idle state to the second list in response to the partition state indicating that the target partition is in the message idle state;

[0036] The message processing module is used to control the message consumers in the second list to assist the message consumers in the first list in processing the messages in the target partition that are in a message accumulation state.

[0037] In some further optional implementations of the present disclosure, the message processing module includes:

[0038] A list reading submodule, used for reading the first list;

[0039] The first processing submodule is used to control the message consumers in the second list to process the messages in the target partition in the message accumulation state according to the association information of the message consumers in the first list in response to the first list being not empty.

[0040] In some further optional implementations of the present disclosure, the message processing module includes:

[0041] A first determination submodule, configured to determine, in response to there being only one message consumer in the first list, the one message consumer as a target consumer;

[0042] A second determination submodule is configured to select a message consumer from the two or more message consumers as a target consumer in response to there being more than two message consumers in the first list;

[0043] A second processing submodule is used to obtain and process the to-be-processed message from the pulled message queue of the target consumer, where the pulled message queue is determined according to the associated information of the target consumer;

[0044] The storage submodule is used to store the attribute information of the message to be processed into a corresponding consumed message queue in response to the message to be processed being successfully processed, and the consumed message queue is determined according to the associated information of the target consumer.

[0045] In some further optional implementations of the present disclosure, the message processing module further includes:

[0046] The sending submodule is used to control the target consumer to return the attribute information of the message to be processed to the corresponding target partition, so that the target partition updates the consumption offset according to the attribute information of the message to be processed.

[0047] In some further optional implementations of the present disclosure, the pulled message queue contains messages pulled by the message consumer from the target partition, and the pulled message queue is stored in a distributed cache system;

[0048] The consumed message queue contains messages obtained and successfully processed by the message consumer from the pulled message queue, and the consumed message queue is stored in the distributed cache system;

[0049] The first list and the second list are stored in a distributed cache system.

[0050] In some further optional implementations of the present disclosure, the state determination module includes:

[0051] A calculation submodule, used for calculating the difference between the production offset and the consumption offset of each target partition;

[0052] A third determining submodule, configured to determine, in response to the difference being greater than a first threshold, that the partition state of the corresponding target partition is a message accumulation state;

[0053] a fourth determination submodule, configured to determine, in response to the difference being not greater than the first threshold and greater than the second threshold, that the partition state of the corresponding target partition is a normal message inventory state;

[0054] The fifth determining submodule is configured to determine, in response to the difference being not greater than the second threshold, that the partition state of the corresponding target partition is a message idle state.

[0055] In some further optional embodiments of the present disclosure, the device further comprises:

[0056] The prompt module is used to generate prompt information, where the prompt information is used to prompt the user that the target partition is in a message accumulation state.

[0057] According to a third aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, wherein the storage medium stores computer program instructions, and when the computer program instructions are executed, the above-mentioned message processing method is implemented.

[0058] According to a fourth aspect of an embodiment of the present disclosure, an electronic device is provided, the electronic device comprising:

[0059] A memory for storing a computer program product;

[0060] The processor is used to execute the computer program product stored in the memory, and when the computer program product is executed, the message processing method is implemented.

[0061] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, comprising computer program instructions, which implement the above-mentioned message processing method when executed by a processor.

[0062] Based on the above-mentioned embodiments of the present disclosure, when communicating through a message queue, the message consumer can periodically obtain the consumption offset and production offset of the target partition according to a set period, and then determine the partition status of the target partition, so that when the target partition is in a message accumulation state, the message consumer of the target partition in the message accumulation state is added to the first list, and the message consumer of the target partition in the message idle state is added to the second list, so as to control the message consumers in the second list to process the messages of the target partition in the message accumulation state. Therefore, the technical solution of the present disclosure can realize that each message consumer automatically and periodically monitors the partition status of the assigned target partition, and the message consumer in the idle state assists in processing the messages in the partition in the message accumulation state, thereby improving the message processing capability and solving the message accumulation problem in the partition.

[0063] The technical solution of the present disclosure is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] By describing the embodiments of the present disclosure in more detail in conjunction with the accompanying drawings, the above and other purposes, features and advantages of the present disclosure will become more apparent. The accompanying drawings are used to provide a further understanding of the embodiments of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. In the drawings, the same reference numerals generally represent the same components or steps.

[0065] Figure 1 A flowchart of an embodiment of the message processing method disclosed in the present invention;

[0066] Figure 2 A message processing schematic diagram of the message processing method disclosed in the present invention;

[0067] Figure 3 A flowchart of another embodiment of the message processing method disclosed herein;

[0068] Figure 4 A flowchart of assisting message processing by a message consumer in an idle state in the message processing method disclosed herein;

[0069] Figure 5 A schematic diagram of the structure of an embodiment of a message processing device disclosed in the present invention;

[0070] Figure 6 A structural diagram of another embodiment of the message processing device disclosed in the present invention;

[0071] Figure 7 It is a structural diagram of an electronic device provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0072] The exemplary embodiments according to the present disclosure will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all the embodiments of the present disclosure, and it should be understood that the present disclosure is not limited to the exemplary embodiments described here.

[0073] It should be noted that the relative arrangement of components and steps, the numerical expressions and numerical values ​​set forth in these embodiments do not limit the scope of the present disclosure unless specifically stated otherwise.

[0074] Those skilled in the art can understand that the terms "first" and "second" in the embodiments of the present disclosure are only used to distinguish different steps, devices or modules, etc., and neither represent any specific technical meaning nor indicate the necessary logical order between them.

[0075] It should also be understood that in the embodiments of the present disclosure, “plurality” may refer to two or more than two, and “at least one” may refer to one, two, or more than two.

[0076] It should also be understood that any component, data or structure mentioned in the embodiments of the present disclosure can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.

[0077] In addition, the term "and / or" in this disclosure is only a description of the association relationship of associated objects, indicating that there may be three relationships, such as A and / or B, which can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this disclosure generally indicates that the associated objects before and after are in an "or" relationship.

[0078] It should also be understood that the description of the various embodiments in the present disclosure focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced to each other, and for the sake of brevity, they will not be described one by one.

[0079] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.

[0080] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.

[0081] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.

[0082] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.

[0083] The embodiments of the present disclosure can be applied to electronic devices such as terminal devices, computer systems, servers, etc., which can operate with many other general or special computing system environments or configurations. Examples of well-known terminal devices, computing systems, environments and / or configurations suitable for use with electronic devices such as terminal devices, computer systems or servers include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network personal computers, small computer systems, large computer systems, and distributed cloud computing technology environments including any of the above systems, etc.

[0084] Electronic devices such as terminal devices, computer systems, servers, etc. can be described in the general context of computer system executable instructions (such as program modules) executed by computer systems. Generally, program modules can include routines, programs, target programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in a distributed cloud computing environment. In a distributed cloud computing environment, tasks can be performed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can be located on local or remote computing system storage media including storage devices.

[0085] SUMMARY OF THE DISCLOSURE

[0086] In the process of implementing the present disclosure, the inventors found that when using a message queue to send messages, there is a problem that due to uneven message sending, a large number of messages in some partitions are accumulated, or due to burst traffic, a large number of messages in all partitions are accumulated, and it is difficult for message consumers to quickly consume the accumulated messages. In the message processing method provided by the present disclosure, each message consumer can store the message in a distributed cache system after pulling the message, such as a remote dictionary service (RemoteDictionary Server, referred to as Redis) storage system, and periodically detect the partition status of each target partition in the message server, so that when the partition status is a message accumulation state, the corresponding message consumer is added to the first list, and when the partition status is a message idle state, the corresponding second message consumer is added to the second list, and the second message consumer in the second list assists the first message consumer in the first list to process the message of the target partition, thereby solving the problem that message consumers find it difficult to quickly consume accumulated messages.

[0087] Among them, each partition is an ordered, immutable message queue. When a new message needs to be inserted into the partition, the message can be inserted after the partition (that is, the tail of the queue). Each message in the partition will be assigned a continuous ID value (production offset).

[0088] In order to ensure the orderly consumption of messages, messages in a partition are usually subscribed / consumed by one consumer. When a message consumer consumes a message, it needs to record a consumption offset for the corresponding partition. The consumption offset is the position of the latest consumed message (the production offset of the latest consumed message).

[0089] Exemplary Methods

[0090] Figure 1 FIG. 1 is a flow chart of an embodiment of the message processing method disclosed in the present invention. Figure 1 The method shown includes step 101 to step 105. Each step is described below.

[0091] In step 101, the consumption offset and production offset of at least one target partition in the message server are periodically obtained according to a set period.

[0092] In some optional implementations, the set period can be freely set according to the amount of message traffic in the platform, the latency requirements for message processing, etc. For example, during business peaks, such as when an e-commerce platform is promoting a big sale, the number of orders increases dramatically, and the order server may generate a large number of messages and send them to the inventory server for processing. In this scenario, the set period can be set to be shorter so that message consumers can promptly obtain information on whether there is a backlog of messages in each partition of the message server.

[0093] In some optional implementations, the set period may also be a preset fixed value. For example, if the set period is 3 seconds, the message offset and production offset of the partition are obtained every 3 seconds.

[0094] In some optional implementations, the target partition is the partition subscribed by the message consumer. The target partition subscribed by each message consumer is determined based on the configuration. A message consumer can subscribe to multiple target partitions, but a target partition can only be subscribed to by one message consumer. Figure 2When deploying a message server, you can pre-configure a message consumer group, which includes multiple message consumers. Each message consumer corresponds to a target partition. For example, message consumer 1 is configured to consume messages in partition 1, so the target partition of message consumer 1 is partition 1, message consumer 2 is configured to consume messages in partition 2, so the target partition of message consumer 2 is partition 2, message consumer 3 is configured to consume messages in partition 3, so the target partition of message consumer 3 is partition 3, and message consumer 4 and message consumer 5 are not configured with partitions. Therefore, message consumer 4 and message consumer 5 can be used as message consumers for dynamic expansion. When the message consumer subscribed to the target partition cannot consume messages quickly, resulting in message accumulation in partitions 1 to 3 at the same time, the message consumer can be dynamically expanded in the message consumer group, and when the message consumer subscribed to the target partition can consume messages quickly and there is no message accumulation in partitions 1 to 3 at the same time, the dynamically expanded message consumer can be deleted.

[0095] Among them, the production offset of the target partition is used to indicate the offset corresponding to the latest message added in the target partition. For example, in partition 1, when the first message is added, the production offset can be 00001, and when the 100th message is added, the production offset can be 00100. The production offset increases with the number of messages added to the target partition. The consumption offset of the target partition is used to indicate the offset corresponding to the latest processed message in the target partition. For example, after the message consumer pulls and processes the message in partition 1, it can return the attribute information of the processed message to partition 1 after the processing is completed, such as the message identifier and production offset of the message, so that partition 1 can obtain the current consumption offset.

[0096] For specific implementation, see Figure 2 After message consumer 1 pulls the message from partition 1, it can be stored in the pulled message queue 1 of the distributed cache system redis. The pulled message queue 1 stores the attribute information of the message (including message identifier, message displacement (production offset), the partition to which the message belongs), etc. After message consumer 1 or other auxiliary consumers process the message in the pulled message queue 1, they can add the attribute information of the processed message to the corresponding consumed message queue 1. Message consumer 1 can return the attribute information of the message in the consumed message queue 1 to partition 1 in sequence, so that partition 1 can obtain the consumption offset. It should be noted that if a message consumer subscribes to more than two target partitions, it is necessary to set a pulled message queue and a consumed message queue for the messages of each partition.

[0097] In some optional implementations, the message consumer may access the corresponding target partition to obtain the consumption offset and production offset of the target partition.

[0098] In step 102, the partition state of each target partition in at least one target partition is determined according to the consumption offset and the production offset.

[0099] In some optional implementations, the partition state of the target partition can be used to indicate whether there is a message accumulation state in the target partition. The partition state can include a message accumulation state, a message idle state, and a message inventory normal state.

[0100] In some optional implementations, the partition state of the target partition may be determined based on the difference between the consumption offset and the production offset. For example, the difference between the production offset and the consumption offset is calculated; in response to the difference being greater than a first threshold, the partition state of the target partition is determined to be a message accumulation state; in response to the difference being not greater than the first threshold and greater than a second threshold, the partition state of the target partition is determined to be a message inventory normal state; in response to the difference being not greater than the second threshold, the partition state of the target partition is determined to be a message idle state.

[0101] Among them, the first threshold is greater than the second threshold, and the sizes of the first threshold and the second threshold can be freely set according to the amount of message traffic in the platform, the delay requirements for message processing, etc.

[0102] The message accumulation state indicates that the throughput of the message consumer is insufficient and the consumption speed is much lower than the production speed of the partition. For example, when an e-commerce platform holds a big promotion, a large number of messages may be produced in the order server and consumed by the inventory system. At this time, the order server may publish too many messages to the partition of the message server, causing the message consumer to be unable to consume in time and too many messages to accumulate in the partition of the message server.

[0103] The message idle state is used to indicate that there are very few unconsumed messages in the target partition, and can even be close to zero, that is, the value of the second threshold is relatively small. If the target partition of a message consumer is in the message idle state, the message consumer can assist other message consumers in processing messages in the partition in the message accumulation state.

[0104] The normal state of message inventory is used to indicate that the amount of unconsumed messages in the target partition is in a state where the message consumers subscribed to the target partition can consume them themselves. When the message inventory is normal, the corresponding message consumer can neither help other message consumers to consume nor need other message consumers to help consume.

[0105] Furthermore, if a message consumer subscribes to only one target partition, if the target partition is in a message accumulation state, step 103 is executed; if the target partition is in a message idle state, step 104 is executed. If a message consumer subscribes to more than two target partitions, the partition states of each target partition subscribed by the message consumer can be determined, and when the partition state of a partition in the subscribed target partition is a message accumulation state, step 103 is executed; when the partition state of each target partition in the subscribed target partition is a message idle state, step 104 is executed.

[0106] In step 103, in response to the partition status indicating that a target partition is in a message accumulation state, message consumers of the target partition in the message accumulation state are added to the first list.

[0107] The first list records the target partition message consumers in the message accumulation state. Specifically, the consumer ID of the message consumer can be recorded in the first list, and the pulled message queue ID and consumed message queue ID of the message consumer can also be recorded. When a message consumer subscribes to only one target partition, there is only one pulled message queue and one consumed message queue ID; when a message consumer subscribes to more than two target partitions, there is one pulled message queue and one consumed message queue for each target partition.

[0108] In some optional implementations, the first list may be stored in a distributed cache system, and each message consumer may access the first list.

[0109] In some optional implementations, the consumer identifier of a message consumer is used to identify the corresponding message consumer, such as the server address of the message consumer; the pulled message queue identifier of the message consumer is used to identify the corresponding pulled message queue, such as the queue name or queue storage address of the pulled message queue; the consumed message queue identifier of the message consumer is used to identify the corresponding consumed message queue, such as the queue name or queue storage address of the consumed message queue.

[0110] Among them, the pulled message queue contains messages pulled by message consumers from the target partition, and the pulled message queue is stored in the distributed cache system; the consumed message queue contains messages obtained and successfully processed by message consumers from the pulled message queue, and the consumed message queue is stored in the distributed cache system.

[0111] In step 104, in response to the partition status indicating that a target partition is in a message idle state, the message consumers of the target partition in the message idle state are added to the second list.

[0112] The second list records the message consumers in idle state (the above-mentioned second message consumers), and specifically records the consumer identifier of the second message consumer. The second message consumers in idle state may include message consumers to which no target partition is assigned, and may also include message consumers to which target partitions are assigned but all the assigned target partitions are in message idle state.

[0113] In step 105, the message consumers in the second list are controlled to assist the message consumers in the first list in processing messages in the target partition that are in a message accumulation state.

[0114] In some optional implementations, the message consumers in the second list can be used to assist the message consumers in the first list in processing messages. The process of processing messages can be found in Figure 3 The illustrated embodiment will not be described in detail here.

[0115] In some optional implementations, the second list may be stored in a distributed cache system, and each message consumer may access the second list.

[0116] Through the above steps 101 to 105, when communicating through the message queue, the message consumer can periodically obtain the consumption offset and production offset of the target partition according to the set period, and then determine the partition status of the target partition, so that when the target partition is in a message accumulation state, the message consumer of the target partition in the message accumulation state is added to the first list, and the message consumer of the target partition in the message idle state is added to the second list, so that the message consumers in the second list can assist the message consumers in the first list to process the messages of the target partition in the message accumulation state. Therefore, the technical solution disclosed in the present invention can realize that each message consumer automatically and periodically monitors the partition status of the assigned target partition, and the message consumer in the idle state assists in processing the messages in the partition in the message accumulation state, thereby improving the message processing capability and solving the problem of message accumulation in the partition.

[0117] Figure 3 The present invention is a flowchart of another embodiment of the message processing method of the present invention. Figure 3 Take the example of how the message consumer in the second list assists in processing messages. Figure 3 The method shown includes step 301 and step 302. Each step is described below.

[0118] In step 301, a first list is read.

[0119] In some optional implementations, each message consumer added to the second list can access the first list in real time. When the first list is not empty, step 302 is executed; when the first list is empty, step 302 is executed.

[0120] In step 302, in response to the first list being not empty, the message consumers in the second list are controlled to process the messages in the target partition in a message accumulation state according to the associated information of the message consumers in the first list.

[0121] In some optional implementations, if the first list is not empty, it means that the first list contains the associated information of the message consumers in the busy state, as shown in FIG. Figure 2 Message consumer 1 in.

[0122] In some optional implementations, the first list may record only one message consumer, or may record more than two message consumers. Each message consumer in the second list can randomly select a message consumer in the first list, obtain the pulled message queue of the message consumer based on the associated information of the message consumer, and read messages from the pulled message queue for processing.

[0123] Among them, the associated information of the message consumer recorded in the first list includes not only the consumer identifier of the message consumer, but also the queue identifier of the message queue that the message consumer has pulled (such as the queue name or the queue storage address), the consumed message queue identifier of the message consumer (such as the queue name or the queue storage address), and other information.

[0124] In some optional implementations, the process in which the message consumer in the second list assists the message consumer in the first list in processing the messages in the target partition in the message accumulation state can be seen in Figure 4 The embodiment shown.

[0125] In some other optional implementations, if the first list is empty, a prompt message may be generated to prompt the user to delete the message consumers that are not subscribed to the target partition from the system.

[0126] In some optional real-time methods, users (operators) can dynamically add and delete message consumers in the second list that are not subscribed to the target partition.

[0127] In specific implementation, if the target partitions of each message consumer are not in a message accumulation state, it means that each message consumer subscribed to the target partition can consume messages in the target partition normally, and there may even be message consumers in an idle state. In this case, each message consumer or message consumers in an idle state can generate a prompt message to prompt the operator to delete the message consumer that has not subscribed to the target partition from the system. If the target partitions of each message consumer are in a message accumulation state, or some target partitions are in a message accumulation state, and some target partitions are in a normal message inventory state, it means that the currently configured message consumers are insufficient and it is necessary to expand the capacity of message consumers to assist in processing messages. In this case, the message consumers of the target partition in a message accumulation state can also generate a prompt message, which is used to prompt the user that the target partition is in a message accumulation state, so that the user (operator) can dynamically expand the capacity of message consumers according to the prompt message.

[0128] The message processing method disclosed in the present invention realizes that the second message consumer in the second list which is in an idle state can automatically assist the first message consumer in the first list in processing messages, and when the currently configured message consumers are insufficient to consume messages, prompts the operator to dynamically expand the message consumers by generating prompt information, and when the expanded message consumers do not need to process messages, prompts the operator to promptly delete the expanded message consumers by generating prompt information, thereby realizing dynamic expansion and deletion of message consumers, being simple to operate, and eliminating the need for the operator to monitor in real time whether the configuration of the message consumers is sufficient, thereby reducing the workload of the operator.

[0129] Figure 4 This is a flowchart of the message consumer in the idle state assisting in processing messages in the message processing method disclosed in the present invention. Figure 4 As shown, step 302 includes steps 321 to 324.

[0130] In step 321, in response to there being only one message consumer in the first list, the message consumer is determined as a target consumer.

[0131] In some optional implementations, the target consumer can be understood as the message consumer selected by the message consumer in the second list to assist in processing messages. If there is only one message consumer in the first list, the message consumer can be directly determined as the target consumer.

[0132] In step 322, in response to there being more than two message consumers in the first list, one message consumer is selected from the more than two message consumers as a target consumer.

[0133] In some optional implementations, a message consumer may be randomly selected from two or more message consumers in the first list as the target consumer; in another optional implementation, a busiest message consumer may be selected as the target consumer based on the busyness of the two or more message consumers.

[0134] In order to implement the disclosed embodiment, the busyness value of each message consumer can also be recorded in the first list. The busyness of each message consumer can be determined according to the number of accumulated messages (the difference between the production offset and the consumption offset of the target partition). For example, if the number of pending messages accumulated in the target partition 1 subscribed by message consumer 1 exceeds 3000, and the number of pending messages accumulated in the target partition subscribed by message consumer 2 does not exceed 2000, then the busyness of message consumer 1 exceeds the busyness of message consumer 2, and the message consumers in the second list can give priority to message consumer 1 as the target consumer.

[0135] In step 323, the to-be-processed message is obtained from the pulled message queue of the target consumer and processed.

[0136] In some optional implementations, if the target consumer subscribes to only one target partition, it is sufficient to obtain and process the pending messages from the pulled message queue corresponding to the target partition.

[0137] In some other optional implementations, if the target consumer subscribes to more than two target partitions, a pulled message queue may be selected from more than two pulled message queues corresponding to the more than two target partitions to obtain and process the pending messages.

[0138] In specific implementation, you can select a pulled message queue based on the message accumulation levels of the target partitions corresponding to more than two pulled message queues. For example, a message consumer in the first list subscribes to two target partitions, and the message accumulation levels of the two target partitions are such that target partition 1 has more accumulated messages. In this case, you can choose to first obtain and process the pending messages from the pulled message queue corresponding to target partition 1.

[0139] In step 324, in response to the pending message being successfully processed, the attribute information of the pending message is stored in the corresponding consumed message queue.

[0140] In some optional implementations, the corresponding consumed message queue is used to indicate the consumed message queue corresponding to the pulled message queue. For example, if message consumer 2 in the second list assists message consumer 1 in the first list to process pending messages of target partition 1 in a message accumulation state, the message association information can be added to the consumed message queue 1 corresponding to target partition 1 after successfully processing the pending messages.

[0141] The attribute information of the message to be processed may include the message identifier, the production offset of the message, the partition to which the message belongs, etc.

[0142] In some optional implementations, if the corresponding pending message is not successfully processed, a retry may be performed. If the message is still not successfully processed after the number of retries exceeds the set number of times, the attribute information and processing results of the pending message may be returned to the corresponding target partition for delayed consumption.

[0143] In some optional embodiments, after the message consumer in the second list assists the target consumer in processing the pending message and stores the attribute information of the pending message in the corresponding consumed message queue, the corresponding target consumer may return the attribute information of the pending message to the target partition, so that the target partition updates the consumption offset according to the attribute information of the pending message.

[0144] In the disclosed embodiment, an implementation method is disclosed in which message consumers in the second list assist message consumers in the first list in processing messages. Idle message consumers can be used to assist busy message consumers in processing messages, and dynamic expansion of message consumers can be used to assist busy message consumers in processing messages, thereby ensuring fast consumption of messages from each partition.

[0145] Exemplary Devices

[0146] Figure 5 FIG. 1 is a schematic diagram of a structure of an embodiment of a message processing device disclosed in the present invention. Figure 5 As shown, the device comprises:

[0147] An acquisition module 51, used for periodically acquiring a consumption offset and a production offset of at least one target partition in a message server according to a set period;

[0148] A state determination module 52, configured to determine a partition state of each target partition in at least one target partition according to the consumption offset and the production offset;

[0149] A first adding module 53 is used for adding message consumers of the target partition in the message accumulation state to the first list in response to the partition state indicating that the target partition is in the message accumulation state;

[0150] A second adding module 54 is configured to add the message consumers of the target partition in the message idle state to the second list in response to the partition state indicating that the target partition is in the message idle state;

[0151] The message processing module 55 is used to control the message consumers in the second list to assist the message consumers in the first list in processing the messages in the target partition in the message accumulation state.

[0152] Figure 6 A structural diagram of another embodiment of the message processing device disclosed in the present invention. Figure 6 As shown, in Figure 5 On the basis of the illustrated embodiment, in some further optional implementations of the present disclosure, the message processing module 55 includes:

[0153] The list reading submodule 551 is used to read the first list;

[0154] The first processing submodule 552 is used to control the message consumers in the second list to process the messages in the target partition in the message accumulation state according to the association information of the message consumers in the first list in response to the first list being not empty.

[0155] In some further optional embodiments of the present disclosure, the message processing module 56 includes:

[0156] A first determination submodule 553, configured to determine, in response to there being only one message consumer in the first list, the one message consumer as a target consumer;

[0157] A second determining submodule 554 is configured to select a message consumer from the two or more message consumers as a target consumer in response to there being more than two message consumers in the first list;

[0158] A second processing submodule 555 is used to obtain and process the to-be-processed message from the pulled message queue of the target consumer, where the pulled message queue is determined according to the associated information of the target consumer;

[0159] The storage submodule 556 is used to store the attribute information of the message to be processed into a corresponding consumed message queue in response to the message to be processed being successfully processed. The consumed message queue is determined according to the associated information of the target consumer.

[0160] In some further optional implementations of the present disclosure, the message processing module 55 further includes:

[0161] The sending submodule 557 is used to control the target consumer to return the attribute information of the message to be processed to the corresponding target partition, so that the target partition updates the consumption offset according to the attribute information of the message to be processed.

[0162] In some further optional embodiments of the present disclosure, the pulled message queue contains messages pulled by the message consumer from the target partition, and the pulled message queue is stored in the distributed cache system;

[0163] The consumed message queue contains messages that the message consumer has obtained and successfully processed from the pulled message queue. The consumed message queue is stored in the distributed cache system.

[0164] The first list and the second list are stored in a distributed cache system.

[0165] In some further optional embodiments of the present disclosure, the state determination module 52 includes:

[0166] A calculation submodule 521, used for calculating the difference between the production offset and the consumption offset of each target partition;

[0167] A third determining submodule 522, configured to determine, in response to the difference being greater than a first threshold, that the partition state of the corresponding target partition is a message accumulation state;

[0168] A fourth determining submodule 523 is configured to determine, in response to the difference being not greater than the first threshold and greater than the second threshold, that the partition state of the corresponding target partition is a normal message inventory state;

[0169] The fifth determining submodule 524 is configured to determine, in response to the difference being not greater than the second threshold, that the partition state of the corresponding target partition is a message idle state.

[0170] In some further optional embodiments of the present disclosure, the device further comprises:

[0171] The prompt module 56 is used to generate prompt information in response to the partition state of the target partition being a message accumulation state, where the prompt information is used to prompt the user that the target partition is in a message accumulation state.

[0172] The device of the embodiment of the present disclosure can be used to implement the methods of the above-mentioned embodiments of the present disclosure. The two correspond to each other in specific implementation, and the specific implementations of related parts are referenced to each other, which will not be repeated here.

[0173] Exemplary electronic devices, computer program products, and computer-readable storage media

[0174] An embodiment of the present disclosure further provides an electronic device, comprising: a memory for storing a computer program; a processor for executing the computer program stored in the memory, and when the computer program is executed, the message processing method of any of the above embodiments of the present disclosure is implemented.

[0175] Below, reference Figure 7 An electronic device according to an embodiment of the present disclosure is described, in which a device for implementing the method according to an embodiment of the present disclosure may be integrated. Figure 7 A structural diagram of an electronic device provided in an exemplary embodiment of the present disclosure, such as Figure 7 As shown, the electronic device includes one or more processors 71, one or more computer-readable storage media memory 72, and a computer program stored in the memory and executable on the processor. When the program in the memory 72 is executed, the above-mentioned message processing method can be implemented.

[0176] Specifically, in practical applications, the electronic device may further include components such as an input device 73 and an output device 74, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown). Those skilled in the art will appreciate that Figure 7 The structure of the electronic device shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or certain components, or different component arrangements.

[0177] The processor 71 can be a central processing unit (CPU) or other forms of processing units with message processing capabilities and / or instruction execution capabilities. It performs various functions and processes data by running or executing software programs and / or modules stored in the memory 72, and calling data stored in the memory 72, thereby monitoring the electronic device as a whole.

[0178] The memory 72 may store one or more computer programs, and the memory may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The above-mentioned volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. The above-mentioned non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer programs may be stored on the computer-readable storage medium, and the processor 71 may run the computer program to implement the message processing method of each embodiment of the present disclosure above and / or other desired functions.

[0179] The input device 73 can be used to receive input digital or character information. The input device 73 can include a keyboard, a mouse, a joystick, etc. related to user settings and function control.

[0180] The output device 74 can output various information to the outside, including the determined distance information, direction information, etc. The output device 74 can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, and the like.

[0181] The electronic device may also include a power supply for supplying power to various components, which may be logically connected to the processor 71 through a power management system, so as to manage charging, discharging, power consumption and other functions through the power management system. The power supply may also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components.

[0182] Of course, to simplify, Figure 7 Only some of the components related to the present disclosure in the electronic device are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device may further include any other appropriate components.

[0183] In addition to the above-mentioned methods and devices, an embodiment of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the message processing method according to various embodiments of the present disclosure described in the above-mentioned "Exemplary Method" section of this specification.

[0184] The computer program product may be written in any combination of one or more programming languages ​​to write program code for performing the operations of the disclosed embodiments, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0185] In addition, an embodiment of the present disclosure may also be a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the processor executes the steps of the message processing method according to various embodiments of the present disclosure described in the above "Exemplary Method" section of this specification.

[0186] Computer readable storage media can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0187] The basic principles of the present disclosure are described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, effects, etc. mentioned in the present disclosure are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. are required by each embodiment of the present disclosure. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, and are not limitations. The above details do not limit the present disclosure to the necessity of adopting the above specific details to be implemented.

[0188] Each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system embodiment, since it basically corresponds to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0189] A person of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk, etc., various media that can store program codes.

[0190] The method and apparatus of the present disclosure may be implemented in many ways. For example, the method and apparatus of the present disclosure may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is for illustration only, and the steps of the method of the present disclosure are not limited to the order specifically described above, unless otherwise specifically stated. In addition, in some embodiments, the present disclosure may also be implemented as a program recorded in a recording medium, which includes machine-readable instructions for implementing the method according to the present disclosure. Therefore, the present disclosure also covers a recording medium storing a program for executing the method according to the present disclosure.

[0191] The description of the present disclosure is given for the purpose of illustration and description, and is not intended to be exhaustive or to limit the present disclosure to the disclosed form. Many modifications and variations will be apparent to those of ordinary skill in the art. The embodiments are selected and described in order to better illustrate the principles and practical applications of the present disclosure, and to enable those of ordinary skill in the art to understand the present disclosure and thereby design various embodiments with various modifications suitable for specific uses.

Claims

1. A message processing method, characterized in that: include: According to the set period, periodically obtain the consumption offset and production offset of at least one target partition in the message server; Determine a partition state of each target partition in at least one target partition according to the consumption offset and the production offset; In response to the partition status indicating that a target partition is in a message accumulation state, adding a message consumer of the target partition in the message accumulation state to a first list; In response to the partition status indicating that a target partition is in a message idle state, adding a message consumer of the target partition in the message idle state to a second list; The message consumers in the second list are controlled to assist the message consumers in the first list in processing messages in the target partition that are in a message accumulation state.

2. The method according to claim 1, characterized in that The controlling the message consumers in the second list to assist the message consumers in the first list in processing messages in the target partition in a message accumulation state includes: Reading the first list; In response to the first list being not empty, controlling the message consumers in the second list to process the messages in the target partition in a message accumulation state according to the associated information of the message consumers in the first list.

3. The method according to any one of claims 1-2, characterized in that: The controlling the message consumers in the second list to assist the message consumers in the first list in processing messages in the target partition in a message accumulation state includes: In response to there being only one message consumer in the first list, determining the one message consumer as a target consumer; In response to there being more than two message consumers in the first list, selecting a message consumer from the more than two message consumers as a target consumer; Acquire and process the to-be-processed message from the pulled message queue of the target consumer, wherein the pulled message queue is determined according to the associated information of the target consumer; In response to the pending message being successfully processed, the attribute information of the pending message is stored in a corresponding consumed message queue, and the consumed message queue is determined according to the associated information of the target consumer.

4. The method according to claim 3, characterized in that After storing the attribute information of the to-be-processed message in the corresponding consumed message queue, the method further includes: The target consumer is controlled to return the attribute information of the message to be processed to the corresponding target partition, so that the target partition updates the consumption offset according to the attribute information of the message to be processed.

5. The method according to claim 3, characterized in that: The pulled message queue contains messages pulled by the message consumer from the target partition, and the pulled message queue is stored in the distributed cache system; The consumed message queue contains messages obtained and successfully processed by the message consumer from the pulled message queue, and the consumed message queue is stored in the distributed cache system; The first list and the second list are stored in a distributed cache system.

6. The method according to any one of claims 1 to 5, characterized in that: The step of determining the partition status of each target partition in at least one target partition according to the consumption offset and the production offset includes: Calculate the difference between the production offset and the consumption offset of each target partition; In response to the difference being greater than a first threshold, determining that the partition state of the corresponding target partition is a message accumulation state; In response to the difference being not greater than the first threshold and greater than the second threshold, determining that the partition state of the corresponding target partition is a normal message inventory state; In response to the difference being not greater than the second threshold, determining that the partition state of the corresponding target partition is a message idle state.

7. The method according to any one of claims 1 to 6, characterized in that: In response to the partition state of the target partition being a message accumulation state, the method further includes: Prompt information is generated, where the prompt information is used to prompt a user that the target partition is in a message accumulation state.

8. A computer-readable storage medium, wherein the storage medium stores computer program instructions, and when the computer program instructions are executed, the method according to any one of claims 1 to 7 is implemented.

9. An electronic device, comprising: Memory for storing computer programs; A processor is used to execute the computer program stored in the memory, and when the computer program is executed, the method described in any one of claims 1 to 7 is implemented.

10. A computer program product comprising computer program instructions, characterized in that When the computer program instructions are executed by a processor, the method described in any one of claims 1 to 7 is implemented.