CN112948138A - Method and device for processing message - Google Patents

Method and device for processing message Download PDF

Info

Publication number
CN112948138A
CN112948138A CN201911259680.8A CN201911259680A CN112948138A CN 112948138 A CN112948138 A CN 112948138A CN 201911259680 A CN201911259680 A CN 201911259680A CN 112948138 A CN112948138 A CN 112948138A
Authority
CN
China
Prior art keywords
message
processed
idempotent
token
processing
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201911259680.8A
Other languages
Chinese (zh)
Inventor
赵正威
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Wodong Tianjun Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Wodong Tianjun Information Technology Co Ltd
Priority to CN201911259680.8A priority Critical patent/CN112948138A/en
Publication of CN112948138A publication Critical patent/CN112948138A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Abstract

The invention discloses a method and a device for processing messages, and relates to the technical field of computers. One embodiment of the method comprises: obtaining an idempotent token of a message to be processed; querying a network cache, a local cache and a message database by using the idempotent token to determine whether the message to be processed is processed; and when the message to be processed is not processed, processing the message to be processed and storing the message to be processed. The implementation method can avoid the repeated consumption of the message or excessive waste of the memory, and realize the real message idempotency; and the relation between the order number and the message can be traced.

Description

Method and device for processing message
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for processing a message.
Background
The existing message queue, the timeout, retransmission or acknowledgement mechanism adopted to ensure the accessibility of the message may cause the message queue server or the service side to receive repeated messages, thereby affecting the service.
Message idempotency is the repetition of a message many times, the end of the consumer consuming the repeated message many times as a result of one consumption, and the multiple consumption has no side effect on the system. Currently, the method for implementing message idempotency is to store a message in a Redis cache for a period of time, and when a certain message is consumed, if the message exists in the Redis cache, it indicates that the message is repeated, and the message may be discarded.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
if the Redis cache time is short, the message is easily consumed repeatedly; if the Redis cache time is long, excessive memory waste is easily caused; and the relationship between the order number and the message cannot be traced.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for processing a message, which can avoid repeated consumption of the message or excessive memory waste, and implement true idempotent of the message; and the relation between the task list and the message can be traced.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method of processing a message.
The method for processing the message comprises the following steps:
obtaining an idempotent token of a message to be processed;
querying a network cache, a local cache and a message database by using the idempotent token to determine whether the message to be processed is processed;
and when the message to be processed is not processed, processing the message to be processed and storing the message to be processed.
Optionally, the idempotent token is composed of a task identifier of the message to be processed and a corresponding timestamp; and
obtaining an idempotent token for a message to be processed, comprising:
obtaining a message to be processed from a message queue;
and extracting the idempotent token of the message to be processed.
Optionally, querying a network cache, a local cache, and a message database with the idempotent token to determine whether the message to be processed is processed includes:
querying a local cache for the idempotent token;
if the idempotent token exists in the local cache, the message to be processed is processed;
if the idempotent token does not exist in the local cache, setting the idempotent token as a key in a network cache;
if the setting is failed, the message to be processed is processed;
and if the setting is successful, inquiring the idempotent token in a message database to determine whether the message to be processed is processed.
Optionally, querying the idempotent token in a message database to determine whether the message to be processed is processed includes:
judging whether the idempotent token is a primary key in the message database;
if yes, the message to be processed is processed;
if not, the message to be processed is not processed.
Optionally, processing the message to be processed and storing the message to be processed includes:
processing the message to be processed;
caching the idempotent token in the local cache; and
and storing the message to be processed in the message database by taking the idempotent token as a primary key.
To achieve the above object, according to still another aspect of an embodiment of the present invention, there is provided an apparatus for processing a message.
The device for processing the message in the embodiment of the invention comprises:
the acquisition module is used for acquiring the idempotent token of the message to be processed;
the query module is used for querying a network cache, a local cache and a message database by using the idempotent token to determine whether the message to be processed is processed;
and the processing module is used for processing the message to be processed and storing the message to be processed when the message to be processed is not processed.
Optionally, the idempotent token is composed of a task identifier of the message to be processed and a corresponding timestamp; and
the acquisition module is further configured to:
obtaining a message to be processed from a message queue;
and extracting the idempotent token of the message to be processed.
Optionally, the query module is further configured to:
querying a local cache for the idempotent token;
if the idempotent token exists in the local cache, the message to be processed is processed;
if the idempotent token does not exist in the local cache, setting the idempotent token as a key in a network cache;
if the setting is failed, the message to be processed is processed;
and if the setting is successful, inquiring the idempotent token in a message database to determine whether the message to be processed is processed.
Optionally, the query module is further configured to:
judging whether the idempotent token is a primary key in the message database;
if yes, the message to be processed is processed;
if not, the message to be processed is not processed.
Optionally, the processing module is further configured to:
processing the message to be processed;
caching the idempotent token in the local cache; and
and storing the message to be processed in the message database by taking the idempotent token as a primary key.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided an electronic device for processing a message.
An electronic device for processing a message according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement a method of processing messages of an embodiment of the present invention.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided a computer-readable storage medium.
A computer-readable storage medium of an embodiment of the present invention has stored thereon a computer program that, when executed by a processor, implements a method of processing a message of an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: because the idempotent token for acquiring the message to be processed is adopted; querying a network cache, a local cache and a message database by using the idempotent token 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 the message to be processed is stored, so that the technical means that the message is repeatedly consumed or the memory is excessively wasted is overcome; the technical problem that the relation between the task list and the message cannot be traced is solved, so that the message can be prevented from being repeatedly consumed or excessively wasted, and the real message idempotency is realized; and the technical effect of tracing the relation between the task list and the message can be achieved.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main steps of a method of processing messages according to an embodiment of the invention;
fig. 2 is a schematic diagram illustrating an implementation flow of a method for processing a message according to a reference embodiment of the present invention;
FIG. 3 is a schematic diagram of the main modules of an apparatus for processing messages according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 5 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
It should be noted that the embodiments of the present invention and the technical features of the embodiments may be combined with each other without conflict.
Fig. 1 is a schematic diagram of the main steps of a method of processing messages according to an embodiment of the invention.
As shown in fig. 1, the method for processing a message according to the embodiment of the present invention mainly includes the following steps:
step S101: and acquiring an idempotent token of the message to be processed.
Idempotent tokens, which are used to uniquely identify the same pending message, may be created when the pending message is generated. Due to the uniqueness of the idempotent token, whether the message to be processed is processed can be judged according to the idempotent token.
In the embodiment of the present invention, step S101 may be implemented in the following manner: obtaining a message to be processed from a message queue; an idempotent token for the message to be processed is extracted.
The idempotent token can be composed of a task identifier and a timestamp, the task identifier and the timestamp are processed according to a specific rule to obtain the idempotent token, and as a preferred implementation mode, the task identifier and the timestamp can be directly spliced into the idempotent token. The task identifier is used for identifying the message to be processed, and can be an order number or a task name and the like as the task identifier; the time stamp represents the creation time of the message to be processed and is used for determining the unique operation of the time point. The idempotent token consisting of the common task identifier and the time stamp can uniquely represent the message to be processed, so that the message to be processed for consumption can be simply inquired in the consumption process or the subsequent tracing process.
In the method for processing the message, the message to be processed comes from the message queue, and before the message to be processed is processed, the idempotent token of the message to be processed is extracted. A message queue is a container that holds messages during the transmission of the messages, such as MQ (an application-to-application communication method), Kafka (a high-throughput distributed publish-subscribe messaging system), and the like.
Step S102: the network cache, local cache, and message database are queried with the idempotent token to determine whether the message to be processed is processed.
The method for processing the message of the embodiment of the invention adopts a three-layer mechanism of combining double cache with a message database, namely if the idempotent token of a certain message to be processed exists in one of the storage structures, the message to be processed is represented to be processed, thereby ensuring the uniqueness constraint of the message to be processed. Although the caching time of the network cache and the local cache is short, most of the repeated processing can be blocked, and the message database is used as the last line of defense of the uniqueness constraint and stores all the processed messages to be processed.
Specifically, the token with idempotent power may be queried in the network cache and the local cache, if the token with idempotent power is not queried in the message database, if the token with idempotent power exists in the network cache, the local cache, or the message database, the message to be processed is already processed, and if the token with idempotent power does not exist in any of the network cache, the local cache, and the message database, the message to be processed is not processed.
In the embodiment of the present invention, step S102 may be implemented in the following manner: querying the idempotent token in a local cache; if the token with idempotent is in the local cache, the message to be processed is processed; if the idempotent token does not exist in the local cache, setting the idempotent token as a key in the network cache; if the setting fails, the message to be processed is processed; and if the setting is successful, querying an idempotent token in a message database to determine whether the message to be processed is processed.
The local cache may be EhCache, configured to temporarily store an idempotent token of a to-be-processed message that has been processed, and if an idempotent token of a certain to-be-processed message exists in the local cache, it indicates that the to-be-processed message has just been processed. EhCache is a pure Java in-process distributed cache framework and has the characteristics of high speed, high precision and the like.
The network cache can be Redis, Jimdb or a database based on Redis, and the like, and not only can be used as the cache, but also a locking mechanism (namely, setting the idempotent token as a key) is introduced, namely, the idempotent token can be set as the key through a setnx command, and whether the idempotent token can be set as the key is determined whether the message to be processed is processed or not. The Redis is an open-source supporting network, a log-type and Key-Value pair (Key-Value) database which can be based on a memory and can also be persistent. Jimdb is a distributed, redis-based, memory-based and persistent journaled, Key-Value database. The setnx command is used to set certain string values in the Redis key (if the key does not exist in Redis).
In this embodiment of the present invention, the idempotent token is queried in a message database to determine whether the message to be processed is processed, and the following steps may be implemented: judging whether the idempotent token is a primary key in the message database; if yes, the message to be processed is processed; if not, the message to be processed is not processed.
The message database may be a Key-Value database such as Hbase, which is used as the last line of defense of the uniqueness constraint, and stores a message body of the message to be processed (i.e., a complete message to be processed), so as to obtain the processed message corresponding to the task ticket according to the task identifier. All processed messages to be processed are stored in a message database in a mode of taking an idempotent token as a primary key and taking a message to be processed as a value, so that if the idempotent token of a certain message to be processed is the primary key in the message database, the message to be processed is processed. Hbase is a distributed, column-oriented open-ended database.
Step S103: and when the message to be processed is not processed, processing the message to be processed and storing the message to be processed.
When the idempotent token does not exist in the network cache, the local cache and the message database, the message to be processed is not processed, in this case, the message to be processed needs to be processed, and the processed message needs to be stored after being processed, so that when the message to be processed is received again, the message to be processed can be determined to be processed and not be processed repeatedly.
In the embodiment of the present invention, step S103 may be implemented by referring to the following manner: processing the message to be processed; caching the idempotent tokens in a local cache; and storing the message to be processed in a message database by taking the idempotent token as a primary key.
For the processed messages to be processed, two modes can be adopted for storage at the same time, firstly, only the idempotent tokens are stored in a local cache, and the storage space occupied by the messages is reduced under the condition of meeting the requirement of inquiring whether to process repeatedly when new messages to be processed are processed; and the other is that the messages to be processed are stored in the message database by taking the idempotent tokens as the main keys, so that the follow-up relationship between the task list and the messages can be traced.
According to the method for processing the message, the token with the idempotent power is obtained; querying a network cache, a local cache and a message database by using the idempotent token 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 the message to be processed is stored, so that the technical means that the message is repeatedly consumed or the memory is excessively wasted is overcome; the technical problem that the relation between the task list and the message cannot be traced is solved, so that the message can be prevented from being repeatedly consumed or excessively wasted, and the real message idempotency is realized; and the technical effect of tracing the relation between the task list and the message can be achieved.
In order to further illustrate the technical idea of the present invention, the technical solution of the present invention will now be described with reference to specific application scenarios.
As shown in fig. 2, the method for processing a message according to the embodiment of the present invention may be implemented by referring to the following flows:
1. a Producer (Producer) creates a Message (Message) to be processed and sets a Message Id for the Message, wherein the Message Id consists of a service Id (namely a task identifier) and a time stamp when the Message is created;
2. sending the Message to a Message queue, the Message id being an idempotent token while passing through the Message queue to the consumer (Consstumer);
3. after a consumer (Consstumer) receives a Message in a subscription mode, acquiring a Message Id of the Message;
4. verifying the presence of the MessageId in EhCache; if the Message exists, the Message is consumed, and the process is ended; otherwise, continuing to carry out the step 5;
5. setting a value for Key by using MessageId based on the atomicity characteristic of setnx command in Jimdb; if the setting is failed, the Message is consumed, and the flow is ended; if the setting is successful, continuing to carry out the step 6;
6. the presence or absence of Message is verified using MessageId as the primary key (RowKey) of Hbase. If the Message exists, the Message is consumed, and the flow is ended; otherwise, continuing to step 7;
7. consuming the Message; meanwhile, Hbase stores the current Message, and EhCache stores the current Message id.
Fig. 3 is a schematic diagram of main blocks of an apparatus for processing a message according to an embodiment of the present invention.
As shown in fig. 3, an apparatus 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.
Wherein the content of the first and second substances,
an obtaining module 301, configured to obtain an idempotent token of a message to be processed;
a query module 302, configured to query a network cache, a local cache, and a message database with the idempotent token to determine whether the message to be processed is processed;
a processing module 303, configured to process the to-be-processed message and store the to-be-processed message when the to-be-processed message is not processed.
Furthermore, the idempotent token consists of a task identification and a corresponding timestamp of the message to be processed.
In this embodiment of the present invention, the obtaining module 301 may further be configured to:
obtaining a message to be processed from a message queue;
and extracting the idempotent token of the message to be processed.
In this embodiment of the present invention, the query module 302 may further be configured to:
querying a local cache for the idempotent token;
if the idempotent token exists in the local cache, the message to be processed is processed;
if the idempotent token does not exist in the local cache, setting the idempotent token as a key in a network cache;
if the setting is failed, the message to be processed is processed;
and if the setting is successful, inquiring the idempotent token in a message database to determine whether the message to be processed is processed.
In an embodiment of the present invention, the query module 302 may be further configured to:
judging whether the idempotent token is a primary key in the message database;
if yes, the message to be processed is processed;
if not, the message to be processed is not processed.
In this embodiment of the present invention, the processing module 303 may further be configured to:
processing the message to be processed;
caching the idempotent token in the local cache; and
and storing the message to be processed in the message database by taking the idempotent token as a primary key.
According to the device for processing the message, the token with the idempotent power is obtained; querying a network cache, a local cache and a message database by using the idempotent token 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 the message to be processed is stored, so that the technical means that the message is repeatedly consumed or the memory is excessively wasted is overcome; the technical problem that the relation between the task list and the message cannot be traced is solved, so that the message can be prevented from being repeatedly consumed or excessively wasted, and the real message idempotency is realized; and the technical effect of tracing the relation between the task list and the message can be achieved.
Fig. 4 illustrates an exemplary system architecture 400 to which the method of processing a message or the apparatus for processing a message of an embodiment of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have various communication client applications installed thereon, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, and the like.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server that provides various services, such as a background management server that supports shopping websites browsed by users using the terminal devices 401, 402, and 403. The background management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (e.g., target push information and product information) to the terminal device.
It should be noted that the method for processing a message provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, a device for processing a message is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that 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 section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes an acquisition module, a query module, and a processing module. The names of these modules do not in some cases form a limitation on the module itself, for example, the obtaining module may also be described as a "module that obtains an idempotent token for a message to be processed".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: step S101: obtaining an idempotent token of a message to be processed; step S102: querying a network cache, a local cache and a message database by using the idempotent token to determine whether the message to be processed is processed; step S103: and when the message to be processed is not processed, processing the message to be processed and storing the message to be processed.
According to the technical scheme of the embodiment of the invention, the idempotent token of the message to be processed is obtained; querying a network cache, a local cache and a message database by using the idempotent token 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 the message to be processed is stored, so that the technical means that the message is repeatedly consumed or the memory is excessively wasted is overcome; the technical problem that the relation between the task list and the message cannot be traced is solved, so that the message can be prevented from being repeatedly consumed or excessively wasted, and the real message idempotency is realized; and the technical effect of tracing the relation between the task list and the message can be achieved.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (12)

