A distributed transaction processing method based on RabbitMQ
By adopting a RabbitMQ-based distributed transaction processing method in the RocketMQ queue and using MySQL for message sequence identification and push, the problem that the RocketMQ queue cannot be decoupled and may fall into an infinite loop is solved, and orderly push of messages and business decoupling are achieved. .
Patent Information
- Application Number
- CN201910600556.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-07-04
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2039-07-04
AI Technical Summary
Since RocketMQ queue is not open source, it cannot achieve business decoupling and may fall into an infinite loop due to message sending failure.
Using a distributed transaction processing method based on RabbitMQ, the message is inserted into MySQL for sequence identification, and the sequence identification information is obtained and sent to the RabbitMQ queue. The sequence identification information is obtained and pushed to achieve orderly push of messages and avoid endless loops.
It realizes the orderly push of messages, facilitates business decoupling, and avoids an infinite loop caused by failure to send messages.
Smart Images

Figure CN112181674B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communications, and in particular to a distributed transaction processing method based on RabbitMQ. Background Art
[0002] Currently, RocketMQ queue is often used for message push. RocketMQ queue is a message middleware with queue model, which has the characteristics of high performance, high reliability, high real-time and distribution. However, it is not open source and cannot achieve business decoupling. It is possible to fall into an infinite loop due to message sending failure.
[0003] Therefore, it is an urgent problem to design a distributed transaction processing method that can send messages accurately and orderly. Summary of the invention
[0004] The present invention provides a distributed transaction processing method based on RabbitMQ to solve the deficiencies of the prior art.
[0005] In a first aspect, the present invention provides a distributed transaction processing method based on RabbitMQ, the method comprising:
[0006] Insert the message into MySQL;
[0007] Sequence the message to obtain sequence identification information;
[0008] Send the sequence identification information to the RabbitMQ queue;
[0009] Get the sequence identification information in the RabbitMQ queue;
[0010] Push the sequence identifier information obtained from the RabbitMQ queue.
[0011] Optionally, after inserting the message into MySQL also include:
[0012] Determine the business correctness of the message. If it is correct, the message is sequenced and the sequence identification information is obtained; otherwise, the message is deleted.
[0013] Optionally, judging the business correctness of the message includes:
[0014] Get business data and previous messages;
[0015] Verify the message with the business data and previous message to determine the business correctness of the message.
[0016] Optionally, obtaining the sequence identifier information in the RabbitMQ queue further includes:
[0017] Record the sequence identification information in the RabbitMQ queue into MySQL.
[0018] Optionally, after recording the sequence identifier information in the RabbitMQ queue to MySQL, it also includes:
[0019] Determine whether the sequence identification information in the RabbitMQ queue meets the preset sequence identification. If it meets the requirements, push the sequence identification information obtained from the RabbitMQ queue; otherwise, resend it from MySQL at a scheduled time.
[0020] Optionally, the sequence identifier information obtained from the RabbitMQ queue is pushed and the following is also included:
[0021] Determine whether the push is successful. If it fails, the failed push will be refunded at a scheduled time.
[0022] Optionally, before inserting the message into MySQL also include:
[0023] Call the business interface.
[0024] In a second aspect, the present invention provides a computer device, comprising a processor, wherein the processor is used to execute a computer program stored in a memory to implement a RabbitMQ-based distributed transaction processing method as described in any one of the first aspects.
[0025] In a third aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that a processor is used to execute the computer program stored in the storage medium to implement a RabbitMQ-based distributed transaction processing method as described in any one of the first aspects.
[0026] It can be seen from the above technical scheme that the present invention provides a distributed transaction processing method based on RabbitMQ, which includes: inserting a message into MySQL; serializing the message to obtain serial identification information; sending the serial identification information to the RabbitMQ queue; obtaining the serial identification information in the RabbitMQ queue; and pushing the serial identification information obtained from the RabbitMQ queue. This method serializes the message to obtain the serial identification information, and then sends the serial identification information to the RabbitMQ queue, thereby achieving orderly push of the message, facilitating business decoupling, and not falling into an infinite loop due to message sending failure. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the technical solution of the present invention, the drawings required for use in the embodiments are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0028] Figure 1 , which is a flowchart of a distributed transaction processing method based on RabbitMQ in the first aspect provided by the present invention. DETAILED DESCRIPTION
[0029] The following is a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings in the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0030] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described again, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0031] The present invention solves the problem that the RocketMQ queue is not open source, cannot achieve business decoupling, and may fall into an infinite loop due to message sending failure. The present invention provides a distributed transaction processing method based on RabbitMQ, the method comprising: inserting a message into MySQL; performing sequence identification on the message to obtain sequence identification information; sending the sequence identification information to the RabbitMQ queue; obtaining the sequence identification information in the RabbitMQ queue; and pushing the sequence identification information obtained from the RabbitMQ queue. The method performs sequence identification on the message to obtain the sequence identification information, and then sends the sequence identification information to the RabbitMQ queue, thereby achieving orderly push of the message, facilitating business decoupling, and not falling into an infinite loop due to message sending failure.
[0032] Embodiment 1:
[0033] See also Figure 1 , is a flow chart of a distributed transaction processing method based on RabbitMQ provided by the present invention. The present invention provides a distributed transaction processing method based on RabbitMQ, the method comprising:
[0034] S101, insert the message into MySQL;
[0035] When inserting messages into MySQL, it is necessary to ensure that there are transactions in a single-machine, single-service scenario, that is, to use MySQL to operate data under the InnoDB engine.
[0036] InnoDB provides MySQL with transaction-safe (ACID compliant) tables with transaction, rollback and crash recovery capabilities, and multi-versioned concurrency control.
[0037] S102, sequence identification is performed on the message to obtain sequence identification information;
[0038] The purpose of serializing messages in MySQL is to push them out in an orderly manner.
[0039] S103, sending the sequence identification information to the RabbitMQ queue;
[0040] There is no way to ensure consistency between the sent sequence identification information and the above-mentioned single machine and single service. Therefore, it is necessary to store the message in MySQL in advance in the single machine and single service. In this way, even if a failure occurs when the sequence identification information is sent, the message can still be extracted from the database for resending.
[0041] S104, obtaining sequence identification information in the RabbitMQ queue;
[0042] S105, push the sequence identification information obtained from the RabbitMQ queue.
[0043] Optionally, after inserting the message into MySQL also include:
[0044] Determine the business correctness of the message. If it is correct, the message is sequenced and the sequence identification information is obtained; otherwise, the message is deleted.
[0045] Verifying the business correctness of messages is to ensure the order in which messages are sent;
[0046] Optionally, judging the business correctness of the message includes:
[0047] Get business data and previous messages;
[0048] Verify the message with the business data and previous message to determine the business correctness of the message.
[0049] Optionally, obtaining the sequence identifier information in the RabbitMQ queue further includes:
[0050] Record the sequence identification information in the RabbitMQ queue into MySQL.
[0051] Optionally, after recording the sequence identifier information in the RabbitMQ queue to MySQL, it also includes:
[0052] Determine whether the sequence identification information in the RabbitMQ queue meets the preset sequence identification. If it meets the requirements, push the sequence identification information obtained from the RabbitMQ queue; otherwise, resend it from MySQL at a scheduled time.
[0053] Optionally, the sequence identifier information obtained from the RabbitMQ queue is pushed and the following is also included:
[0054] Determine whether the push is successful. If it fails, the failed push will be refunded at a scheduled time.
[0055] Optionally, before inserting the message into MySQL also include:
[0056] Call the business interface.
[0057] Embodiment 2:
[0058] A RabbitMQ-based distributed transaction processing system, comprising a storage module, a sequence identification module, an information sending module, an information acquisition module and a push module, wherein:
[0059] Storage module, used to insert messages into MySQL;
[0060] A sequence identification module is used to perform sequence identification on messages to obtain sequence identification information;
[0061] Information sending module, used to send sequence identification information to the RabbitMQ queue:
[0062] Information acquisition module, used to obtain sequence identification information in the RabbitMQ queue;
[0063] The push module is used to push the sequence identification information obtained from the RabbitMQ queue.
[0064] The RabbitMQ-based distributed transaction processing system also includes a business correctness judgment module:
[0065] The business correctness judgment module is used to judge the business correctness of the message after inserting the message into MySQL. If it is correct, the message is sequenced to obtain sequence identification information; otherwise, the message is deleted.
[0066] Embodiment 3:
[0067] The present invention provides a computer device, comprising a processor, wherein the processor is used to execute a computer program stored in a memory to implement any of the RabbitMQ-based distributed transaction processing methods of the first aspect:
[0068] Insert the message into MySQL; sequence the message and obtain sequence identification information; send the sequence identification information to the RabbitMQ queue; obtain the sequence identification information in the RabbitMQ queue; push the sequence identification information obtained from the RabbitMQ queue.
[0069] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only storage memory (ROM) or a random access memory (RAM), etc. The computer processor is used to execute the computer program stored in the storage medium to implement the following method:
[0070] The present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that a processor is used to execute the computer program stored in the storage medium to implement any of the RabbitMQ-based distributed transaction processing methods as described in the first aspect:
[0071] Insert the message into MySQL; sequence the message and obtain sequence identification information; send the sequence identification information to the RabbitMQ queue; obtain the sequence identification information in the RabbitMQ queue; push the sequence identification information obtained from the RabbitMQ queue.
[0072] It can be seen from the above technical scheme that the present invention provides a distributed transaction processing method based on RabbitMQ, which includes: inserting a message into MySQL; serializing the message to obtain serial identification information; sending the serial identification information to the RabbitMQ queue; obtaining the serial identification information in the RabbitMQ queue; and pushing the serial identification information obtained from the RabbitMQ queue. This method serializes the message to obtain the serial identification information, and then sends the serial identification information to the RabbitMQ queue, thereby achieving orderly push of the message, facilitating business decoupling, and not falling into an infinite loop due to message sending failure.
[0073] The above is only a specific implementation of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the protection scope of the present invention.
Claims
1. A distributed transaction processing method based on RabbitMQ, characterized in that: The method comprises: Insert the message into MySQL; Performing sequence identification on the message to obtain sequence identification information; Sending the sequence identification information to the RabbitMQ queue; Obtain the sequence identification information in the RabbitMQ queue; Pushing the sequence identification information obtained from the RabbitMQ queue; Wherein, after inserting the message into MySQL, the method further includes: The service correctness of the message is judged. If it is correct, the message is sequenced to obtain sequence identification information; otherwise, the message is deleted.
2. The RabbitMQ-based distributed transaction processing method according to claim 1, characterized in that: Determining the business correctness of the message includes: Get business data and previous messages; The message is verified with the business data and the preceding message respectively to determine the business correctness of the message.
3. The RabbitMQ-based distributed transaction processing method according to claim 1, characterized in that: After obtaining the sequence identification information in the RabbitMQ queue, the method further includes: The sequence identification information in the RabbitMQ queue is recorded in the MySQL.
4. The RabbitMQ-based distributed transaction processing method according to claim 3, characterized in that: After recording the sequence identification information in the RabbitMQ queue into the MySQL, the method further includes: Determine whether the sequence identification information in the RabbitMQ queue meets the preset sequence identification. If so, push the sequence identification information obtained from the RabbitMQ queue; otherwise, resend it from the MySQL at a scheduled time.
5. The RabbitMQ-based distributed transaction processing method according to claim 1, characterized in that: After pushing the sequence identification information obtained from the RabbitMQ queue, the method further includes: Determine whether the push is successful. If it fails, resend the failed push at a scheduled time.
6. The RabbitMQ-based distributed transaction processing method according to claim 1, characterized in that: Before inserting the message into MySQL, the following steps are also included: Call the business interface.
7. A computer device, characterized in that: It includes a processor, which is used to execute a computer program stored in a memory to implement the RabbitMQ-based distributed transaction processing method as claimed in any one of claims 1 to 6.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: The processor is used to execute a computer program stored in a storage medium to implement a RabbitMQ-based distributed transaction processing method as described in any one of claims 1 to 6.
