CROSS REFERENCE TO THE RELATED APPLICATIONS

This application is based upon and claims priority to Chinese Patent Application No. 202010840396.6, filed on Aug. 20, 2020, the entire contents of which are incorporated herein by reference.

TECHNICAL FIELD

The present invention relates to the technical field of transaction processing, and more particularly, to a distributed transaction processing method and system based on a message queue and a database.

BACKGROUND

As the smallest working unit of a database operation, a transaction is a series of operations executed by a single logical unit of work (LUW). A distributed transaction means that a transaction participant, a transaction supporting server, a resource server, and a transaction manager are located on different nodes in different distributed systems, respectively. However, Java database connectivity (JDBC) can only ensure that transactions in an identical database are valid in codes of an identical system, and cannot guarantee the consistency of transactions between different databases or different systems.

Although related technologies such as an XA two-phase commit scheme, a try-confirm-cancel (TCC) scheme, a best-effort-notify (BEN) scheme, and a reliable-message eventual consistency scheme can solve the above-mentioned transaction consistency problem, there are some issues in these technologies. Specifically, the XA two-phase commit scheme has poor performance. Implementation of code logic of the TCC scheme is complicated. The BEN scheme is applied to a single scenario, and can only be applied to a business with low sensitivity to time of eventual consistency. The reliable-message eventual consistency scheme needs to use a specific message queue RocketMq, which limits selection of a message queue.

Therefore, a message queue—based eventual consistency scheme is widely used to solve the transaction consistency problem. The message queue—based eventual consistency scheme, however, has poor usability, and is difficult to be quickly deployed in different distributed systems.

SUMMARY

In order to solve the above problems, the present invention provides a distributed transaction processing method and system based on a message queue and a database, which can generate a target compressed package for deploying a distributed transaction processing component according to configuration information of different business request servers and business execution servers. In this way, the business request server and the business execution server can separately deploy the distributed transaction processing component and a related function based on the target compressed package, thereby improving usability and deployment efficiency of a distributed transaction processing scheme based on a message queue and a database.

A first aspect of the embodiments of the present invention provides a distributed transaction processing method based on a message queue and a database, applied to a distributed transaction processing system. The distributed transaction processing system includes a component encapsulation server, a business request server, and a business execution server. The business request server and the business execution server communicate with each other through the message queue. The component encapsulation server communicates with the business request server and the business execution server, respectively. The method includes:

obtaining first configuration information of the business request server and second configuration information of the business execution server by the component encapsulation server, where the first configuration information includes data source information of the business request server and first parameter information of a transaction manager in the business request server, and the second configuration information includes second parameter information of a transaction processor in the business execution server;

generating a target compressed package by the component encapsulation server according to the first configuration information and the second configuration information, and sending the target compressed package to the business request server and the business execution server, respectively;

decompressing and configuring the target compressed package by the business request server, generating a transaction processing component, and importing prestored user information to the transaction processing component;

decompressing and configuring the target compressed package by the business execution server, and establishing a message transmission path between the transaction processor and the message queue;

creating a user record in the transaction processing component by the business request server according to a received user request, generating a transaction message according to the user record, and sending the transaction message to the message queue, where the transaction processing component includes the database for storing the user record; and

extracting the transaction message by the business execution server from the message queue through the message transmission path, and processing the transaction message through the transaction manager.

Optionally, the step of generating the target compressed package by the component encapsulation server according to the first configuration information and the second configuration information includes:

determining a matching path between the data source information and the first parameter information, where the matching path includes a call path of target information in the data source information called by the transaction manager in a process of creating a transaction publishing table;

extracting node attribute information and a node association identifier of each path node in the matching path, where the node attribute information is used to represent an address of storage space of a path node, and the association identifier is used to represent a hierarchical relationship between path nodes;

generating a script file of a distributed transaction processing component according to the node attribute information and the node association identifier, and adding a first device label of the business request server to the script file to obtain a target script file;

constructing an information list of the second parameter information of the transaction processor, and determining a plurality of pieces of business thread information corresponding to the information list; concatenating character strings corresponding to each piece of business thread information based on an interface parameter of a data interface to obtain a path parameter of the data interface; and packaging the path parameter to obtain a path installation package of the transaction processor, and adding a second device label of the business execution server to the path installation package; and

compressing the target script file and the path installation package to obtain the target compressed package.

Optionally, the step of decompressing and configuring the target compressed package by the business request server, and generating the transaction processing component includes:

obtaining the script file from the target compressed package, and running the script file to generate the transaction processing component for storing the data source information and the first parameter information.

