Method and device for sending message corresponding to transaction

By configuring commit messages for transactions and performing persistence and rollback operations, the problem of inconsistency between messages and business operations is solved, consistency between business operations and messages is achieved in complex transaction scenarios, and the synchronization success or failure of messages and business operations is ensured.

CN114281603BActive Publication Date: 2025-09-23中国邮政储蓄银行股份有限公司
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111645363.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-29
Publication Date
2025-09-23
Estimated Expiration
2041-12-29

AI Technical Summary

Technical Problem

In the existing technology, the problem of inconsistency between messages and services cannot be effectively solved, especially in cases where the message middleware crashes, traffic is limited, or the network fluctuates, resulting in the message being sent successfully but the business operation failing, or the message being sent failing but the business operation succeeding. The existing methods cannot guarantee the consistency of messages and services.

Method used

By configuring the first commit message for the target transaction and performing persistence operations, the transaction lifecycle is monitored to ensure that the message is sent to the message middleware after the commit is completed. In the event of a commit failure, data is rolled back to ensure that the corresponding message is deleted from the local database. Furthermore, for nested transaction scenarios, the second commit message of the sub-transaction is configured and managed independently to ensure message consistency throughout the sub-transaction lifecycle.

Benefits of technology

It achieves consistency between business operations and messages in complex transaction scenarios, ensuring that messages are sent successfully when business operations succeed, and fail synchronously when operations fail, meeting the needs of complex business scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114281603B_ABST
    Figure CN114281603B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for sending messages corresponding to transactions. The invention includes: determining a target transaction and configuring a corresponding first commit message for the target transaction; persisting the first commit message to store it in a local database; monitoring the lifecycle of the target transaction and, upon determining that the target transaction has been committed, extracting the first commit message and sending it to a message middleware; and, upon determining that the target transaction has failed to commit, controlling the data corresponding to the target transaction to perform a data rollback operation, and deleting the first commit message corresponding to the target transaction in the local database based on the data rollback operation. The present invention solves the problem of inconsistency between business data and corresponding messages due to some reasons in the related art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of control transactions, and in particular to a method and device for sending a message corresponding to a transaction. Background Art

[0002] In related technologies, there is a problem of inability to maintain consistency between messages and businesses. The main reason is that message sending is a remote communication method, and message sending objectively has unreliable characteristics. Due to the downtime, current limiting or network fluctuations of the message middleware, the message sending will fail, which will lead to inconsistency between messages and businesses. At the same time, the inconsistency is also caused by the failure to persist business data after the message is successfully sent, resulting in the phenomenon that business operations fail but the message is successfully sent.

[0003] Existing methods for sending messages resend messages based on whether the message middleware returns a successful result. While this method can guarantee message delivery success, it lacks consideration for consistency between business operations and messages, failing to meet business requirements. Consider a simulated business operation: business operation data A, business message B, and business operation data C. According to existing methods, if business message B is successfully sent but business operation data C fails, the entire business operation must fail, requiring both business operation data A and business message B to be rolled back. Existing methods are unsuitable for such scenarios. While existing methods guarantee message delivery success, they cannot guarantee consistency between messages and business operations.

[0004] At the same time, existing methods cannot solve complex nested independent transaction scenarios.

[0005] Currently, no effective solution has been proposed to the above-mentioned problems existing in the related technologies. Summary of the Invention

[0006] The main purpose of the present invention is to provide a method and device for sending a message corresponding to a transaction, so as to solve the problem in the related art that business data and the corresponding message are inconsistent due to some reasons.

[0007] In order to achieve the above-mentioned purpose, according to one aspect of the present invention, a method for sending a message corresponding to a transaction is provided. The invention comprises: determining a target transaction and configuring a corresponding first commit message for the target transaction, wherein the first commit message is used to notify at least one business system that the target transaction has been committed; performing a persistence operation on the first commit message to store the first commit message in a local database; monitoring the life cycle of the target transaction, and when it is determined that the target transaction has been committed, extracting the first commit message and sending the first commit message to a message middleware, wherein the message middleware is used to receive the first commit message and forward the first commit message to at least one business system corresponding to the target transaction; when it is determined that the target transaction has failed to commit, controlling the data corresponding to the target transaction to perform a data rollback operation, and deleting the first commit message corresponding to the target transaction in the local database based on the data rollback operation.

[0008] Furthermore, after monitoring the lifecycle of the target transaction and, upon determining that the target transaction has been committed, extracting the first commit message and sending the first commit message to the message middleware, the method further includes: periodically scanning the local database; and upon detecting that the first commit information corresponding to the target transaction is still stored in the local database, extracting the first commit message until the first commit message is successfully forwarded to the message middleware.

[0009] Furthermore, before monitoring the life cycle of the target transaction and extracting the first commit message and sending the first commit message to the message middleware when determining that the target transaction is committed, the method also includes: determining whether to start a sub-transaction corresponding to the target transaction; when determining to start the sub-transaction, configuring a corresponding second commit message for the sub-transaction, and storing the second commit message in a message temporary area corresponding to the sub-transaction, wherein the sub-transaction is a data operation transaction based on the target transaction, and the second commit message is used to characterize the completion of the sub-transaction submission; monitoring the life cycle of the sub-transaction, and when obtaining the corresponding interception action before the sub-transaction is committed, persisting the second commit information to the local database; when determining that the sub-transaction is committed, extracting the second commit message and forwarding it to the message middleware.