1. A method of processing a message, comprising:
obtaining an idempotent token of a message to be processed;
querying a network cache, a local cache and a message database by using the idempotent token to determine whether the message to be processed is processed;
and when the message to be processed is not processed, processing the message to be processed and storing the message to be processed.
2. The method of claim 1, wherein the idempotent token consists of a task identity and a corresponding timestamp of the message to be processed; and
obtaining an idempotent token for a message to be processed, comprising:
obtaining a message to be processed from a message queue;
and extracting the idempotent token of the message to be processed.
3. The method of claim 1, wherein querying a network cache, a local cache, and a message database with the idempotent token to determine whether the message to be processed is processed comprises:
querying a local cache for the idempotent token;
if the idempotent token exists in the local cache, the message to be processed is processed;
if the idempotent token does not exist in the local cache, setting the idempotent token as a key in a network cache;
if the setting is failed, the message to be processed is processed;
and if the setting is successful, inquiring the idempotent token in a message database to determine whether the message to be processed is processed.
4. The method of claim 3, wherein querying the idempotent token in a message database to determine whether the message to be processed is processed comprises:
judging whether the idempotent token is a primary key in the message database;
if yes, the message to be processed is processed;
if not, the message to be processed is not processed.
5. The method of claim 1, wherein processing the message to be processed and storing the message to be processed comprises:
processing the message to be processed;
caching the idempotent token in the local cache; and
and storing the message to be processed in the message database by taking the idempotent token as a primary key.
6. An apparatus for processing messages, comprising:
the acquisition module is used for acquiring the idempotent token of the message to be processed;
the query module is used for querying a network cache, a local cache and a message database by using the idempotent token to determine whether the message to be processed is processed;
and the processing module is used for processing the message to be processed and storing the message to be processed when the message to be processed is not processed.
7. The apparatus of claim 6, wherein the idempotent token consists of a task identification and a corresponding timestamp of the pending message; and
the acquisition module is further configured to:
obtaining a message to be processed from a message queue;
and extracting the idempotent token of the message to be processed.
8. The apparatus of claim 6, wherein the query module is further configured to:
querying a local cache for the idempotent token;
if the idempotent token exists in the local cache, the message to be processed is processed;
if the idempotent token does not exist in the local cache, setting the idempotent token as a key in a network cache;
if the setting is failed, the message to be processed is processed;
and if the setting is successful, inquiring the idempotent token in a message database to determine whether the message to be processed is processed.
9. The apparatus of claim 8, wherein the query module is further configured to:
judging whether the idempotent token is a primary key in the message database;
if yes, the message to be processed is processed;
if not, the message to be processed is not processed.
10. The apparatus of claim 6, wherein the processing module is further configured to:
processing the message to be processed;
caching the idempotent token in the local cache; and
and storing the message to be processed in the message database by taking the idempotent token as a primary key.
11. An electronic device for processing messages, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-5.
12. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-5.
CN201911259680.8A 2019-12-10 2019-12-10 Method and device for processing message Pending CN112948138A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911259680.8A CN112948138A (en) 2019-12-10 2019-12-10 Method and device for processing message

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911259680.8A CN112948138A (en) 2019-12-10 2019-12-10 Method and device for processing message

