Disclosure of Invention
The invention aims to provide a method and a device for online trading idempotent to solve the problems in the background technology.
In order to achieve the purpose, the invention provides the following technical scheme:
an on-line transaction idempotent method and device comprises a transaction idempotent detection table, a transaction effective detection module and a transaction idempotent control module.
As a still further scheme of the invention: the key field definition of the transaction idempotent detection table comprises field names, field types and field description definitions, wherein the field names comprise transaction codes, peripheral system IDs, transaction serial numbers, request messages, response messages and transaction processing states, and the field types comprise character strings and enumeration values.
An online idempotent trading method, comprising the steps of:
s11, in the online transaction processing system, acquiring the transaction serial number of the transaction from the request message, and inquiring a transaction idempotent check table according to the transaction serial number;
s12, whether a record of the current transaction serial number is found in the transaction power and the like check table through the transaction effective detection module, if the record of the current transaction serial number is not found, the transaction is not processed; and adopting independent transaction to register the related information of the current transaction serial number in the transaction idempotent check table;
s13, after the registration operation of the current transaction serial number is successful, the subsequent service logic is continuously processed through the transaction idempotent control module, after the processing is finished, the transaction state, the processing result and the response message are registered, and the response message is returned;
s14, after the current transaction serial number registration operation fails, judging the failure reason, if the failure reason is the 'unique index conflict' of the transaction serial number field in the transaction power and the like check table, then showing that another request for processing the same transaction serial number is concurrently sent in the system, and the subsequent processing is needed; otherwise, error reporting is needed for system exception errors;
s15, after the current transaction pipelining operation fails to be registered and the 'unique index conflict' is reported in error; inquiring the transaction idempotent check table according to the transaction serial number; for the found transaction, judging whether the transaction state is 'forward transaction' or 'checking transaction'; if yes, the record is inserted by the first processed forward transaction or the checking transaction, and the transaction failure and the original transaction are returned, or the transaction failure and the original transaction are checked; otherwise, the record is inserted by the original transaction processed first and returns to the transaction processing;
s16, searching a transaction idempotent check table in the step S11 to find a record; judging whether the transaction state is 'forward transaction' or 'checking transaction'; if yes, the record is inserted by the first processed forward transaction or the checking transaction, and the transaction failure and the original transaction are returned, or the transaction failure and the original transaction are checked; otherwise, the record is inserted by the original transaction processed first, and further identification and judgment are carried out; if the transaction state is 'processing', returning to 'transaction processing';
s17, if the original transaction state processed in the step S16 is 'reversal success', returning to 'transaction reversal'; otherwise, if the transaction is processed normally, returning to the original transaction response message.
As a still further scheme of the invention: in the step S11: any one transaction must contain a transaction serial number, and any one serial number can only correspond to one transaction, and any two different transactions must correspond to two different transaction serial numbers.
As a still further scheme of the invention: the independent transaction in the step S12 is a transaction completely independent from the business processing master transaction, and its commit or rollback operation only affects its internal operations and data, but has no effect on the master transaction.
Compared with the prior art, the invention has the beneficial effects that:
the invention sets a detection table of transaction powers, a detection module of transaction effectiveness, a control module of transaction powers and the like, correctly and efficiently processes the incidence relation of the transaction types of original transaction, forward transaction, checking transaction and the like in the financial field, and meets the requirements of transaction powers and the like; the invention can support business non-intrusive transaction idempotent, and can also realize scene specific transaction idempotent through customization of the transaction layer.
Detailed Description
The embodiment of the invention discloses a method and a device for online transaction idempotent, and the device for online transaction idempotent is characterized by comprising a transaction idempotent detection table, a transaction effective detection module and a transaction idempotent control module.
Preferably, the key field definition of the transaction idempotent detection table includes definitions of field names, field types and field descriptions, where the field names include transaction codes, peripheral system IDs, transaction serial numbers, request messages, response messages, transaction processing states, field type strings and enumeration values.
The key field definitions of the transaction idempotent look-up table are shown in the following table:
TABLE 1 Critical field description of transaction idempotent checklist
Example one
In this embodiment, the transaction sequence number is used to identify the uniqueness of the transaction, and in fig. 2, an online idempotent method comprises the following steps:
s11, in 101-in the online transaction processing system, acquiring a transaction serial number of the transaction from the request message, and inquiring a transaction idempotent check table according to the transaction serial number;
s12, in 102, through the transaction validity detection module, whether the record of the current transaction serial number is found in the transaction idempotent check table, if the record of the current transaction serial number is not found, the transaction is never processed; and adopting independent transaction to register the related information of the current transaction serial number in the transaction idempotent check table;
s13, in 103, after the registration operation of the current transaction serial number is successful, the subsequent service logic is continuously processed through the transaction idempotent control module, after the processing is finished, the transaction state, the processing result and the response message are registered, and the response message is returned;
s14, in 104, after the current transaction serial number registration operation fails, judging the failure reason, if the failure reason is 'unique index conflict' of the transaction serial number field in the transaction power and the like check table, indicating that another request for processing the same transaction serial number is concurrently sent in the system, and subsequent processing is needed; otherwise, error reporting is needed for system exception errors;
s15, at 105-after registering that the current transaction pipelining failed, error reporting "unique index conflict"; inquiring the transaction idempotent check table according to the transaction serial number; for the found transaction, judging whether the transaction state is 'forward transaction' or 'checking transaction'; if yes, the record is inserted by the first processed forward transaction or the checking transaction, and the transaction failure and the original transaction are returned, or the transaction failure and the original transaction are checked; otherwise, the record is inserted by the original transaction processed first and returns to the transaction processing;
s16, in 106, in 101 in S11, searching a transaction idempotent check table to find a record; judging whether the transaction state is 'forward transaction' or 'checking transaction'; if yes, the record is inserted by the first processed forward transaction or the checking transaction, and the transaction failure and the original transaction are returned, or the transaction failure and the original transaction are checked; otherwise, the record is inserted by the original transaction processed first, and further identification and judgment are carried out; if the transaction state is 'processing', returning to 'transaction processing';
s17, in 107, if the original transaction state processed in 106 in the step S16 is 'positive reversal success', returning to 'transaction positive reversal'; otherwise, if the transaction is processed normally, returning to the original transaction response message.
Preferably, in step S11: any one transaction must contain a transaction serial number, and any one serial number can only correspond to one transaction, and any two different transactions must correspond to two different transaction serial numbers.
Preferably, the independent transaction in step S12 is a transaction completely independent from the business processing master transaction, and its commit or rollback operation only affects its internal operations and data, but has no effect on the master transaction.
Example two
The transaction uniqueness is identified by comparing the transaction request messages, and as illustrated from the difference between fig. 3 and fig. 2, in fig. 3, the implementation method includes the following steps:
s21, in 201, when the transaction serial number is obtained from the request message, the original transaction record can not be found from the transaction idempotent check table according to the transaction serial number, which indicates that the transaction is not processed;
registering the related information of the current transaction serial number to a transaction power-like check list, wherein the operation fails, and the failure reason is judged to be 'unique index conflict'; inquiring the transaction power check table again to obtain the original transaction information, and judging whether the transaction is positive transaction or checking the insertion of the transaction; this means that the record is the original transaction insert that was processed first;
taking out the request message of the original transaction and comparing the request message with the current request message; if the two transaction serial numbers are inconsistent, the situation that one transaction serial number corresponds to two different transactions is shown, and the transaction failure is reported in error, and other same serial requests exist; if the two requests match, the transaction processing returns to the step of transaction processing, which means that the two requests correspond to the same transaction.
S22, in 202, the trade serial number is obtained from the request message, and the original trade record is found from the trade idempotent checking table according to the trade serial number. This indicates that the transaction has been processed;
acquiring original transaction information, and judging whether the transaction is a forward transaction or a check transaction insertion; this means that the record is the original transaction insert that was processed first;
taking out the request message of the original transaction and comparing the request message with the current request message; if the two transaction serial numbers are inconsistent, the situation that one transaction serial number corresponds to two different transactions is shown, and the transaction failure is reported in error, and other same serial requests exist; if the two requests are consistent, the two requests correspond to the same transaction, and further judgment and processing are needed.
It can thus be derived: compared with fig. 2 (i.e., embodiment one), fig. 3 (embodiment two) can recognize the case where "one transaction serial number corresponds to two different transactions".
EXAMPLE III
The transaction uniqueness is identified in a scene-customized manner, which is illustrated from the perspective of the difference between fig. 4 and fig. 3, in fig. 4, the implementation method includes the following steps:
s31, in 301, acquiring a transaction serial number from the request message, and according to the transaction serial number, the original transaction record cannot be found from the transaction idempotent check table; this indicates that the transaction has never been processed;
registering the related information of the current transaction serial number to a transaction power-like check list, wherein the operation fails, and the failure reason is judged to be 'unique index conflict'; and inquiring the transaction idempotent check list again to obtain the original transaction information, and judging whether the transaction is positive transaction or checking the insertion of the transaction. This means that the record is the original transaction insert that was processed first;
taking out the request message of the original transaction and comparing the request message with the current request message; if the two requests are consistent with each other, the two requests correspond to the same transaction, and the transaction is returned to the transaction processing; if the transaction request is inconsistent with the original transaction request, a customization logic is called according to the transaction scene to judge the original transaction request and the current request;
if the scene customization logic judgment result is inconsistent, returning 'transaction failure, existence of other same flow requests'; otherwise, returning to the transaction processing;
s32, in 302, acquiring a transaction serial number from the request message, and finding an original transaction record from the transaction idempotent check table according to the transaction serial number; this indicates that the transaction has been processed;
acquiring original transaction information, and judging whether the transaction is a forward transaction or a check transaction insertion; this means that the record is the original transaction insert that was processed first;
taking out the request message of the original transaction and comparing the request message with the current request message; if the two requests are consistent, the two requests correspond to the same transaction, and further judgment and processing are needed; if the transaction request is inconsistent with the original transaction request, a customization logic is called according to the transaction scene to judge the original transaction request and the current request;
if the scene customization logic judgment result is inconsistent, returning 'transaction failure, existence of other same flow requests'; otherwise, further judgment processing is required.
In fig. 5, a "transaction power-equivalent scene configuration table" needs to be set in a decision logic selection flow in a scene customization transaction power-equivalent mode, and fig. 5 mainly configures a mapping relationship from a transaction code, a peripheral system ID to a transaction power-equivalent processing class; the transaction idempotent processing class can realize different request consistency judgment logics respectively based on transaction codes, peripheral systems and other scene specific factors; for example, for the transaction code "002", the peripheral system 418535 needs to use "SceneProcessor 02" for determination, and the peripheral system "020101" needs to use "SceneProcessor 03" for determination;
in 401, according to the transaction code and the peripheral system ID obtained from the request, inquiring a transaction idempotent scene configuration table to obtain a transaction idempotent processing class; then, the original transaction request and the current request are transmitted, the instance of the processing class is called, and consistency judgment is carried out.
The selection and decision logic of the invention for three modes, namely, which mode of the first embodiment, the second embodiment and the third embodiment is used in what scene if management, selection and decision are made, needs to be explained;
first, hierarchy of trading idempotent: the hierarchy of the transaction idempotent processing mode in the invention comprises two levels: a peripheral system layer (also called a channel layer) and a transaction layer (also called a system layer);
the transaction power processing mode of the transaction layer or the system layer is set in the transaction configuration table; a processing mode of the transaction idempotent which represents the default support of the transaction; as shown in fig. 6, in addition to the three modes of the first, second and third embodiments, there is a "0-raised" mode;
the transaction idempotent processing mode of the peripheral system layer or the channel layer is set in a transaction registry; representing the processing mode adopted by a certain peripheral system when a certain transaction is called; as shown in fig. 7, a null-idempotent in the transaction configuration table option is added.
Second, strategy of trading idempotent: in terms of the priority of the transaction idempotent processing mode, the priority of a peripheral system layer is higher than that of a transaction layer; the transaction layer's processing mode will only be used when the peripheral system layer is configured as null-in an idempotent mode with transaction configuration table; as shown in fig. 8;
in fig. 8, the procedure of the selection flow of the idempotent transaction method is as follows:
in 501, acquiring a transaction code and a peripheral system ID from the transaction request, inquiring a transaction registry according to the transaction code and the peripheral system ID, and acquiring an idempotent processing mode of a peripheral system layer; judging that the peripheral system layer idempotent mode is null; if not, processing according to the idempotent mode of the peripheral system layer;
in 502, the peripheral system layer idempotent mode is null, a transaction configuration table is inquired according to a transaction code, a default idempotent processing mode of a transaction layer is obtained, and processing is carried out according to the idempotent mode of the transaction layer.
The relevant logics of forward trade clearing and transaction checking in the invention are as follows:
unlike ordinary transactions, there are two transaction serial numbers for transactions of correction and verification: the self-transaction serial number and the target transaction serial number; the idempotent logic of the self-transaction serial number conforms to the mode set forth above; the contents explained here mainly include processing of forward trade, checking trade and target trade serial number;
the processing flow of the transaction sequence number of the hedge transaction to the target transaction is shown in fig. 9;
in fig. 9, the logic flow steps for the transaction are as follows:
in 601, acquiring a target transaction serial flow from the request, and inquiring a transaction idempotent check table according to a target transaction serial number;
in 602, if the relevant information of the target transaction serial number is not found, the relevant information of the target transaction serial number is registered in the checking table for inquiring transaction idempotent, and the state is 'transaction failure, positive already';
if the registration operation is successful, returning to 'original transaction failure'; if the registration operation fails, whether the failure reason is 'unique index conflict' of the transaction power check table is judged. If not, return "system error"; if yes, the check is inquired again;
in 603-determination and processing of the status of the target transaction;
at 604-after confirming that the state of the target transaction is normal, performing traffic reversal logic;
in 605-the transaction status with the new transaction idempotent checklist is "positive successful".
Processing of the target transaction serial number by the verification transaction, as shown in FIG. 10;
in FIG. 10, the logic flow steps for verifying a transaction are as follows:
in 701-obtain the target transaction serial from the request, query the transaction idempotent look-up table according to the target transaction serial number.
In 702-if the relevant information of the target transaction serial number is not found, the relevant information of the target transaction serial number is registered to the checking table for inquiring transaction power and the like, and the state is 'transaction failure, verified';
if the registration operation is successful, returning to 'original transaction failure'; if the registration operation fails, judging whether the failure reason is 'unique index conflict' of the transaction power and other check tables; if not, return "system error"; if yes, the check is inquired again;
in 703-identification and determination of the transaction status of the target transaction.
The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art should be considered to be within the technical scope of the present invention, and the technical solutions and the inventive concepts thereof according to the present invention are equivalent to or changed within the technical scope of the present invention.