[0010] Furthermore, when it is determined to start the sub-transaction, before configuring a corresponding second commit message for the sub-transaction and storing the second commit message in the message temporary storage area corresponding to the sub-transaction, the method further includes: suspending the data corresponding to the target transaction and the first commit message.

[0011] Furthermore, when it is determined that the sub-transaction has been committed, after extracting the second commit message and forwarding it to the message middleware, the method includes: periodically scanning the local database; when it is found that the second commit information corresponding to the sub-transaction is still stored in the local database, extracting the second commit message and forwarding the second commit message to the message middleware.

[0012] Furthermore, the life cycle of the target transaction is monitored, and the target transaction submission is determined to be complete, including: determining whether the actions before the target transaction submission and the actions after the target transaction submission can be intercepted; and determining that the target transaction submission is complete if the actions before the submission and the actions after the submission are intercepted.

[0013] Furthermore, when it is determined that the sub-transaction fails to commit, the method includes: controlling the data corresponding to the sub-transaction to perform a data rollback operation; and deleting the second commit message corresponding to the sub-transaction in the local database based on the data rollback operation.

[0014] In order to achieve the above-mentioned purpose, according to another aspect of the present invention, a device for sending messages corresponding to a control transaction is provided. The device includes: a configuration unit, which determines the target transaction and configures a corresponding first commit message for the target transaction, wherein the first commit message is used to notify at least one business system that the target transaction has been committed; a persistence unit, which performs a persistence operation on the first commit message to store the first commit message in a local database; a determination unit, which monitors the life cycle of the target transaction and, if it is determined that the target transaction has been committed, extracts the first commit message and sends the first commit message to a message middleware, wherein the message middleware is used to receive the first commit message and forward the first commit message to at least one business system corresponding to the target transaction; a deletion unit, which, if it is determined that the target transaction has failed to commit, controls the data corresponding to the target transaction to perform a data rollback operation, and deletes the first commit message corresponding to the target transaction in the local database based on the data rollback operation.

[0015] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a computer-readable storage medium is provided, which includes a stored program, wherein the program executes the method for sending a message corresponding to any one of the above-mentioned transactions.

[0016] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a processor is provided, and the processor is used to run a program, wherein the program executes the message sending method corresponding to any one of the above-mentioned transactions.

[0017] Through the present invention, the following steps are adopted: determining the target transaction and configuring a corresponding first commit message for the target transaction, wherein the first commit message is used to notify at least one business system that the target transaction has been committed; performing a persistence operation on the first commit message to store the first commit message in a local database; monitoring the life cycle of the target transaction, and when it is determined that the target transaction has been committed, extracting the first commit message and sending the first commit message to the message middleware, wherein the message middleware is used to receive the first commit message and forward the first commit message to at least one business system corresponding to the target transaction; when it is determined that the target transaction has failed to commit, controlling the data corresponding to the target transaction to perform a data rollback operation, and deleting the first commit message corresponding to the target transaction in the local database based on the data rollback operation, thereby solving the problem in the related art that the business data and the corresponding messages are inconsistent due to some reasons, thereby achieving consistency between the business operation and the corresponding message, that is, the business operation failure message also fails synchronously, and the business operation success message is also sent successfully. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The accompanying drawings, which constitute part of the present invention, are provided to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are provided to explain the present invention and do not constitute an undue limitation of the present invention. In the accompanying drawings:

[0019] Figure 1 This is a process of sending a message corresponding to a transaction provided by an embodiment of the present invention. Figure 1 ;

[0020] Figure 2 This is a process of sending a message corresponding to a transaction provided by an embodiment of the present invention. Figure 2 ;

[0021] Figure 3 This is a timing diagram of a target transaction and a sub-transaction being successfully submitted according to a method for sending a message corresponding to a transaction provided by an embodiment of the present invention;

[0022] Figure 4 This is a timing diagram of a method for sending a message corresponding to a transaction provided by an embodiment of the present invention, in which a target transaction is successfully submitted and a sub-transaction is failed to be submitted;

[0023] Figure 5 This is a timing diagram of a method for sending a message corresponding to a transaction provided by an embodiment of the present invention, in which a target transaction fails to commit and a sub-transaction succeeds to commit;

[0024] Figure 6 It is a schematic diagram of a device for sending a message corresponding to a control transaction provided according to an embodiment of the present invention. DETAILED DESCRIPTION

[0025] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments of the present invention can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0026] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described 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 making creative efforts should fall within the scope of protection of the present invention.

[0027] It should be noted that the terms "first," "second," and the like in the specification and claims of the present invention and the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate for the embodiments of the present invention described herein. In addition, the terms "including," "having," and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to these processes, methods, products, or apparatuses.

[0028] According to an embodiment of the present invention, a method for sending a message corresponding to a transaction is provided.

[0029] Figure 1 This is a flow chart of a method for sending a message corresponding to a transaction according to an embodiment of the present invention. Figure 1 .like Figure 1 As shown, the invention includes the following steps:

[0030] Step S101 : determining a target transaction and configuring a corresponding first commit message for the target transaction, wherein the first commit message is used to notify at least one business system that the target transaction has been committed.

[0031] As mentioned above, during the business operation process, some asynchronous notification messages to the outside world are generated. In this application, a corresponding commit message is configured in advance for the target transaction to be processed, that is, the first commit message corresponding to the target transaction. When the target transaction is committed, the first commit message is used to notify the business system that the target transaction has been committed. For example, in a banking scenario, when the target transaction is a withdrawal, after the withdrawal is completed, the first commit message corresponding to the target transaction is used to notify business systems such as the SMS system and the account system that the balance of the user's account has changed.

[0032] Step S102: Perform a persistence operation on the first submitted message to store the first submitted message in a local database.

[0033] As mentioned above, in this application, the first submitted message needs to be persisted, and the persisted submitted message is stored in the corresponding local database. The persisted message data and the business operation corresponding to the target transaction maintain a transaction, and the status of the message just written is to be sent.

[0034] Step S103, monitor the life cycle of the target transaction, and when it is determined that the target transaction is committed, extract the first commit message and send the first commit message to the message middleware, wherein the message middleware is used to receive the first commit message and forward the first commit message to at least one business system corresponding to the target transaction.

[0035] As mentioned above, this application provides a message-based middleware concept. By monitoring the lifecycle of a target transaction, the message status is modified to successfully sent based on the receipt received. Based on the receipt of successful delivery, the submitted message from the local database is forwarded to the message-based middleware. If no receipt is received after a configured period of time, a timed retransmission is enabled to forward the message to the middleware until it succeeds. Success is terminated when the message expiration time has expired, at which point the message will no longer be resubmitted. This solution can maximize the guarantee of successful message delivery to the message-based middleware.

[0036] Step S104 : when it is determined that the target transaction fails to commit, the data corresponding to the target transaction is controlled to be rolled back, and the first commit message corresponding to the target transaction in the local database is deleted based on the data rollback operation.

[0037] As mentioned above, when the target transaction fails to commit, the corresponding data is rolled back. Based on the rollback operation, the first commit message corresponding to the target transaction in the local database is deleted to avoid the error of successfully sending the message when the transaction fails to commit. For example, in an optional scenario, the target transaction is a withdrawal. If the withdrawal operation fails, the corresponding commit message is deleted based on the rollback data, and the persistent data corresponding to the target transaction is also deleted.

[0038] Through the above method, this application solves the problem of consistency between business data and corresponding message sending, eliminates the coupling problem between business data and corresponding message consistency, and is unaware of the consistency between message sending and business operations during business use. It is suitable for complex transactions in business scenarios, so that the transaction characteristics ensure consistency between messages and business data, and support complex transaction scenarios in business operations.

[0039] In an optional instance, after monitoring the lifecycle of the target transaction and, upon determining that the target transaction is committed, extracting the first commit message and sending the first commit message to the message middleware, the method further includes: periodically scanning the local database; and upon detecting that the first commit information corresponding to the target transaction is still stored in the local database, extracting the first commit message until the first commit message is successfully forwarded to the message middleware.

[0040] Specifically, after the target transaction is successfully committed, the corresponding commit message is forwarded to the message middleware. However, due to the downtime, current limiting or network fluctuations of the message middleware itself, the message sending may fail. At this time, the transaction life and message sending will be inconsistent. At the same time, the inconsistency may also occur because the business data persistence fails after the message is successfully sent, resulting in the failure of business operations while the message is successfully sent.

[0041] In an optional embodiment provided by the present application, a timed scan of the local database is set to obtain the success of the corresponding transaction. The local database is periodically scanned to determine whether the first submission information corresponding to the target transaction is still stored in the local database. If it is still present, the first submission message corresponding to the target transaction is forwarded to the message middleware again, and the above steps are repeated until the first submission information corresponding to the target transaction is no longer in the local database. Preferably, the specific scanning period can be set according to different business requirements. For example, in a banking scenario, the target transaction is a withdrawal. After the withdrawal is successful, the local database is scanned every 10 seconds to determine whether the submission information corresponding to the withdrawal is still present in the local database. If it is still present, the corresponding message is extracted and forwarded to the message middleware until it is successful, and the scan ends.

[0042] In an optional instance, before monitoring the lifecycle of the target transaction and extracting the first commit message and sending the first commit message to the message middleware when determining that the target transaction is committed, the method also includes: determining whether to start a sub-transaction corresponding to the target transaction; when determining to start the sub-transaction, configuring a corresponding second commit message for the sub-transaction, and storing the second commit message in a message temporary area corresponding to the sub-transaction, wherein the sub-transaction is a data operation transaction based on the target transaction, and the second commit message is used to characterize the completion of the sub-transaction submission; monitoring the lifecycle of the sub-transaction, and when obtaining the corresponding interception action before the sub-transaction submission, persisting the second commit information to the local database; when determining that the sub-transaction submission is completed, extracting the second commit message and forwarding it to the message middleware.