Publications (1)

Publication Number Publication Date
CN112948138A true CN112948138A (en) 2021-06-11

Family

ID=76225586

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911259680.8A Pending CN112948138A (en) 2019-12-10 2019-12-10 Method and device for processing message

Country Status (1)

Country Link
CN (1) CN112948138A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113641519A (en) * 2021-08-17 2021-11-12 上海微盟企业发展有限公司 Service idempotent calling method, device, equipment and storage medium
CN114116260A (en) * 2021-11-29 2022-03-01 云知声智能科技股份有限公司 Message processing method, device, terminal and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113641519A (en) * 2021-08-17 2021-11-12 上海微盟企业发展有限公司 Service idempotent calling method, device, equipment and storage medium
CN114116260A (en) * 2021-11-29 2022-03-01 云知声智能科技股份有限公司 Message processing method, device, terminal and storage medium

Similar Documents

Publication Publication Date Title
CN111460129B (en) Method, device, electronic equipment and storage medium for generating identification
CN110471848B (en) Method and device for dynamically returning message
CN110706093A (en) Accounting processing method and device
CN110909022A (en) Data query method and device
CN111510466B (en) Data updating method and device for client, electronic equipment and readable medium
CN112948138A (en) Method and device for processing message
CN112685481A (en) Data processing method and device
CN111460020B (en) Method, device, electronic equipment and medium for resolving message
CN114417318A (en) Third-party page jumping method and device and electronic equipment
CN109087097B (en) Method and device for updating same identifier of chain code
CN113127561B (en) Method and device for generating service single number, electronic equipment and storage medium
CN113726885A (en) Method and device for adjusting flow quota
CN113779122A (en) Method and apparatus for exporting data
CN113742617A (en) Cache updating method and device
CN113722193A (en) Method and device for detecting page abnormity
CN113779018A (en) Data processing method and device
CN110262756B (en) Method and device for caching data
CN113132480B (en) Data transmission method, device and system
CN110858240A (en) Front-end module loading method and device
CN113766437B (en) Short message sending method and device
CN111783044B (en) Method and device for sharing login state
CN109388536B (en) Data collection method and device
CN113760965A (en) Data query method and device
CN114091044A (en) System authority management method and device
CN115705387A (en) File generation method and device, terminal equipment and computer medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination