Message processing method and apparatus, and communication device and storage medium
By obtaining the primary and child IDs of the target message from the Kafka cluster partition and using a record table to identify and process abnormal child messages, the problem of data loss and inconsistency in the Kafka message system is solved, improving message processing efficiency and data consistency.
Patent Information
- Application Number
- PCT/CN2023/139963
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-02-27
- Filing Date
- 2023-12-19
- Publication Date
- 2024-09-06
AI Technical Summary
In existing technologies, Kafka messaging systems suffer from problems such as data loss, duplication, and inconsistency due to abnormal messages during consumption. Furthermore, existing solutions increase the complexity of message processing and reduce efficiency.
By obtaining the primary ID of the target message from the Kafka cluster partition, and utilizing the message processing record table and sub-message processing record table, unconsumed sub-messages can be identified and processed to achieve exception handling and avoid duplicate execution of the entire message.
It improves the efficiency of asynchronous message processing, ensures the concurrency and order of messages, prevents unrecoverable exceptions from blocking tasks, and guarantees data consistency.
Smart Images

Figure CN2023139963_06092024_PF_FP
Abstract
Description
Message processing method, device, communication equipment and storage medium
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on February 27, 2023, with application number 202310166682.2, and application name “Message Processing Method, Device, Communication Equipment and Storage Medium”, all contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of data communication technology and provides a message processing method, apparatus, communication equipment and storage medium. Background Art
[0003] Kafka is a distributed, partitioned, multi-copy distributed messaging system. Its biggest feature is that it can process large amounts of data in real time to meet various demand scenarios.
[0004] Implementing asynchronous task execution based on Kafka has obvious advantages over traditionally cumbersome task types and data persistence implementation processes. However, when abnormal messages such as database connection exceptions and message configuration errors occur on the consumer side during the consumption process, it will lead to data loss, data duplication, Kafka message congestion and other problems during business processing, resulting in high system pressure and data inconsistency.
[0005] In the prior art, for abnormal messages generated during the consumption process, the abnormal messages are pushed to the second consumption queue for delayed consumption; when the second consumption queue still fails to process the messages, the messages are stored in the database, and a scheduled task is used to periodically scan the abnormal tasks in the database and execute them again. In addition, by periodically scanning the tasks to be processed in the database, the complexity of message processing is increased and the efficiency of message processing is reduced.
[0006] Summary of the Invention
[0007] The embodiments of the present application provide a message processing method, apparatus, communication equipment and storage medium to solve problems such as consumption data loss, duplication, and data inconsistency caused by system anomalies, message configuration errors, etc.
[0008] In order to solve the above problems, in a first aspect, an embodiment of the present application discloses a message processing method, the method comprising:
[0009] Get the target message and the primary ID corresponding to the target message in the Kafka cluster partition;
[0010] Searching for the processing status of the target message in a pre-acquired message processing record table according to the primary ID;
[0011] When it is detected that the processing status of the target message is in an unsuccessful consumption state, searching the execution status of all sub-messages corresponding to the target message from the pre-acquired sub-message processing record table according to the main ID;
[0012] When it is detected that the execution state of the target sub-message is in an abnormal state, the target sub-message is subjected to abnormal processing.
[0013] Optionally, after the step of searching the pre-acquired message processing record table for the processing status of the target message according to the primary ID, the method further includes:
[0014] When it is detected that the processing status of the target message is in a consumption success state, a flag bit corresponding to the target message is sent to the Kafka cluster, wherein the flag bit is used to indicate that the target message has completed consumption.
[0015] Optionally, each of the messages includes a unique main ID, each of the messages includes at least one sub-message, and each of the sub-messages includes a unique sub-ID.
[0016] Optionally, performing exception processing on the target sub-message includes:
[0017] Updating the processing status corresponding to the target message in the message processing record table, and updating the execution status corresponding to the target sub-message in the sub-message processing record table;
[0018] When it is detected that the execution status corresponding to the target sub-message is in the completed state, the processing status corresponding to the target message is updated to the consumption success state in the message processing record table.
[0019] Optionally, when detecting that the execution status of the target sub-message is in an abnormal state, performing abnormal processing on the target sub-message includes:
[0020] When it is detected that the execution state corresponding to the target sub-message is in an abnormal state, the target sub-message is subjected to abnormal processing according to the abnormal type corresponding to the target sub-message.
[0021] Optionally, performing exception handling on the target sub-message according to the exception type corresponding to the target sub-message includes:
[0022] When it is detected that the exception type corresponding to the target sub-message is a recoverable exception type, reprocessing the target sub-message according to a preset time interval;
[0023] When it is detected that the exception type corresponding to the target sub-message is an unrecoverable exception type, a flag bit corresponding to the target message is sent to the Kafka cluster, wherein the flag bit is used to indicate that the target message has completed consumption.
[0024] Optionally, the unsuccessful consumption state includes: the processing state identifier corresponding to the target message is a recoverable identifier, or the processing state identifier corresponding to the target message is an interruption identifier.
[0025] Optionally, after the step of searching the pre-acquired message processing record table for the processing status of the target message according to the primary ID, the method includes:
[0026] When it is detected that the processing status of the target message in the message processing record table is a state that cannot be queried, the target message is recreated in the Kafka cluster partition.
[0027] In a second aspect, an embodiment of the present application further discloses a message processing device, the device comprising:
[0028] The acquisition module is used to obtain the target message and the primary ID corresponding to the target message in the Kafka cluster partition;
[0029] A first search module is used to search the processing status of the target message in a preset message processing record table according to the main ID;
[0030] A second search module is configured to search, based on the primary ID, from a preset sub-message processing record table for the execution status of all sub-messages corresponding to the target message when detecting that the processing status of the target message is in an unsuccessful consumption state;
[0031] The processing module is used to perform exception processing on the target sub-message when it is detected that the execution status of the target sub-message is in an abnormal state.
[0032] Optionally, the device further includes:
[0033] The sending module is used to send a flag corresponding to the target message to the Kafka cluster when it is detected that the processing status of the target message is in a consumption success state, wherein the flag is used to indicate that the target message has completed consumption.
[0034] Optionally, the processing module includes:
[0035] A first updating submodule, configured to update the processing status corresponding to the target message in the message processing record table, and to update the execution status corresponding to the target sub-message in the sub-message processing record table;
[0036] The second updating submodule is configured to update the processing status corresponding to the target message to a consumption success status in the message processing record table when detecting that the execution status corresponding to the target submessage is in a completion status.
[0037] Optionally, the processing module includes:
[0038] The exception handling submodule is used to perform exception handling on the target sub-message according to the exception type corresponding to the target sub-message when it is detected that the execution state corresponding to the target sub-message is in an abnormal state.
[0039] Optionally, the exception handling submodule includes:
[0040] a first processing unit, configured to reprocess the target sub-message at a preset time interval when detecting that the exception type corresponding to the target sub-message is a recoverable exception type;
[0041] The second processing unit is used to send a flag corresponding to the target message to the Kafka cluster when it is detected that the exception type corresponding to the target sub-message is an unrecoverable exception type, wherein the flag is used to indicate that the consumption of the target message is completed.
[0042] Optionally, the device further includes:
[0043] A creation module is used to recreate the target message in the Kafka cluster partition when it is detected that the processing status of the target message in the message processing record table is a state that cannot be queried.
[0044] In a third aspect, an embodiment of the present application further discloses a communication device, including:
[0045] at least one processor; and,
[0046] a memory communicatively connected to the at least one processor; wherein,
[0047] The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to perform the message processing method described above.
[0048] In a fourth aspect, the present application further discloses a computer-readable storage medium storing a computer program, characterized in that the computer program implements the above-mentioned message processing method when executed by a processor.
[0049] The embodiments of the present application include the following advantages:
[0050] The message processing method provided by the embodiment of the present application obtains the target message and the main ID corresponding to the target message in the Kafka cluster partition; searches for the processing status of the target message in the pre-acquired message processing record table according to the main ID; when it is detected that the processing status of the target message is in the unsuccessful consumption state, searches for the execution status of all sub-messages corresponding to the target message from the pre-acquired sub-message processing record table according to the main ID; when it is detected that the execution status of the target sub-message is in the abnormal state, performs abnormal processing on the target sub-message. The present application obtains the target message and the target message ID in the Kafka cluster partition, that is, by utilizing the principle of multi-partition parallel consumption of Kafka, and a single partition has only one consumption thread for a consumer group, thereby ensuring the concurrency and sequentiality of asynchronous messages. When the status of the target message is in the unsuccessful consumption state, it only needs to start execution from the abnormal sub-message, without the need to re-execute the entire message, thereby improving the efficiency of asynchronous message processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0052] FIG1 is a flowchart of one of the steps of the message processing method provided in an embodiment of the present application;
[0053] FIG2 is a second flow chart of the steps of the message processing method provided in an embodiment of the present application;
[0054] FIG3 is a flowchart of the third step of the message processing method provided in an embodiment of the present application;
[0055] FIG4 is a device block diagram of a message processing device provided in an embodiment of the present application;
[0056] FIG5 is a schematic structural diagram of a communication device provided in an embodiment of the present application;
[0057] FIG6 is a schematic diagram of parallel consumption provided in an embodiment of the present application. DETAILED DESCRIPTION
[0058] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0059] 1 , a flowchart of one of the steps of a message processing method provided in an embodiment of the present application is shown. The method may include:
[0060] Step 101: Obtain a target message and a primary ID corresponding to the target message in a Kafka cluster partition.
[0061] It should be noted that Kafka represents a distributed publish-subscribe message system. For the Kafka system, the data push end will store the data in the Kafka database, and will write a unique identifier to each message. The consumer end can obtain this data from the Kafka database. When multiple messages are consumed in parallel, as shown in Figure 6, Figure 6 is a parallel consumption schematic diagram provided by an embodiment of the present application, wherein producer represents the producer, consumer represents the consumer, partition represents the partition, topic is similar to a folder in the file system, and events are files in the folder. The topic in Kafka includes multiple producers and multiple subscribers, and the topic is partitioned, which means that a topic can be distributed on multiple Kafka nodes. Therefore, combined with Figure 6, it can be seen that by utilizing Kafka's multi-partition parallel consumption, the principle that a single partition has only one consumer thread for a consumer group can maximize the concurrency and sequentiality of asynchronous messages.
[0062] The consumer can obtain messages or tasks from the Kafka cluster partition. A message includes several sub-messages or sub-tasks. A message has a globally unique main ID and can include multiple sub-messages. Each sub-message has a sub-ID. Multiple sub-IDs of the same message cannot be repeated. The main ID and sub-ID can determine the corresponding unique sub-task, and the main ID can be used to determine whether the message is repeated.
[0063] It should be noted that for sub-messages, sub-messages support transactionality and idempotence, where transactionality means that during the message processing process, the message is either in a consumption success state or a consumption failure state, with no intermediate state, that is, transactionality includes a consumption success state and an unsuccessful consumption state; a new combined identification ID is generated by combining the main ID and the sub-ID, and the combined identification ID is used as the idempotent unique identifier of a sub-task. The execution result of the identifier is stored in redis (Remote Dictionary Server, remote dictionary service), where redis is an open source log-type database that supports the network and can be memory-based or persistent. Repeated execution will not change the result. By only ensuring the transactionality and idempotence of a single sub-task, there is no need to ensure the transactionality and idempotence of the entire message. When an exception occurs during message processing, it is only necessary to retry from the abnormal sub-message without re-executing the entire main message, thereby reducing resource waste and improving the speed of asynchronous message processing.
[0064] Specifically, a message with a primary ID and a sub-ID is obtained from a Kafka partition. After the message is sent to the partition corresponding to the Kafka topic, it can be obtained by the consumer, for example, by consumption subscription. Therefore, after the consumer thread obtains the message, it can identify the message according to the primary ID, and can also identify a sub-message according to the primary ID and sub-ID.
[0065] Step 102: Search the processing status of the target message in the pre-acquired message processing record table according to the primary ID.
[0066] It should be noted that in the embodiments of the present application, the message processing status can be found in the message processing record table in the database based on the unique primary ID corresponding to the message. Specifically, during the message processing process, the message content including the primary ID is first stored in the message processing record table, and the status mark is updated in real time based on the processing status corresponding to the message. Therefore, in the Kafka database table, based on the primary ID, it is possible to query whether there are duplicate messages and the processing status.
[0067] Step 103: When it is detected that the processing status of the target message is in an unsuccessful consumption state, the execution status of all sub-messages corresponding to the target message is searched from a pre-acquired sub-message processing record table according to the main ID.
[0068] It should be noted that in an embodiment of the present application, the processing status of the target message is searched in step 102. If the processing status of the target message is found and the processing status is in an unsuccessful consumption state, there is no need to reprocess the entire target message. The abnormal sub-message can be found according to the characteristics of the sub-message, and the abnormal sub-message can be reprocessed.
[0069] Specifically, if the message is found and determined to be unsuccessful in consumption, it is necessary to re-execute from the abnormal subtask.
[0070] Furthermore, the unsuccessful consumption state includes: the processing state identifier corresponding to the target message is a recoverable identifier, or the processing state identifier corresponding to the target message is an interrupted identifier.
[0071] For example, in one embodiment, the target message is considered to be in an unsuccessful consumption state as long as one of the following conditions is met: first, the message status is marked as failed, and the exception is recoverable; second, the message status is marked as being processed, but the execution time has exceeded the set threshold, in which case it is considered that the system is abnormally interrupted during message processing.
[0072] Step 104: When it is detected that the execution state of the target sub-message is in an abnormal state, the target sub-message is subjected to abnormal processing.
[0073] It should be noted that in this embodiment of the present application, when the processing status corresponding to the target message is determined to be unsuccessful, the sub-message with an abnormal execution status such as failure, timeout, or unprocessed is searched from the sub-message processing record table based on the primary ID of the target message and re-executed. In this application, sub-messages ensure data consistency by supporting transactionality and idempotence.
[0074] Specifically, in some embodiments, step 104 performs exception processing on the target sub-message when it is detected that the execution status of the target sub-message is in an abnormal state, and may include the following steps: updating the processing status corresponding to the target message in the message processing record table, and updating the execution status corresponding to the target sub-message in the sub-message processing record table; when it is detected that the execution status corresponding to the target sub-message is in a completed state, updating the processing status corresponding to the target message in the message processing record table to a consumption success state.
[0075] It should be noted that, when it is detected that the execution status of the target sub-message is in an abnormal state, the target sub-message will be processed abnormally, that is, the abnormal sub-message will be processed and re-executed. The specific steps are: first, the status of the message processing record table is updated to be processed. When executing the sub-message to be retried, the status of the sub-message is first updated to be processed, and then executed. Finally, the completion status of the sub-message is updated. When all sub-messages are executed, the status of the target message is updated.
[0076] Specifically, the execution process is a process of determining whether the sub-message is consumed and subscribed normally according to the user's needs.
[0077] Furthermore, in some embodiments, step 104 may also include: when it is detected that the execution state corresponding to the target sub-message is in an abnormal state, performing exception processing on the target sub-message according to the exception type corresponding to the target sub-message.
[0078] Furthermore, performing exception processing on the target sub-message according to the exception type corresponding to the target sub-message may include the following: when it is detected that the exception type corresponding to the target sub-message is a recoverable exception type, reprocessing the target sub-message at a preset time interval; when it is detected that the exception type corresponding to the target sub-message is an unrecoverable exception type, sending a flag bit corresponding to the target message to the Kafka cluster, wherein the flag bit is used to indicate that the target message has completed consumption.
[0079] It should be noted that if the target submessage's execution result is a successful consumption or the corresponding exception type is a failure or unrecoverable exception, the target message is considered to be consumed. At this point, you can submit the offset value, which sends the corresponding flag of the target message to the Kafka cluster. OFFSET is an attribute operator, indicating that the value of the symbolic address (not the content) following it should be used as the operand. Specifically, when the task is completed, Kafka is notified that the message has been consumed and will not be consumed again next time. For messages with unrecoverable exceptions, a message is sent to the user to notify them for manual processing.
[0080] If the target sub-message's corresponding exception type is Failure (Recoverable), the target message is considered unconsumed and will be consumed again after a predetermined period of hibernation. This means the target sub-message will be reprocessed at a preset interval. Specifically, this type of exception indicates a system failure, preventing the offset from being fed back to Kafka. The consumption process must be repeated. However, if consumed directly again, it will likely fail again. Therefore, a period of hibernation is required before the consumption is repeated.
[0081] The message processing method provided by the embodiment of the present application obtains the target message and the main ID corresponding to the target message in the Kafka cluster partition; searches for the processing status of the target message in the pre-acquired message processing record table according to the main ID; when it is detected that the processing status of the target message is in the unsuccessful consumption state, searches for the execution status of all sub-messages corresponding to the target message from the pre-acquired sub-message processing record table according to the main ID; when it is detected that the execution status of the target sub-message is in the abnormal state, performs abnormal processing on the target sub-message. The present application obtains the target message and the target message ID in the Kafka cluster partition, that is, by utilizing the principle of multi-partition parallel consumption of Kafka, and a single partition has only one consumption thread for a consumer group, thereby ensuring the concurrency and sequentiality of asynchronous messages. When the status of the target message is in the unsuccessful consumption state, it only needs to start execution from the abnormal sub-message, without the need to re-execute the entire message, thereby improving the efficiency of asynchronous message processing.
[0082] In addition, by classifying and processing sub-message exceptions, we can prevent unrecoverable abnormal sub-messages from blocking tasks, greatly improving message processing efficiency and ensuring that messages in the same partition are executed in sequence. For most asynchronous tasks, the execution order directly affects the eventual consistency of the data.
[0083] 2 , there is shown a second flowchart of the message processing method provided in an embodiment of the present application. The method may include:
[0084] Step 101: Obtain a target message and a primary ID corresponding to the target message in a Kafka cluster partition.
[0085] Step 102: Search the processing status of the target message in the pre-acquired message processing record table according to the primary ID.
[0086] Step 103: When it is detected that the processing status of the target message is in an unsuccessful consumption state, the execution status of all sub-messages corresponding to the target message is searched from a pre-acquired sub-message processing record table according to the main ID.
[0087] It should be noted that, in the embodiment of the present application, the above steps 101-103 refer to the previous discussion and will not be repeated here.
[0088] Step 105: When it is detected that the processing status of the target message is in a consumption success state, a flag corresponding to the target message is sent to the Kafka cluster, wherein the flag is used to indicate that the target message has completed consumption.
[0089] It should be noted that in an embodiment of the present application, if the processing status of the target message can be found and the processing status corresponding to the target message is in a successful consumption state, the message can be considered to be duplicate data, and the consumption subscription process is completed. At this time, the offset value can be fed back to Kafka, where the offset value can be represented as a flag bit, which is used to indicate that the target message has completed consumption.
[0090] The message processing method provided by the embodiment of the present application obtains the target message and the main ID corresponding to the target message in the Kafka cluster partition; searches for the processing status of the target message in the pre-acquired message processing record table according to the main ID; when it is detected that the processing status of the target message is in the unsuccessful consumption state, searches for the execution status of all sub-messages corresponding to the target message from the pre-acquired sub-message processing record table according to the main ID; when it is detected that the execution status of the target sub-message is in the abnormal state, performs abnormal processing on the target sub-message. The present application obtains the target message and the target message ID in the Kafka cluster partition, that is, by utilizing the principle of multi-partition parallel consumption of Kafka, and a single partition has only one consumption thread for a consumer group, thereby ensuring the concurrency and sequentiality of asynchronous messages. When the status of the target message is in the unsuccessful consumption state, it only needs to start execution from the abnormal sub-message, without the need to re-execute the entire message, thereby improving the efficiency of asynchronous message processing.
[0091] In addition, by sending the flag corresponding to the target message to the Kafka cluster and feeding back the target message to the Kafka system to complete consumption, it can be ensured that relevant data is not lost during the message processing stage.
[0092] 3 , there is shown a flowchart of the third step of the message processing method provided in an embodiment of the present application. The method may include:
[0093] Step 101: Obtain a target message and a primary ID corresponding to the target message in a Kafka cluster partition.
[0094] Step 102: Search the processing status of the target message in the pre-acquired message processing record table according to the primary ID.
[0095] It should be noted that, in the embodiment of the present application, the above steps 101-102 refer to the previous discussion and will not be repeated here.
[0096] Step 106: When it is detected that the processing status of the target message in the message processing record table is in an unqueryable state, recreate the target message in the Kafka cluster partition.
[0097] It should be noted that in this embodiment of the application, if the target message is not found, a record of the main message being processed is first inserted into the database corresponding to the Kafka cluster partition. Then, the status of each sub-message is executed. The processing status of each sub-message is updated in real time to the sub-message processing record table. When the sub-message is executed, the result status of the message processing record table is updated. Specifically, this step records the status of each sub-message in real time so that the abnormal and unprocessed sub-messages can be found and re-executed in the event of an exception.
[0098] This application obtains the target message and target message ID in the Kafka cluster partition, that is, by utilizing the principle of multi-partition parallel consumption of Kafka and a single partition having only one consumer thread for a consumer group, to ensure the concurrency and sequentiality of asynchronous messages. When the status of the target message is not successfully consumed, it only needs to start execution from the abnormal sub-message without re-executing the entire message, thereby improving the efficiency of asynchronous message processing.
[0099] 4 , a schematic diagram of the structure of a message processing device provided in an embodiment of the present application is shown, wherein the device includes:
[0100] Acquisition module 201 is used to obtain the target message and the primary ID corresponding to the target message in the Kafka cluster partition;
[0101] A first search module 202 is configured to search for the processing status of the target message in a preset message processing record table according to the primary ID;
[0102] The second search module 203 is configured to search the execution status of all sub-messages corresponding to the target message from a preset sub-message processing record table according to the main ID when detecting that the processing status of the target message is in an unsuccessful consumption state;
[0103] The processing module 204 is configured to perform exception processing on the target sub-message when it is detected that the execution status of the target sub-message is in an abnormal state.
[0104] Optionally, the device further includes:
[0105] The sending module is used to send a flag corresponding to the target message to the Kafka cluster when it is detected that the processing status of the target message is in a consumption success state, wherein the flag is used to indicate that the target message has completed consumption.
[0106] Optionally, the processing module includes:
[0107] A first updating submodule, configured to update the processing status corresponding to the target message in the message processing record table, and to update the execution status corresponding to the target sub-message in the sub-message processing record table;
[0108] The second updating submodule is configured to update the processing status corresponding to the target message to a consumption success status in the message processing record table when detecting that the execution status corresponding to the target submessage is in a completion status.
[0109] Optionally, the processing module includes:
[0110] The exception handling submodule is used to perform exception handling on the target sub-message according to the exception type corresponding to the target sub-message when it is detected that the execution state corresponding to the target sub-message is in an abnormal state.
[0111] Optionally, the exception handling submodule includes:
[0112] a first processing unit, configured to reprocess the target sub-message at a preset time interval when detecting that the exception type corresponding to the target sub-message is a recoverable exception type;
[0113] The second processing unit is used to send a flag corresponding to the target message to the Kafka cluster when it is detected that the exception type corresponding to the target sub-message is an unrecoverable exception type, wherein the flag is used to indicate that the consumption of the target message is completed.
[0114] Optionally, the device further includes:
[0115] A creation module is used to recreate the target message in the Kafka cluster partition when it is detected that the processing status of the target message in the message processing record table is a state that cannot be queried.
[0116] The message processing device provided by the embodiment of the present application obtains the target message and the main ID corresponding to the target message in the Kafka cluster partition; searches for the processing status of the target message in the pre-acquired message processing record table according to the main ID; when it is detected that the processing status of the target message is in the unsuccessful consumption state, searches for the execution status of all sub-messages corresponding to the target message from the pre-acquired sub-message processing record table according to the main ID; when it is detected that the execution status of the target sub-message is in the abnormal state, performs abnormal processing on the target sub-message. The present application obtains the target message and the target message ID in the Kafka cluster partition, that is, by utilizing the principle of multi-partition parallel consumption of Kafka, and a single partition has only one consumption thread for a consumer group, thereby ensuring the concurrency and sequentiality of asynchronous messages. When the status of the target message is in the unsuccessful consumption state, it only needs to start execution from the abnormal sub-message, without the need to re-execute the entire message, thereby improving the efficiency of asynchronous message processing.
[0117] The embodiment of the present application further provides a communication device, as shown in FIG5 , including a processor 401, a communication interface 402, a memory 403, and a communication bus 404, wherein the processor 401, the communication interface 402, and the memory 403 communicate with each other via the communication bus 404.
[0118] Memory 403, used for storing computer programs;
[0119] When the processor 401 is used to execute the program stored in the memory 403, it can implement the following steps:
[0120] Receive the message to be parsed, generate a table lookup request based on the message, match the message with the TCAM rule table pre-configured in the target protocol processing unit in parallel based on the table lookup request, generate a matching action table, extract the key information of the message, and strip the message according to the preset protocol layer length in the action table to obtain the data information of the message.
[0121] The communication bus mentioned in the terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not mean that there is only one bus or only one type of bus.
[0122] The communication interface is used for communication between the above terminal and other devices.
[0123] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.
[0124] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.
[0125] In another embodiment provided by the present application, a computer-readable storage medium is further provided. The computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the message processing method described in any one of the above embodiments.
[0126] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the message processing method described in any one of the above embodiments.
[0127] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
[0128] Although preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic inventive concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0129] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or terminal device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that includes the element.
[0130] Each embodiment in this specification is described in a related manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiment is generally similar to the method embodiment, so the description is relatively simple. For related parts, refer to the description of the method embodiment.
[0131] The above is a detailed introduction to a message processing method, device, communication equipment and storage medium provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
[0132] The above description is only a preferred embodiment of the present application and is not intended to limit the scope of protection of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the scope of protection of the present application.
Claims
1. A message processing method, characterized in that: The method comprises: Get the target message and the primary ID corresponding to the target message in the Kafka cluster partition; Searching the processing status of the target message in a pre-acquired message processing record table according to the primary ID; When it is detected that the processing status of the target message is in an unsuccessful consumption state, searching the execution status of all sub-messages corresponding to the target message from the pre-acquired sub-message processing record table according to the main ID; When it is detected that the execution state of the target sub-message is in an abnormal state, the target sub-message is subjected to abnormal processing.
2. The message processing method according to claim 1, characterized in that: After the step of searching the processing status of the target message in the pre-acquired message processing record table according to the primary ID, the method further includes: When it is detected that the processing status of the target message is in a consumption success status, a flag bit corresponding to the target message is sent to the kafka cluster, wherein the flag bit is used to indicate that the target message has completed consumption.
3. The message processing method according to claim 1, characterized in that: Each of the messages includes a unique main ID, each of the messages includes at least one sub-message, and each of the sub-message includes a unique sub-ID.
4. The message processing method according to claim 1, characterized in that: The performing exception processing on the target sub-message comprises: The processing status corresponding to the target message is updated in the message processing record table, and the execution status corresponding to the target sub-message is updated in the sub-message processing record table; When it is detected that the execution status corresponding to the target sub-message is in the completed state, the processing status corresponding to the target message is updated to the consumption success state in the message processing record table.
5. The message processing method according to claim 1, characterized in that: When detecting that the execution state of the target sub-message is in an abnormal state, performing abnormal processing on the target sub-message includes: When it is detected that the execution state corresponding to the target sub-message is in an abnormal state, the target sub-message is subjected to abnormal processing according to the abnormal type corresponding to the target sub-message.
6. The message processing method according to claim 5, characterized in that: The performing exception handling on the target sub-message according to the exception type corresponding to the target sub-message includes: When it is detected that the exception type corresponding to the target sub-message is a recoverable exception type, reprocessing the target sub-message at a preset time interval; When it is detected that the exception type corresponding to the target sub-message is an unrecoverable exception type, a flag bit corresponding to the target message is sent to the Kafka cluster, wherein the flag bit is used to indicate that the target message has completed consumption.
7. The message processing method according to claim 1, characterized in that: The unsuccessful consumption state includes: the processing state identifier corresponding to the target message is a recoverable identifier, or the processing state identifier corresponding to the target message is an interrupt identifier.
8. The message processing method according to claim 1, characterized in that: After the step of searching the processing status of the target message in the pre-acquired message processing record table according to the primary ID, the method includes: When it is detected that the processing status of the target message in the message processing record table is a state that cannot be queried, the target message is recreated in the kafka cluster partition.
9. A message processing device, characterized in that: The device comprises: The acquisition module is used to obtain the target message and the primary ID corresponding to the target message in the Kafka cluster partition; A first search module, used to search the processing status of the target message in a preset message processing record table according to the main ID; A second search module is used to search the execution status of all sub-messages corresponding to the target message from a preset sub-message processing record table according to the main ID when it is detected that the processing status of the target message is in an unsuccessful consumption state; The processing module is used to perform exception processing on the target sub-message when it is detected that the execution state of the target sub-message is in an abnormal state.
10. The device according to claim 9, characterized in that The device also includes: The sending module is used to send a flag bit corresponding to the target message to the Kafka cluster when it is detected that the processing status of the target message is in a consumption success state, wherein the flag bit is used to indicate that the target message has completed consumption.
11. The device according to claim 9, characterized in that The processing module comprises: A first updating submodule, configured to update the processing status corresponding to the target message in the message processing record table, and to update the execution status corresponding to the target sub-message in the sub-message processing record table; The second updating submodule is used to update the processing status corresponding to the target message to a consumption success status in the message processing record table when detecting that the execution status corresponding to the target sub-message is in a completion status.
12. The device according to claim 9, characterized in that The processing module comprises: The exception handling submodule is used to perform exception handling on the target submessage according to the exception type corresponding to the target submessage when it is detected that the execution state corresponding to the target submessage is in an abnormal state.
13. The device according to claim 12, characterized in that The exception handling submodule includes: A first processing unit, configured to reprocess the target sub-message at a preset time interval when detecting that the exception type corresponding to the target sub-message is a recoverable exception type; The second processing unit is used to send a flag bit corresponding to the target message to the Kafka cluster when it is detected that the exception type corresponding to the target sub-message is an irrecoverable exception type, wherein the flag bit is used to indicate that the consumption of the target message is completed.
14. A communication device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, used to implement the steps of the message processing method described in any one of claims 1 to 8 when executing a program stored in a memory.
15. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the message processing method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Message processing method and system based on kafka, storage medium and computer equipment
CN111314422A
Anomaly detection method and system, and computing device
CN113347201A
Task processing method, device and equipment and computer readable medium
CN113485806A
Task state switching method and device and electronic system
CN113590277A
Message processing method and device, communication equipment and storage medium
CN115866017A