[0043] As described above, the present application provides a message sending method for nested transactions. When determining whether the sub-transaction corresponding to the target transaction is opened, a corresponding second commit message is configured for the sub-transaction, wherein the second commit message exists independently from the first commit message and does not interfere with each other. At the same time, the second commit message is stored in a message temporary storage area corresponding to the sub-transaction, wherein the message temporary storage area is a memory area where the program runs and exists relatively independently.

[0044] Monitor the life cycle of the sub-transaction. When the corresponding action before the sub-transaction is committed is intercepted, the second commit information is persisted to the local database. After the sub-transaction is committed, the second commit message stored in the local database and persisted is sent to the message middleware.

[0045] For example, in a banking scenario, the target transaction can be a withdrawal, and the sub-transaction corresponding to the withdrawal is the logging operation of the withdrawal. Regardless of whether the withdrawal operation succeeds or fails, the logging operation is unaffected and relatively independent of the withdrawal operation. A commit message is configured for the log, and after the log is completed, the commit message is forwarded to the message middleware.

[0046] In an optional example, when it is determined to start a sub-transaction, a corresponding second commit message is configured for the sub-transaction, and before the second commit message is stored in a message temporary area corresponding to the sub-transaction, the method further includes: suspending the data corresponding to the target transaction and the first commit message.

[0047] As described above, after determining to start the sub-transaction, the data corresponding to the target transaction and the first commit message are suspended to provide an operating space for the sub-transaction operation.

[0048] In an optional instance, when it is determined that the sub-transaction is committed, after extracting the second commit message and forwarding it to the message middleware, the method includes: periodically scanning the local database; when it is found that the second commit information corresponding to the sub-transaction is still stored in the local database, extracting the second commit message and forwarding the second commit message to the message middleware.

[0049] As described above, the local database is scanned periodically to determine whether the second commit information corresponding to the sub-transaction is still stored in the local database. If it is still stored, the second commit message corresponding to the sub-transaction is forwarded to the message middleware again, and the above steps are repeated until the second commit information corresponding to the sub-transaction is no longer in the local database. Preferably, the specific scanning period can be set according to different business requirements.

[0050] In an optional example, monitoring the lifecycle of a target transaction and determining whether the target transaction is committed successfully include: determining whether actions before and after the target transaction is committed can be intercepted; and determining whether the target transaction is committed successfully if the actions before and after the target transaction are intercepted.

[0051] As described above, in the embodiment provided in the present application, whether the target transaction is successfully submitted is determined by intercepting the actions before and after the target transaction is submitted. If both actions are intercepted successfully, it is determined that the target transaction is successfully submitted. If only the actions before submission are intercepted and there are no actions after submission, it is determined that the target transaction has failed to submit. If both actions are not intercepted successfully, it is determined that the target transaction has failed to submit.

[0052] It should be noted that during the operation of nested transactions, the determination method for whether the sub-transaction is committed is the same as that for the main transaction (target transaction).

[0053] In an optional example, when it is determined that the subtransaction commit fails, the method includes: controlling the data corresponding to the subtransaction to perform a data rollback operation; and deleting the second commit message corresponding to the subtransaction in the local database based on the data rollback operation.

[0054] As described above, when a sub-transaction fails to commit, a data rollback operation is performed on the corresponding data, and the second commit message corresponding to the sub-transaction in the local database is deleted.

[0055] Through the above method, an independent transaction is opened in the processing of nested transactions. The user of the message is unaware, that is, the user does not need to pay attention to the consistency guarantee of business operation data and messages. It is no different from the conventional way of sending messages. It only needs to configure whether a consistent sending method needs to be used, and the internal interception method is used to persist and send messages. Business operations do not need to pay attention to when to persist and when to send. The consistency of the message follows the current transaction of the business operation and keeps the data consistent with the current transaction of the business operation. It meets the needs of complex business operation scenarios, and can correctly follow the transaction to meet the message consistency in scenarios such as opening independent transactions. This application details how to keep the sending of messages consistent with the data of business operations. This is especially important for some sensitive data, and supports complex business scenarios such as how to ensure data consistency in the case of nested transactions, meet the needs of nested transactions, and support the semantics of nested transactions.

[0056] In an optional embodiment provided in this application, as Figure 2 As shown, Figure 2 This is a process of sending a message corresponding to a service provided by an embodiment of the present invention. Figure 2According to this method, the commit message corresponding to the transaction can be successfully sent to the message middleware to the greatest extent possible.

[0057] In an optional embodiment provided in the present application, a section interception mechanism is used in combination with spring transaction management, timed scheduling, and transaction processing to perform operations such as caching, persistence, sending to the submission message middleware, and timed resubmission of submission messages.

[0058] Depending on the complexity of the transaction, there are the following types of processing:

[0059] 1) No transaction wraparound: At this point, the commit message cannot follow the business process and the business process itself has no transaction. Depending on the configuration, there are two possible behaviors:

[0060] a. Throws an exception because this sending method is not supported.

[0061] b. Enable subtransactions, persist commit messages to the local database, and send commit messages to the commit message middleware after persistence is complete.

[0062] 2) When both the target transaction and subtransactions exist: The discussion is divided into three cases based on the success or failure of the target transaction and subtransaction submission.

[0063] Scenario 1: If Figure 3 As shown, Figure 3 The present invention is a timing diagram of a method for sending a commit message corresponding to a transaction provided by an embodiment of the present invention, in which a target transaction is successfully committed and a sub-transaction is successfully committed.

[0064] a. Both the target transaction and the subtransaction are configured with commit messages.

[0065] b. After the target transaction sends a commit message, the commit message will enter the commit message temporary storage area.

[0066] c. After the subtransaction is started, the target transaction will be suspended, and the commit message buffer of the target transaction will also be suspended.

[0067] d. After the subtransaction sends the commit message, the commit message enters the subtransaction's commit message temporary storage area. When the subtransaction is committed, the pre- and post-commit interception processing will be processed. Before the subtransaction is committed, the commit message in the commit message temporary storage area will be persisted.

[0068] e. After the sub-transaction is committed, the commit message in the commit message buffer will be sent to the commit message middleware.

[0069] f. After the subtransaction is completed, the target transaction will be resumed and the target transaction commit message buffer will be restored.

[0070] g. When the target transaction is committed, the interception processing before and after the submission will be processed. Before the target transaction is committed, the submission message in the submission message temporary storage area will be persisted.

[0071] h. After the target transaction is committed, the commit message in the commit message buffer will be sent to the commit message middleware.

[0072] like Figure 3 As shown in the figure, the temporary storage areas of the target transaction and the subtransaction are independent of each other and are not affected by each other. The commit messages will be sent consistently along with the life cycle of their respective transactions.

[0073] Scenario 2: If Figure 4 As shown, Figure 4 The present invention is a timing diagram of a method for sending a commit message corresponding to a transaction provided by an embodiment of the present invention, in which a target transaction is successfully committed and a sub-transaction is failed to be committed.

[0074] a. If an exception occurs after a subtransaction sends a commit message, the data corresponding to the subtransaction will be rolled back.

[0075] b. When rolling back, the commit message temporary storage area of ​​the sub-transaction will be cleared. At this time, the commit message of the sub-transaction is not sent or persisted.

[0076] c. The target transaction is committed normally, and the commit message sent by the target transaction can also be persisted normally and sent to the commit message middleware, maintaining consistency with the business data.

[0077] Scenario 3: If Figure 5 As shown, Figure 5 The present invention is a timing diagram of a method for sending a commit message corresponding to a transaction provided by an embodiment of the present invention, in which a target transaction fails to commit and a sub-transaction succeeds to commit.

[0078] a. The subtransaction successfully commits the transaction. When committing the transaction, the pre- and post-commit actions are intercepted and processed, and the commit message is persisted in the temporary storage area and sent to the commit message middleware.

[0079] b. After the subtransaction succeeds, the target transaction is resumed and the target transaction commit message buffer data is restored.

[0080] c. An exception occurs in the subsequent processing of the target transaction, and the data corresponding to the target transaction is rolled back. After the rollback, the data in the commit message temporary storage area is cleared. The target transaction commit message is not sent, and the data remains consistent.

[0081] An embodiment of the present invention provides a method for sending messages corresponding to a transaction, which determines a target transaction and configures a corresponding first commit message for the target transaction, wherein the first commit message is used to notify at least one business system that the target transaction has been committed; the first commit message is persisted to store the first commit message in a local database; the life cycle of the target transaction is monitored, and when it is determined that the target transaction has been committed, the first commit message is extracted and sent to a message middleware, wherein the message middleware is used to receive the first commit message and forward the first commit message to at least one business system corresponding to the target transaction; when it is determined that the target transaction has failed to commit, the data corresponding to the target transaction is controlled to perform a data rollback operation, and the first commit message corresponding to the target transaction in the local database is deleted based on the data rollback operation, thereby solving the problem in the related art that the business data and the corresponding messages are inconsistent due to some reasons, thereby achieving consistency between the business operation and the corresponding message, that is, the business operation failure message also fails synchronously, and the business operation success message is also sent successfully.

[0082] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0083] An embodiment of the present invention further provides a device for sending a message corresponding to a control transaction. It should be noted that the device for sending a message corresponding to a control transaction according to an embodiment of the present invention can be used to execute the method for sending a message corresponding to a transaction according to an embodiment of the present invention. The following describes the device for sending a message corresponding to a control transaction according to an embodiment of the present invention.

[0084] Figure 6 FIG. 1 is a schematic diagram of a device for sending a message corresponding to a control transaction according to an embodiment of the present invention. Figure 6As shown, the device includes: a configuration unit 601, which determines the target transaction and configures a corresponding first commit message for the target transaction, wherein the first commit message is used to notify at least one business system that the target transaction has been committed; a persistence unit 602, which persists the first commit message to store the first commit message in a local database; a determination unit 603, which monitors the life cycle of the target transaction, and when it is determined that the target transaction has been committed, extracts the first commit message and sends the first commit message to the message middleware, wherein the message middleware is used to receive the first commit message and forward the first commit message to at least one business system corresponding to the target transaction; a deletion unit 604, which controls the data corresponding to the target transaction to perform a data rollback operation when it is determined that the target transaction has failed to commit, and deletes the first commit message corresponding to the target transaction in the local database based on the data rollback operation.

[0085] In an optional instance, the device also includes: a first scanning unit, which monitors the life cycle of the target transaction and, when determining that the target transaction is committed, extracts the first commit message and sends the first commit message to the message middleware, and then periodically scans the local database; a first extraction unit, which, when scanning finds that the first commit information corresponding to the target transaction is still stored in the local database, extracts the first commit message until the first commit message is successfully forwarded to the message middleware.

[0086] In an optional instance, the device also includes: a second extraction unit, which monitors the life cycle of the target transaction and, when determining that the target transaction is committed, extracts the first commit message and determines whether to start a sub-transaction corresponding to the target transaction before sending the first commit message to the message middleware; a storage unit, which, when determining to start the sub-transaction, configures a corresponding second commit message for the sub-transaction and stores the second commit message in a message temporary area corresponding to the sub-transaction, wherein the sub-transaction is a data operation transaction based on the target transaction, and the second commit message is used to characterize the completion of the sub-transaction submission; a monitoring unit, which monitors the life cycle of the sub-transaction and, when obtaining the corresponding interception action before the sub-transaction is committed, persists the second commit information to a local database; a third extraction unit, which, when determining that the sub-transaction is committed, extracts the second commit message and forwards it to the message middleware.

[0087] In an optional instance, the device also includes: a suspending unit, which, when determining to start a sub-transaction, configures a corresponding second commit message for the sub-transaction, and suspends the data corresponding to the target transaction and the first commit information before storing the second commit message in a message temporary area corresponding to the sub-transaction.

[0088] In an optional instance, the device includes: a second scanning unit, which extracts a second commit message and forwards it to the message middleware when determining that the sub-transaction is committed, and then periodically scans the local database; a forwarding unit, which extracts the second commit message and forwards the second commit message to the message middleware when scanning that the second commit information corresponding to the sub-transaction is still stored in the local database.

[0089] In an optional instance, the monitoring unit includes: a first determination subunit, which determines whether the actions before and after the target transaction is committed can be intercepted; and a second determination subunit, which determines that the target transaction is committed if the actions before and after the commit are intercepted.

[0090] An embodiment of the present invention provides a device for sending messages corresponding to a control transaction, which determines a target transaction and configures a corresponding first commit message for the target transaction, wherein the first commit message is used to notify at least one business system that the target transaction has been committed; the first commit message is persisted to store the first commit message in a local database; the life cycle of the target transaction is monitored, and when it is determined that the target transaction has been committed, the first commit message is extracted and sent to a message middleware, wherein the message middleware is used to receive the first commit message and forward the first commit message to at least one business system corresponding to the target transaction; when it is determined that the target transaction has failed to commit, the data corresponding to the target transaction is controlled to perform a data rollback operation, and the first commit message corresponding to the target transaction in the local database is deleted based on the data rollback operation, thereby solving the problem in the related art that the business data and the corresponding messages are inconsistent due to some reasons, thereby achieving consistency between the business operation and the corresponding message, that is, the business operation failure message also fails synchronously, and the business operation success message is also sent successfully.

[0091] The device for sending a message corresponding to a control transaction includes a processor and a memory. The above-mentioned configuration unit 601 and the like are stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to realize corresponding functions.

[0092] The processor includes a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be configured, and kernel parameters can be adjusted to resolve inconsistencies between business data and corresponding messages due to various reasons.

[0093] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0094] An embodiment of the present invention provides a computer-readable storage medium storing a program, which, when executed by a processor, implements a method for sending a message corresponding to a transaction.

[0095] An embodiment of the present invention provides a processor, which is used to run a program, wherein the program executes a method for sending a message corresponding to a transaction when the program is running.

[0096] An embodiment of the present invention provides a device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, the following steps are implemented: determining a target transaction and configuring a corresponding first commit message for the target transaction, wherein the first commit message is used to notify at least one business system that the target transaction has been committed; persisting the first commit message to store the first commit message in a local database; monitoring the life cycle of the target transaction, and when it is determined that the target transaction has been committed, extracting the first commit message and sending the first commit message to a message middleware, wherein the message middleware is used to receive the first commit message and forward the first commit message to at least one business system corresponding to the target transaction; when it is determined that the target transaction has failed to commit, controlling the data corresponding to the target transaction to perform a data rollback operation, and deleting the first commit message corresponding to the target transaction in the local database based on the data rollback operation.

[0097] In an optional instance, after monitoring the lifecycle of the target transaction and, upon determining that the target transaction is committed, extracting the first commit message and sending the first commit message to the message middleware, the method further includes: periodically scanning the local database; and upon detecting that the first commit information corresponding to the target transaction is still stored in the local database, extracting the first commit message until the first commit message is successfully forwarded to the message middleware.

[0098] In an optional instance, before monitoring the lifecycle of the target transaction and extracting the first commit message and sending the first commit message to the message middleware when determining that the target transaction is committed, the method also includes: determining whether to start a sub-transaction corresponding to the target transaction; when determining to start the sub-transaction, configuring a corresponding second commit message for the sub-transaction, and storing the second commit message in a message temporary area corresponding to the sub-transaction, wherein the sub-transaction is a data operation transaction based on the target transaction, and the second commit message is used to characterize the completion of the sub-transaction submission; monitoring the lifecycle of the sub-transaction, and when obtaining the corresponding interception action before the sub-transaction submission, persisting the second commit information to the local database; when determining that the sub-transaction submission is completed, extracting the second commit message and forwarding it to the message middleware.

[0099] In an optional example, when it is determined to start a sub-transaction, a corresponding second commit message is configured for the sub-transaction, and before the second commit message is stored in a message temporary area corresponding to the sub-transaction, the method further includes: suspending the data corresponding to the target transaction and the first commit message.

[0100] In an optional instance, when it is determined that the sub-transaction is committed, after extracting the second commit message and forwarding it to the message middleware, the method includes: periodically scanning the local database; when it is found that the second commit information corresponding to the sub-transaction is still stored in the local database, extracting the second commit message and forwarding the second commit message to the message middleware.

[0101] In an optional example, monitoring the lifecycle of a target transaction and determining whether the target transaction is committed successfully include: determining whether actions before and after the target transaction is committed can be intercepted; and determining whether the target transaction is committed successfully if the actions before and after the target transaction are intercepted.

[0102] In an optional example, when it is determined that the subtransaction commit fails, the method includes: controlling the data corresponding to the subtransaction to perform a data rollback operation; and deleting the second commit message corresponding to the subtransaction in the local database based on the data rollback operation.

[0103] The devices in this article can be servers, PCs, PADs, mobile phones, etc.

[0104] The present invention also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialized program having the following method steps: determining a target transaction and configuring a corresponding first commit message for the target transaction, wherein the first commit message is used to notify at least one business system that the target transaction has been committed; performing a persistence operation on the first commit message to store the first commit message in a local database; monitoring the life cycle of the target transaction, and when it is determined that the target transaction has been committed, extracting the first commit message and sending the first commit message to a message middleware, wherein the message middleware is used to receive the first commit message and forward the first commit message to at least one business system corresponding to the target transaction; when it is determined that the target transaction has failed to commit, controlling the data corresponding to the target transaction to perform a data rollback operation, and deleting the first commit message corresponding to the target transaction in the local database based on the data rollback operation.

[0105] In an optional instance, after monitoring the lifecycle of the target transaction and, upon determining that the target transaction is committed, extracting the first commit message and sending the first commit message to the message middleware, the method further includes: periodically scanning the local database; and upon detecting that the first commit information corresponding to the target transaction is still stored in the local database, extracting the first commit message until the first commit message is successfully forwarded to the message middleware.

[0106] In an optional instance, before monitoring the lifecycle of the target transaction and extracting the first commit message and sending the first commit message to the message middleware when determining that the target transaction is committed, the method also includes: determining whether to start a sub-transaction corresponding to the target transaction; when determining to start the sub-transaction, configuring a corresponding second commit message for the sub-transaction, and storing the second commit message in a message temporary area corresponding to the sub-transaction, wherein the sub-transaction is a data operation transaction based on the target transaction, and the second commit message is used to characterize the completion of the sub-transaction submission; monitoring the lifecycle of the sub-transaction, and when obtaining the corresponding interception action before the sub-transaction submission, persisting the second commit information to the local database; when determining that the sub-transaction submission is completed, extracting the second commit message and forwarding it to the message middleware.

[0107] In an optional example, when it is determined to start a sub-transaction, a corresponding second commit message is configured for the sub-transaction, and before the second commit message is stored in a message temporary area corresponding to the sub-transaction, the method further includes: suspending the data corresponding to the target transaction and the first commit message.

[0108] In an optional instance, when it is determined that the sub-transaction is committed, after extracting the second commit message and forwarding it to the message middleware, the method includes: periodically scanning the local database; when it is found that the second commit information corresponding to the sub-transaction is still stored in the local database, extracting the second commit message and forwarding the second commit message to the message middleware.

[0109] In an optional example, monitoring the lifecycle of a target transaction and determining whether the target transaction is committed successfully include: determining whether actions before and after the target transaction is committed can be intercepted; and determining whether the target transaction is committed successfully if the actions before and after the target transaction are intercepted.

[0110] In an optional example, when it is determined that the subtransaction commit fails, the method includes: controlling the data corresponding to the subtransaction to perform a data rollback operation; and deleting the second commit message corresponding to the subtransaction in the local database based on the data rollback operation.

[0111] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0112] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0113] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0114] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0115] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0116] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0117] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0118] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0119] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0120] The above are merely embodiments of the present invention and are not intended to limit the present invention. It will be apparent to those skilled in the art that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention are intended to be included within the scope of the claims of the present invention.

Claims

