A method and device for processing messages
By obtaining and using an idempotent token composed of task identifiers and timestamps, querying the cache and database to determine the status of message processing, and processing and storing it when it is not processed, the problems of repeated message consumption and memory waste are solved, and message idempotence and task order traceability are realized.
Patent Information
- Application Number
- CN201911259680.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-10
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2039-12-10
AI Technical Summary
In the prior art, the short cache time of Redis can easily lead to repeated consumption of messages, and the long cache time can easily lead to excessive memory waste, and the relationship between order number and message cannot be effectively traced.
By obtaining the idempotent token of the pending message, the token is used to query the network cache, local cache, and message database to determine whether the message is processed. If not processed, the process is performed and the message is stored. Idespicable tokens are composed of task identifiers and timestamps.
It effectively avoids repeated message consumption and excessive memory waste, realizes true message idempotence, and can trace the relationship between task orders and messages.
Smart Images

Figure CN112948138B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for processing messages. Background Art
[0002] The timeout, retransmission or confirmation mechanism used by existing message queues to ensure the reachability of messages may cause the message queue server or business party to receive duplicate messages, thus affecting the business.
[0003] Message idempotence means that even if a message is repeated multiple times, the result of consuming the repeated message multiple times by the consumer is the same as consuming it once, and multiple consumptions have no side effects on the system. Currently, the method to achieve message idempotence is to store messages in the Redis cache for a period of time. When consuming a message, if the message exists in the Redis cache, it means that the message is a duplicate message and can be discarded.
[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0005] If the Redis cache time is short, messages may be consumed repeatedly. If the Redis cache time is long, memory may be wasted excessively. In addition, the relationship between the order number and the message cannot be traced. Summary of the invention
[0006] In view of this, an embodiment of the present invention provides a method and apparatus for processing messages, which can avoid repeated consumption of messages or excessive waste of memory, achieve true message idempotence, and trace the relationship between task orders and messages.
[0007] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for processing a message is provided.
[0008] A method for processing a message according to an embodiment of the present invention includes:
[0009] Get the idempotency token for the pending message;
[0010] Using the idempotent token to query the network cache, the local cache and the message database to determine whether the pending message has been processed;
[0011] When the to-be-processed message has not been processed, the to-be-processed message is processed and stored.
[0012] Optionally, the idempotent token consists of a task identifier of the message to be processed and a corresponding timestamp; and
[0013] Get the idempotency token for the pending message, including:
[0014] Get pending messages from the message queue;
[0015] Extract the idempotency token of the pending message.
[0016] Optionally, querying a network cache, a local cache, and a message database using the idempotent token to determine whether the to-be-processed message has been processed includes:
[0017] Querying the idempotent token in the local cache;
[0018] If the idempotent token exists in the local cache, the pending message has been processed;
[0019] If the idempotent token does not exist in the local cache, setting the idempotent token as a key in the network cache;
[0020] If the setting fails, the pending message has been processed;
[0021] If the setting is successful, the idempotent token is queried in the message database to determine whether the pending message has been processed.
[0022] Optionally, querying the idempotent token in a message database to determine whether the to-be-processed message has been processed includes:
[0023] Determining whether the idempotent token is a primary key in the message database;
[0024] If yes, the pending message has been processed;
[0025] If not, the pending message is not processed.
[0026] Optionally, processing the to-be-processed message and storing the to-be-processed message includes:
[0027] Processing the message to be processed;
[0028] caching the idempotence token in the local cache; and
[0029] The to-be-processed message is stored in the message database using the idempotent token as a primary key.
[0030] To achieve the above objective, according to another aspect of an embodiment of the present invention, a device for processing a message is provided.
[0031] A message processing device according to an embodiment of the present invention includes:
[0032] The acquisition module is used to obtain the idempotent token of the message to be processed;
[0033] A query module, used to query the network cache, the local cache and the message database using the idempotent token to determine whether the pending message has been processed;
[0034] The processing module is used to process the message to be processed when the message to be processed has not been processed, and store the message to be processed.
[0035] Optionally, the idempotent token consists of a task identifier of the message to be processed and a corresponding timestamp; and
[0036] The acquisition module is also used for:
[0037] Get pending messages from the message queue;
[0038] Extract the idempotency token of the pending message.
[0039] Optionally, the query module is further used to:
[0040] Querying the idempotent token in the local cache;
[0041] If the idempotent token exists in the local cache, the pending message has been processed;
[0042] If the idempotent token does not exist in the local cache, setting the idempotent token as a key in the network cache;
[0043] If the setting fails, the pending message has been processed;
[0044] If the setting is successful, the idempotent token is queried in the message database to determine whether the pending message has been processed.
[0045] Optionally, the query module is further used to:
[0046] Determining whether the idempotent token is a primary key in the message database;
[0047] If yes, the pending message has been processed;
[0048] If not, the pending message is not processed.
[0049] Optionally, the processing module is further used for:
[0050] Processing the message to be processed;
[0051] caching the idempotence token in the local cache; and
[0052] The to-be-processed message is stored in the message database using the idempotent token as a primary key.
[0053] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device for processing messages is provided.
[0054] An electronic device for processing messages according to an embodiment of the present invention comprises: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement a method for processing messages according to an embodiment of the present invention.
[0055] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided.
[0056] A computer-readable storage medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, a method for processing a message according to an embodiment of the present invention is implemented.
[0057] An embodiment of the above invention has the following advantages or beneficial effects: because an idempotent token is adopted to obtain the pending message; the idempotent token is used to query the network cache, local cache and message database to determine whether the pending message is processed; when the pending message is not processed, the pending message is processed and stored by a technical means, so the technical problem of repeated consumption of messages or excessive waste of memory is overcome; and the technical problem of being unable to trace the relationship between task orders and messages is overcome, thereby achieving the ability to avoid repeated consumption of messages or excessive waste of memory, and realizing true message idempotence; and the technical effect of being able to trace the relationship between task orders and messages.
[0058] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0060] Figure 1 is a schematic diagram of main steps of a method for processing a message according to an embodiment of the present invention;
[0061] Figure 2 is a schematic diagram of an implementation flow of a method for processing messages according to a reference embodiment of the present invention;
[0062] Figure 3 is a schematic diagram of main modules of an apparatus for processing messages according to an embodiment of the present invention;
[0063] Figure 4 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0064] Figure 5It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0065] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0066] It should be pointed out that the embodiments of the present invention and the technical features therein may be combined with each other without conflict.
[0067] Figure 1 It is a schematic diagram of main steps of a method for processing messages according to an embodiment of the present invention.
[0068] like Figure 1 As shown, the method for processing a message in an embodiment of the present invention mainly includes the following steps:
[0069] Step S101: Obtain the idempotent token of the message to be processed.
[0070] The idempotency token is used to uniquely identify the same pending message and can be created when a pending message is generated. Due to the uniqueness of the idempotency token, the idempotency token can be used to determine whether the pending message has been processed.
[0071] In the embodiment of the present invention, step S101 may be implemented in the following manner: obtaining a to-be-processed message from a message queue; and extracting an idempotent token of the to-be-processed message.
[0072] The idempotent token can be composed of a task identifier and a timestamp. The idempotent token can be obtained by processing the task identifier and the timestamp according to specific rules. As a preferred implementation, the task identifier and the timestamp can be directly spliced into an idempotent token. The task identifier is used to identify the pending message, and the order number or task name can be used as the task identifier; the timestamp indicates the creation time of the pending message, which is used to determine the unique operation at a point in time. The idempotent token composed of the commonly used task identifier and timestamp can uniquely represent the pending message, so that the consumption pending message can be easily queried during the consumption process or subsequent tracing process.
[0073] In the method for processing messages in the embodiment of the present invention, the message to be processed comes from a message queue. Before processing the message to be processed, the idempotent token of the message to be processed is first extracted. A message queue is a container for storing messages during the transmission of messages, such as MQ (an application-to-application communication method), Kafka (a high-throughput distributed publish-subscribe messaging system), etc.
[0074] Step S102: Use the idempotent token to query the network cache, local cache and message database to determine whether the pending message has been processed.
[0075] The method for processing messages in the embodiment of the present invention adopts a three-layer mechanism of double caching combined with a message database, that is, if the idempotent token of a message to be processed exists in one of the storage structures, it means that the message to be processed has been processed, thereby ensuring the uniqueness constraint on the message to be processed. Although the cache time of the network cache and the local cache is short, most of the repeated processing can be blocked. The message database serves as the last line of defense for the uniqueness constraint, and stores all processed messages to be processed.
[0076] Specifically, the idempotence token can be queried in the network cache and local cache first. If the idempotence token is not found, the idempotence token can be queried in the message database. If the idempotence token exists in the network cache, local cache or message database, the pending message has been processed. If the idempotence token does not exist in the network cache, local cache and message database, the pending message has not been processed.
[0077] In an embodiment of the present invention, step S102 can be implemented in the following manner: query the idempotent token in the local cache; if the idempotent token exists in the local cache, the pending message has been processed; if the idempotent token does not exist in the local cache, the idempotent token is set as the key in the network cache; if the setting fails, the pending message has been processed; if the setting is successful, query the idempotent token in the message database to determine whether the pending message has been processed.
[0078] The local cache can be EhCache, which is used to temporarily store the idempotent tokens of the processed pending messages. If the idempotent token of a pending message exists in the local cache, it means that the pending message has just been processed. EhCache is a pure Java in-process distributed cache framework with the characteristics of fast and efficient.
[0079] The network cache can be Redis, Jimdb, or a database based on Redis. The network cache is not only used as a cache, but also introduces a lock mechanism (that is, setting the idempotent token as a key), that is, the idempotent token can be set as a key through the setnx command. Whether the idempotent token can be set as a key determines whether the pending message is processed. Among them, Redis is an open source network-supported, memory-based, and persistent log-type, key-value database. Jimdb is a distributed, redis-based, memory-based, and persistent log-type, Key-Value database. The setnx command is used to set certain string values in a Redis key (if the key does not exist in Redis).
[0080] In an embodiment of the present invention, the step of querying the idempotent token in the message database to determine whether the pending message has been processed can be implemented in the following manner: determine whether the idempotent token is the primary key in the message database; if so, the pending message has been processed; if not, the pending message has not been processed.
[0081] The message database can be a Key-Value database such as Hbase. As the last line of defense for uniqueness constraints, the message database stores the message body of the pending message (i.e., the complete pending message) so that the processed message corresponding to the task order can be obtained according to the task identifier. In the message database, all processed pending messages are stored in the form of idempotent tokens as primary keys and pending messages as values. Therefore, if the idempotent token of a pending message is the primary key in the message database, the pending message has been processed. Hbase is a distributed, column-oriented open source database.
[0082] Step S103: When the message to be processed has not been processed, the message to be processed is processed and stored.
[0083] When there is no idempotent token in the network cache, local cache, and message database, it means that the pending message has not been processed. In this case, the pending message needs to be processed and stored after processing, so that when the pending message is received again, it can be determined that it has been processed and will not be processed again.
[0084] In an embodiment of the present invention, step S103 may be implemented in the following manner: processing the message to be processed; caching the idempotent token in a local cache; and storing the message to be processed in a message database using the idempotent token as a primary key.
[0085] For pending messages that have been processed, two methods can be used for storage at the same time. One is to store only idempotent tokens in the local cache to reduce the storage space occupied by messages while meeting the need to query whether to process new pending messages repeatedly. The other is to store pending messages in the message database with idempotent tokens as primary keys, so that the relationship between task orders and messages can be traced later.
[0086] It can be seen from the method for processing messages according to an embodiment of the present invention that the idempotent token of the message to be processed is obtained; the idempotent token is used to query the network cache, the local cache and the message database to determine whether the message to be processed is processed; when the message to be processed is not processed, the message to be processed is processed and stored. Therefore, the technical problems of repeated consumption of messages or excessive waste of memory and the inability to trace the relationship between task orders and messages are overcome, thereby achieving the technical effect of avoiding repeated consumption of messages or excessive waste of memory, realizing true message idempotence and being able to trace the relationship between task orders and messages.
[0087] In order to further explain the technical idea of the present invention, the technical solution of the present invention is now described in combination with specific application scenarios.
[0088] like Figure 2 As shown, the method for processing messages in the embodiment of the present invention can be implemented with reference to the following process:
[0089] 1. The producer creates a message to be processed and sets a MessageId for the Message. The MessageId consists of the business Id (i.e., the task ID) and the timestamp when the Message was created.
[0090] 2. Send the Message to the message queue, and the MessageId is passed to the consumer (Constumer) through the message queue as an idempotent token;
[0091] 3. After receiving the message through subscription, the consumer obtains the MessageId of the message;
[0092] 4. Verify whether MessageId exists in EhCache; if it does, it means that the Message has been consumed and the process ends; otherwise, proceed to step 5;
[0093] 5. Based on the atomicity of the setnx command in Jimdb, use MessageId to set the value of the Key; if the setting fails, it means that the Message has been consumed and the process ends; if the setting is successful, proceed to step 6;
[0094] 6. Use MessageId as the primary key (RowKey) of Hbase to verify whether the Message exists. If it does exist, it means that the Message has been consumed and the process ends; otherwise, proceed to step 7;
[0095] 7. Consume Message; at the same time, Hbase stores the current Message and EhCache stores the current MessageId.
[0096] Figure 3 4 is a schematic diagram of main modules of an apparatus for processing messages according to an embodiment of the present invention.
[0097] like Figure 3 As shown, the device 300 for processing a message according to an embodiment of the present invention includes: an acquisition module 301 , a query module 302 and a processing module 303 .
[0098] in,
[0099] An acquisition module 301 is used to acquire an idempotent token of a message to be processed;
[0100] A query module 302 is used to query the network cache, the local cache and the message database using the idempotent token to determine whether the pending message has been processed;
[0101] The processing module 303 is used to process the message to be processed when the message to be processed has not been processed, and store the message to be processed.
[0102] In addition, the idempotent token consists of the task identifier of the message to be processed and the corresponding timestamp.
[0103] In the embodiment of the present invention, the acquisition module 301 may also be used for:
[0104] Get pending messages from the message queue;
[0105] Extract the idempotency token of the pending message.
[0106] In the embodiment of the present invention, the query module 302 may also be used to:
[0107] Querying the idempotent token in the local cache;
[0108] If the idempotent token exists in the local cache, the pending message has been processed;
[0109] If the idempotent token does not exist in the local cache, setting the idempotent token as a key in the network cache;
[0110] If the setting fails, the pending message has been processed;
[0111] If the setting is successful, the idempotent token is queried in the message database to determine whether the pending message has been processed.
[0112] In this embodiment of the present invention, the query module 302 may be further used to:
[0113] Determining whether the idempotent token is a primary key in the message database;
[0114] If yes, the pending message has been processed;
[0115] If not, the pending message is not processed.
[0116] In the embodiment of the present invention, the processing module 303 may also be used for:
[0117] Processing the message to be processed;
[0118] caching the idempotence token in the local cache; and
[0119] The to-be-processed message is stored in the message database using the idempotent token as a primary key.
[0120] It can be seen that the device for processing messages according to an embodiment of the present invention adopts an idempotent token for obtaining the message to be processed; uses the idempotent token to query the network cache, local cache and message database to determine whether the message to be processed is processed; when the message to be processed is not processed, the message to be processed is processed and stored. Therefore, the technical problems of repeated consumption of messages or excessive waste of memory and the inability to trace the relationship between task orders and messages are overcome, thereby achieving the technical effect of avoiding repeated consumption of messages or excessive waste of memory, realizing true message idempotence and being able to trace the relationship between task orders and messages.
[0121] Figure 4 An exemplary system architecture 400 is shown to which the method for processing messages or the apparatus for processing messages according to the embodiments of the present invention can be applied.
[0122] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, network 404 and server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0123] Users can use terminal devices 401, 402, 403 to interact with server 405 through network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0124] The terminal devices 401 , 402 , and 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0125] Server 405 may be a server that provides various services, such as a backend management server that provides support for shopping websites browsed by users using terminal devices 401, 402, and 403. The backend management server may analyze and process received data such as product information query requests, and feed back processing results (such as target push information and product information) to the terminal device.
[0126] It should be noted that the method for processing messages provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the device for processing messages is generally set in the server 405 .
[0127] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0128] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device suitable for implementing an embodiment of the present invention. Figure 5 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0129] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0130] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.
[0131] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are executed.
[0132] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer 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. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0133] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0134] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, they may be described as: a processor includes an acquisition module, a query module, and a processing module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the acquisition module may also be described as a "module for acquiring an idempotent token of a message to be processed".
[0135] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: step S101: obtaining the idempotent token of the message to be processed; step S102: using the idempotent token to query the network cache, local cache and message database to determine whether the message to be processed is processed; step S103: when the message to be processed is not processed, processing the message to be processed and storing the message to be processed.
[0136] According to the technical solution of the embodiment of the present invention, the idempotent token of the pending message is obtained; the idempotent token is used to query the network cache, the local cache and the message database to determine whether the pending message is processed; when the pending message is not processed, the pending message is processed and stored. Therefore, the technical problems of repeated consumption of messages or excessive waste of memory and the inability to trace the relationship between task orders and messages are overcome, thereby achieving the technical effect of avoiding repeated consumption of messages or excessive waste of memory, realizing true message idempotence and being able to trace the relationship between task orders and messages.
[0137] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for processing a message, characterized in that: include: Obtain an idempotent token of the message to be processed; wherein the idempotent token is composed of a task identifier of the message to be processed and a corresponding timestamp; The idempotent token is used to query the network cache, the local cache and the message database to determine whether the pending message has been processed, including: querying the idempotent token in the local cache; if the idempotent token exists in the local cache, the pending message has been processed and the process ends; if the idempotent token does not exist in the local cache, the idempotent token is set as a key in the network cache; if the setting fails, the pending message has been processed and the process ends; if the setting succeeds, the idempotent token is queried in the message database to determine whether the pending message has been processed; When the to-be-processed message has not been processed, the to-be-processed message is processed and stored.
2. The method according to claim 1, characterized in that Get the idempotency token for the pending message, including: Get pending messages from the message queue; Extract the idempotency token of the pending message.
3. The method according to claim 1, characterized in that Querying the idempotent token in the message database to determine whether the to-be-processed message has been processed includes: Determining whether the idempotent token is a primary key in the message database; If yes, the pending message has been processed; If not, the pending message is not processed.
4. The method according to claim 1, characterized in that: Processing the message to be processed and storing the message to be processed includes: Processing the message to be processed; caching the idempotence token in the local cache; and The to-be-processed message is stored in the message database using the idempotent token as a primary key.
5. A device for processing a message, characterized in that: include: An acquisition module, used to acquire an idempotent token of a message to be processed; wherein the idempotent token is composed of a task identifier of the message to be processed and a corresponding timestamp; A query module is used to query the network cache, the local cache and the message database using the idempotent token to determine whether the pending message has been processed, including: querying the idempotent token in the local cache; if the idempotent token exists in the local cache, the pending message has been processed and the process ends; if the idempotent token does not exist in the local cache, the idempotent token is set as a key in the network cache; if the setting fails, the pending message has been processed and the process ends; if the setting succeeds, the idempotent token is queried in the message database to determine whether the pending message has been processed; The processing module is used to process the message to be processed when the message to be processed has not been processed, and store the message to be processed.
6. The device according to claim 5, characterized in that as well as The acquisition module is also used for: Get pending messages from the message queue; Extract the idempotency token of the pending message.
7. The device according to claim 5, characterized in that The query module is further used for: Determining whether the idempotent token is a primary key in the message database; If yes, the pending message has been processed; If not, the pending message is not processed.
8. The device according to claim 5, characterized in that The processing module is also used for: Processing the message to be processed; Cache the idempotent token in the local cache; as well as The to-be-processed message is stored in the message database using the idempotent token as a primary key.
9. An electronic device for processing messages, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 4.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Optimization method for idempotent operation in asynchronous frame
CN107436767A
Three-way communication protocol
US20090216901A1