Optionally, the step of decompressing and configuring the target compressed package by the business execution server, and establishing the message transmission path between the transaction processor and the message queue includes:

decompressing the path installation package to obtain the path parameter;

configuring a handler-type full path of each piece of theme information corresponding to the message queue according to the path parameter; and

establishing the message transmission path between the transaction processor and the message queue according to the handler-type full path and a path matching rate of each piece of business thread information, where the message transmission path supports transmission of different types of transaction messages.

Optionally, the step of creating the user record in the transaction processing component by the business request server according to the received user request, and generating the transaction message according to the user record includes:

creating a user record with a first state in a transaction publishing table of the transaction processing component; and

obtaining payload information for recording transaction content of the user request from the database of the transaction processing component, and determining the payload information as the transaction message.

Optionally, after the step of sending the transaction message to the message queue, the method further includes:

modifying the user record from the first state to a second state, where the first state is used to represent that the user record is newly created or is not published, and the second state is used to represent that the user record has been published.

Optionally, the step of processing the transaction message through the transaction manager includes:

processing the transaction message based on a transaction processing table in the transaction manager, and labeling a processing record corresponding to the transaction message in the transaction processing table.

A second aspect of the embodiments of the present invention provides a distributed transaction processing system based on a message queue and a database, including a component encapsulation server, a business request server, and a business execution server. The business request server and the business execution server communicate with each other through the message queue. The component encapsulation server communicates with the business request server and the business execution server, respectively.

The component encapsulation server is configured to obtain first configuration information of the business request server and second configuration information of the business execution server, where the first configuration information includes data source information of the business request server and first parameter information of a transaction manager in the business request server, and the second configuration information includes second parameter information of a transaction processor in the business execution server.

The component encapsulation server is configured to generate a target compressed package according to the first configuration information and the second configuration information, and send the target compressed package to the business request server and the business execution server, respectively.

The business request server is configured to decompress and configure the target compressed package, generate a transaction processing component, and import prestored user information to the transaction processing component.

The business execution server is configured to decompress and configure the target compressed package, and establish a message transmission path between the transaction processor and the message queue.

The business request server is configured to create a user record in the transaction processing component according to a received user request, generate a transaction message according to the user record, and send the transaction message to the message queue, where the transaction processing component includes the database for storing the user record.

The business execution server is configured to extract the transaction message from the message queue through the message transmission path, and process the transaction message through the transaction manager.

Optionally, the component encapsulation server, through following steps, generates the target compressed package according to the first configuration information and the second configuration information:

determining a matching path between the data source information and the first parameter information, where the matching path includes a call path of target information in the data source information called by the transaction manager in a process of creating a transaction publishing table;

extracting node attribute information and a node association identifier of each path node in the matching path, where the node attribute information is used to represent an address of storage space of a path node, and the association identifier is used to represent a hierarchical relationship between path nodes;

generating a script file of a distributed transaction processing component according to the node attribute information and the node association identifier, and adding a first device label of the business request server to the script file to obtain a target script file;

constructing an information list of the second parameter information of the transaction processor, and determining a plurality of pieces of business thread information corresponding to the information list; concatenating character strings corresponding to each piece of business thread information based on an interface parameter of a data interface to obtain a path parameter of the data interface; and packaging the path parameter to obtain a path installation package of the transaction processor, and adding a second device label of the business execution server to the path installation package; and

compressing the target script file and the path installation package to obtain the target compressed package.

Optionally,

the business request server, through following steps, decompresses and configures the target compressed package, and generates the transaction processing component:

obtaining the script file from the target compressed package, and running the script file to generate the transaction processing component for storing the data source information and the first parameter information; and

the business execution server, through following steps, decompresses and configures the target compressed package, and establishes the message transmission path between the transaction processor and the message queue:

decompressing the path installation package to obtain the path parameter; configuring a handler-type full path of each piece of theme information corresponding to the message queue according to the path parameter; and establishing the message transmission path between the transaction processor and the message queue according to the handler-type full path and a path matching rate of each piece of business thread information, where the message transmission path supports transmission of different types of transaction messages.

According to the distributed transaction processing method and system based on a message queue and a database in the embodiments of the present invention, the component encapsulation server generates the target compressed package according to the obtained first configuration information of the business request server and the obtained second configuration information of the business execution server, and sends the target compressed package to the business request server and the business execution server, respectively, so that the business request server and the business execution server can decompress and configure the target compressed package to deploy the transaction processing component and the message transmission path. In this way, different business request servers and business execution servers can perform distributed transaction processing based on a message queue, thereby improving usability and deployment efficiency of a distributed transaction processing scheme based on a message queue and a database.