1. A method for sending a message corresponding to a transaction, characterized in that: include: Determine a target transaction, and configure a first commit message corresponding to the target transaction, wherein the first commit message is used to notify at least one business system that the target transaction has been committed; Performing a persistence operation on the first commit message to store the first commit message in a local database; monitoring the lifecycle of the target transaction, and upon determining that the target transaction is committed, extracting the first commit message and sending the first commit message to a message middleware, wherein the message middleware is configured to receive the first commit message and forward the first commit message to at least one of the business systems corresponding to the target transaction; When it is determined that the target transaction fails to commit, controlling the data corresponding to the target transaction to perform a data rollback operation, and deleting the first commit message corresponding to the target transaction in the local database based on the data rollback operation; After monitoring the lifecycle of the target transaction and, if it is determined that the target transaction has been committed, extracting the first commit message and sending the first commit message to the message middleware, the method further includes: periodically scanning the local database; and if it is found that the first commit message corresponding to the target transaction is still stored in the local database, extracting the first commit message until the first commit message is successfully forwarded to the message middleware. Before monitoring the lifecycle of the target transaction and extracting the first commit message and sending the first commit message to the message middleware when determining that the target transaction is committed, the method further includes: determining whether to start a subtransaction corresponding to the target transaction; when determining to start the subtransaction, configuring a corresponding second commit message for the subtransaction, and storing the second commit message in a message temporary area corresponding to the subtransaction, wherein the subtransaction is a data operation transaction based on the target transaction, and the second commit message is used to indicate that the subtransaction is committed; monitoring the lifecycle of the subtransaction, and when obtaining the corresponding interception action before the subtransaction is committed, persisting the second commit message to the local database; when determining that the subtransaction is committed, extracting the second commit message and forwarding it to the message middleware.

2. The method according to claim 1, characterized in that In the case of determining to start the sub-transaction, configuring a corresponding second commit message for the sub-transaction, and storing the second commit message in a message temporary storage area corresponding to the sub-transaction, the method further includes: The data corresponding to the target transaction and the first commit message are suspended.

3. The method according to claim 1, characterized in that When it is determined that the sub-transaction is committed, after extracting the second commit message and forwarding it to the message middleware, the method includes: Periodically scanning the local database; In a case where it is found that the second commit message corresponding to the sub-transaction is still stored in the local database, the second commit message is extracted and forwarded to the message middleware.

4. The method according to claim 1, wherein Monitoring the lifecycle of the target transaction and determining whether the target transaction is committed, including: Determine whether actions before and after the target transaction is committed can be intercepted; In the case where the pre-commit action and the post-commit action are intercepted, it is determined that the target transaction is committed successfully.

5. The method according to claim 1, wherein When it is determined that the sub-transaction fails to be submitted, the method includes: Control the data corresponding to the sub-transaction to perform a data rollback operation; Based on the data rollback operation, the second commit message corresponding to the sub-transaction in the local database is deleted.

6. A device for sending a message corresponding to a control transaction, characterized in that: include: a configuration unit, determining a target transaction and configuring a first commit message corresponding to the target transaction, wherein the first commit message is used to notify at least one business system that the target transaction has been committed; a persistence unit, performing a persistence operation on the first submitted message to store the first submitted message in a local database; a determination unit that monitors the lifecycle of the target transaction and, upon determining that the target transaction is committed, extracts the first commit message and sends the first commit message to a message middleware, wherein the message middleware is configured to receive the first commit message and forward the first commit message to at least one business system corresponding to the target transaction; a deleting unit, which controls the data corresponding to the target transaction to perform a data rollback operation when determining that the target transaction fails to commit, and deletes the first commit message corresponding to the target transaction in the local database based on the data rollback operation; The apparatus further includes: a first scanning unit that monitors the lifecycle of the target transaction and, upon determining that the target transaction is committed, extracts the first commit message and sends the first commit message to the message middleware, and then periodically scans the local database; a first extraction unit that, upon detecting that the first commit message corresponding to the target transaction is still stored in the local database, extracts the first commit message until the first commit message is successfully forwarded to the message middleware; The device also includes: a second extraction unit, which monitors the life cycle of the target transaction and, if it is determined that the target transaction is committed, extracts the first commit message and determines whether to start a sub-transaction corresponding to the target transaction before sending the first commit message to the message middleware; a storage unit, which, if it is determined that the sub-transaction is started, configures a corresponding second commit message for the sub-transaction and stores the second commit message in a message temporary storage area corresponding to the sub-transaction, wherein the sub-transaction is a data operation transaction based on the target transaction, and the second commit message is used to indicate that the sub-transaction is committed; a monitoring unit, which monitors the life cycle of the sub-transaction and, when obtaining the corresponding interception action before the sub-transaction is committed, persists the second commit message to the local database; and a third extraction unit, which, if it is determined that the sub-transaction is committed, extracts the second commit message and forwards it to the message middleware.

7. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method for sending a message corresponding to a transaction as described in any one of claims 1 to 5.

8. A processor, characterized in that: The processor is used to run a program, wherein the program, when running, executes the method for sending a message corresponding to a transaction described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method and device for realizing queue message consistency and computing system

    CN109408203A

  • Transaction message processing method and device and electronic equipment

    CN109684045A

  • Distributed transaction processing method and device

    CN113760924A