CN117591311A - Solution for processing idempotent of mq message - Google Patents
Solution for processing idempotent of mq message Download PDFInfo
- Publication number
- CN117591311A CN117591311A CN202311558919.8A CN202311558919A CN117591311A CN 117591311 A CN117591311 A CN 117591311A CN 202311558919 A CN202311558919 A CN 202311558919A CN 117591311 A CN117591311 A CN 117591311A
- Authority
- CN
- China
- Prior art keywords
- order
- idempotent
- message
- idempotency
- data
- 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
Links
- 238000012545 processing Methods 0.000 title claims abstract description 13
- 238000000034 method Methods 0.000 abstract description 11
- 230000005540 biological transmission Effects 0.000 abstract description 10
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 238000003780 insertion Methods 0.000 description 1
- 230000037431 insertion Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/951—Indexing; Web crawling techniques
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/60—Software deployment
- G06F8/65—Updates
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/71—Version control; Configuration management
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q30/00—Commerce
- G06Q30/06—Buying, selling or leasing transactions
- G06Q30/0601—Electronic shopping [e-shopping]
- G06Q30/0633—Lists, e.g. purchase orders, compilation or processing
- G06Q30/0635—Processing of requisition or of purchase orders
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/547—Messaging middleware
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/548—Queue
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Business, Economics & Management (AREA)
- Finance (AREA)
- Computer Security & Cryptography (AREA)
- Databases & Information Systems (AREA)
- Accounting & Taxation (AREA)
- Data Mining & Analysis (AREA)
- Development Economics (AREA)
- Economics (AREA)
- Marketing (AREA)
- Strategic Management (AREA)
- General Business, Economics & Management (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a solution method for processing the idempotency of mq messages, which relates to the technical field of information transmission and comprises the following steps: s1, designing an idempotent interface or business logic; s2, ensuring idempotency of the message based on the unique identifier; s3, realizing idempotent by utilizing unique constraint of the database. In order to avoid information loss, the invention defines an idempotent interface or service logic to ensure that the same information has consistent results when being processed for a plurality of times; the method for avoiding repeated information transmission comprises the following steps: 1. judging whether the order has been processed according to the order number; 2. setting the order number in the order list as a unique index, and ensuring idempotent according to the order number when creating the order; 3. and adding a version number attribute to the service data, and comparing whether the version number of the current data is consistent with the version in the message before updating the data each time.
Description
Technical Field
The invention relates to the technical field of information transmission, in particular to a solution method for processing the idempotency of an mq message.
Background
In the service development, the situation of repeated submission is often encountered, whether the request is reinitiated due to the fact that the network problem cannot receive the request result or the situation of repeated submission is caused by jitter of the operation of the front end. The problems caused by such repeated submissions of payment systems are particularly evident in transaction systems, such as: the user clicks on the APP for submitting orders for a plurality of times, and only one order should be generated in the background; for another example: the payment request is initiated to the payment treasure, which should deduct money only once due to network problems or system BUG retries, rather than multiple retries, resulting in multiple deductions, etc.
The problems of message loss and repeated message transmission often occur in the process of message transmission, so that the problems of untimely information transmission or information interference are caused, and the accuracy and timeliness of information transmission are affected.
Disclosure of Invention
The invention aims to solve the problems that in the prior art, messages are frequently lost and repeatedly sent in the process of transmitting, so that the problems of untimely information transmission or information interference are caused, and the accuracy and timeliness of information transmission are affected.
In order to achieve the above purpose, the present invention adopts the following technical scheme:
a solution for handling the idempotency of an mq message, comprising the steps of:
s1, designing an idempotent interface or business logic;
s2, ensuring idempotency of the message based on the unique identifier;
s3, realizing idempotent by utilizing unique constraint of a database;
s4, multi-version control is carried out, a version number attribute is added to the service data, and whether the version number of the current data is consistent with the version in the message is compared before the data is updated each time.
Preferably, in S1, it is necessary for the consumer of the message queue to define an idempotent interface or business logic, ensuring that the same message results consistent when processed multiple times.
Preferably, in S2, in the order system, it is determined whether the order has been processed according to the order number.
Preferably, in S2, if a new order is made, order processing is performed; if the order number is processed, the processing result can be directly returned through the idempotent interface without the need of order processing again.
Preferably, the order numbers in the order table are set as unique indexes, and idempotent can be ensured according to the order numbers when the orders are created.
Preferably, in S4, if the version number of the current data is inconsistent with the version in the message, the update data is refused, and the version number is updated while the data is successfully updated.
Compared with the prior art, the invention has the beneficial effects that:
in order to avoid information loss, the invention defines an idempotent interface or service logic to ensure that the same information has consistent results when being processed for a plurality of times; the method for avoiding repeated information transmission comprises the following steps: 1. judging whether the order has been processed according to the order number; 2. setting the order number in the order list as a unique index, and ensuring idempotent according to the order number when creating the order; 3. and adding a version number attribute to the service data, and comparing whether the version number of the current data is consistent with the version in the message before updating the data each time.
Detailed Description
The technical solutions of the embodiments of the present invention are clearly and completely described, and it is obvious that the described embodiments are only some embodiments of the present invention, but not all embodiments.
A solution for handling the idempotency of an mq message, comprising the steps of:
s1, designing an idempotent interface or business logic;
s2, ensuring idempotency of the message based on the unique identifier;
s3, realizing idempotent by utilizing unique constraint of a database;
s4, multi-version control is carried out, a version number attribute is added to the service data, and whether the version number of the current data is consistent with the version in the message is compared before the data is updated each time.
In this embodiment, in S1, for the consumer of the message queue, it is necessary to define an idempotent interface or service logic, that is, one or more requests should have the same result for the resource itself, so as to ensure that the result is consistent when the same message is processed multiple times; the unique primary key of the database is realized mainly by utilizing the unique constraint characteristic of the primary key in the database, and generally, the unique primary key is more suitable for idempotent property during 'insertion', so that only one record with the unique primary key can exist in one table.
The unique index can avoid the addition of dirty data, and the database can throw exception when repeated data are inserted, so that the uniqueness of the data is ensured.
Still further, when idempotent is accomplished using a database unique primary key, it should be noted that the primary key is generally not an auto-added primary key in the database, but rather a distributed global ID is used as the primary key, so that global uniqueness of the ID in a distributed environment can be guaranteed.
In this embodiment, in S2, in the order system, it is determined whether the order has been processed according to the order number.
Further, in S2, if the new order is a new order, order processing is performed; if the order number is processed, the processing result can be directly returned through the idempotent interface without the need of order processing again.
When the E-commerce website is accessed, post requests are adopted for submitting orders, repeated order submission is easy to occur if the browser is directly refreshed, and the repeated order submission is not the action which the user wants to take. The PRG method is a method in which a user prevents this phenomenon. After the server processes the Post request, a response is sent to the user browser, and the user browser is instructed to immediately access another URL in a Get mode. The user browser takes the data requested by Get, and the whole process is finished. At this time, the user refreshes the current page and does not cause repeated submission of Post requests.
In this embodiment, the order number in the order table is set as the unique index, and when creating the order, idempotent can be ensured according to the order number. The calling party firstly requests a global ID from the back end when calling the interface, and requests the global ID together when requesting, wherein the Token is preferably put into the Headers, the back end needs to verify the Key Value content of the Token as a Key, the user information is used as a Value to the Redis, if the Key exists and the Value is matched, the deleting command is executed, and then the following business logic is normally executed. And if the corresponding Key or Value does not exist, returning error information of repeated execution, so as to ensure idempotent operation.
In this embodiment, in S4, if the version number of the current data is inconsistent with the version in the message, the update data is refused, and the version number is updated while the data is successfully updated. The scheme is generally applicable to a process of executing update operation, and a field can be added in the corresponding data table in advance to serve as a version identifier of current data. Thus, each time the data in the table of the database is updated, the version identifier is used as a condition, and the value is the value of the version identifier in the data to be updated last time. When updating data, the data is firstly compared with the version number, and if the data is not equal, other requests for updating the data are already provided, and the failure of updating is prompted.
The foregoing is only a preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art, who is within the scope of the present invention, should make equivalent substitutions or modifications according to the technical scheme of the present invention and the inventive concept thereof, and should be covered by the scope of the present invention.
Claims (6)
1. A solution to handling idempotency of an mq message, comprising the steps of:
s1, designing an idempotent interface or business logic;
s2, ensuring idempotency of the message based on the unique identifier;
s3, realizing idempotent by utilizing unique constraint of a database;
s4, multi-version control is carried out, a version number attribute is added to the service data, and whether the version number of the current data is consistent with the version in the message is compared before the data is updated each time.
2. A solution to handling the idempotency of an mq message according to claim 1, wherein:
in S1, it is necessary for the consumer of the message queue to define an idempotent interface or business logic to ensure that the same message results consistent when processed multiple times.
3. A solution to handling the idempotency of an mq message according to claim 1, wherein:
in S2, in the order system, it is determined whether the order has been processed according to the order number.
4. A solution to handling the idempotency of an mq message according to claim 2, wherein:
in S2, if the new order is a new order, order processing is performed; if the order number is processed, the processing result can be directly returned through the idempotent interface without the need of order processing again.
5. A solution to handling the idempotency of an mq message according to claim 1, wherein:
the order numbers in the order list are set as unique indexes, and idempotent can be ensured according to the order numbers when the order is created.
6. A solution to handling the idempotency of an mq message according to claim 1, wherein:
in S4, if the version number of the current data is inconsistent with the version in the message, the update data is refused, and the version number is updated while the data is successfully updated.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311558919.8A CN117591311A (en) | 2023-11-21 | 2023-11-21 | Solution for processing idempotent of mq message |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311558919.8A CN117591311A (en) | 2023-11-21 | 2023-11-21 | Solution for processing idempotent of mq message |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117591311A true CN117591311A (en) | 2024-02-23 |
Family
ID=89912756
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311558919.8A Pending CN117591311A (en) | 2023-11-21 | 2023-11-21 | Solution for processing idempotent of mq message |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117591311A (en) |
-
2023
- 2023-11-21 CN CN202311558919.8A patent/CN117591311A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9756469B2 (en) | System with multiple conditional commit databases | |
CN111897825A (en) | Distributed transaction processing method and device | |
EP3869434B1 (en) | Blockchain-based data processing method and apparatus, device, and medium | |
US9697042B2 (en) | Extensibility of business process and application logic | |
CN110008041B (en) | Message processing method and device | |
US11816163B2 (en) | Systems and methods for improved transactional mainframes | |
CN111400283B (en) | Data processing method, system, electronic equipment and storage medium | |
CN110866757B (en) | Overdraft prevention method and device for electronic account | |
CN117591311A (en) | Solution for processing idempotent of mq message | |
CN111367694B (en) | Event processing method, server and computer storage medium | |
CN115858668A (en) | Distributed transaction processing method, device, electronic device and storage medium | |
JP5043913B2 (en) | How to prevent data loss during data warehouse refresh | |
CN112527531A (en) | Cache processing method and system | |
US11657034B2 (en) | Data consistency in master data integration | |
US20230410212A1 (en) | Matching validation | |
CN117196632A (en) | Order data processing method and related device | |
CN116797366A (en) | Transaction processing method, device, electronic equipment and storage medium | |
CN116703517A (en) | Method, apparatus and computer readable medium for processing information | |
CN117785900A (en) | Data updating method, device, computer equipment and storage medium | |
CN117332393A (en) | Authority verification method, device, equipment and storage medium | |
CN118069299A (en) | Distributed transaction control method and related equipment | |
CN114549069A (en) | Method and device for managing user rights card | |
CN114064220A (en) | Distributed transaction processing method and device, electronic equipment and computer storage medium | |
CN116455913A (en) | Service data synchronization method and related equipment | |
CN116775772A (en) | Data processing method, device, equipment and readable storage 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 |