Disclosure of Invention
The embodiment of the application provides a multi-mode service processing method, device and equipment. The reliability of service processing is improved.
In a first aspect, an embodiment of the present application provides a method for processing a service in multiple modes, including:
Acquiring a service processing request, wherein the service processing request is used for requesting to process a first service, the first service comprises at least one first sub-service and at least one second sub-service, and the modes of the first sub-service and the second sub-service are different;
Preprocessing each first sub-service respectively, wherein the preprocessing is used for enabling the result of executing the first sub-service to be executed successfully;
if the preprocessing of the at least one first sub-service is successful, the at least one second sub-service is processed to obtain a second execution result corresponding to the at least one second sub-service;
And respectively carrying out execution processing or rollback processing on each first sub-service according to the second execution result to obtain a first execution result corresponding to each first sub-service, wherein the first execution result is the same as the second execution result.
In a possible implementation manner, according to the second execution result, executing processing or rollback processing is performed on each first sub-service, so as to obtain a corresponding first execution result of each first sub-service, where the method includes:
If the second execution result is that the execution is successful, executing the first sub-service to obtain a first execution result corresponding to each first sub-service, wherein the first execution result corresponding to each first sub-service is that the execution is successful;
if the second execution result is the execution failure, respectively carrying out rollback processing on each first sub-service to obtain a first execution result corresponding to each first sub-service, wherein the first execution result corresponding to each first sub-service is the execution failure.
In one possible implementation manner, for any one first sub-service, rollback processing is performed on the first sub-service to obtain a first execution result corresponding to the first sub-service, which includes:
And carrying out rollback processing on the preprocessing of the first sub-service to obtain a first execution result corresponding to the first sub-service, wherein the state of the first sub-service after rollback processing is the same as the state of the first sub-service before preprocessing.
In one possible implementation manner, if the second execution result is an execution failure, the method further includes:
determining a second sub-service which is subjected to service processing in the at least one second sub-service;
And performing reverse service processing on the second sub-service which is subjected to service processing.
In a possible implementation manner, the performing service on the at least one second sub-service to obtain a second execution result corresponding to the at least one second sub-service includes:
determining the execution sequence of the at least one second sub-service;
And carrying out service processing on the at least one second sub-service according to the execution sequence until each second sub-service is successfully executed, determining the second execution result as the execution success, or determining the second execution result as the execution failure until any second sub-service in the at least one second sub-service is determined to be failed to be executed.
In one possible implementation manner, for any one second sub-service, the state of the second sub-service after the anti-service processing is the same as the state of the second sub-service before the service processing is performed.
In one possible implementation, for any one of the first sub-services; preprocessing the first sub-service, including:
acquiring service parameters corresponding to the first sub-service from the service processing request;
Judging whether the service parameters meet the service requirements corresponding to the first sub-service;
And when the service parameters are determined to meet the service requirements corresponding to the first sub-service, service resources are allocated for the first sub-service, wherein the service resources are resources required by the execution processing of the first sub-service.
In a possible implementation manner, if preprocessing of any one of the at least one first sub-service fails, the method further includes:
and carrying out rollback processing on the first sub-service which is subjected to the pretreatment, wherein the state of the first sub-service after the rollback processing is the same as the state of the first sub-service before the pretreatment.
In one possible implementation, the mode of the first sub-service is an attempt-acknowledge-cancel TCC mode, and the mode of the second sub-service is a SAGA mode.
In a second aspect, an embodiment of the present application provides a multi-mode service processing apparatus, including an acquisition module, a first processing module, and a second processing module, where,
The acquisition module is used for acquiring a service processing request, wherein the service processing request is used for requesting to process a first service, the first service comprises at least one first sub-service and at least one second sub-service, and the modes of the first sub-service and the second sub-service are different;
the first processing module is used for respectively preprocessing each first sub-service, and the preprocessing is used for enabling the result of executing the first sub-service to be successful;
The second processing module is configured to perform service processing on the at least one second sub-service if the first processing module performs pretreatment on the at least one first sub-service successfully, so as to obtain a second execution result corresponding to the at least one second sub-service;
the first processing module is further configured to perform an execution process or a rollback process on each first sub-service according to the second execution result, so as to obtain a first execution result corresponding to each first sub-service, where the first execution result is the same as the second execution result.
In one possible implementation manner, the first processing module is specifically configured to:
If the second execution result is that the execution is successful, executing the first sub-service to obtain a first execution result corresponding to each first sub-service, wherein the first execution result corresponding to each first sub-service is that the execution is successful;
if the second execution result is the execution failure, respectively carrying out rollback processing on each first sub-service to obtain a first execution result corresponding to each first sub-service, wherein the first execution result corresponding to each first sub-service is the execution failure.
In one possible implementation manner, for any one of the first sub-services, the first processing module is specifically configured to:
And carrying out rollback processing on the preprocessing of the first sub-service to obtain a first execution result corresponding to the first sub-service, wherein the state of the first sub-service after rollback processing is the same as the state of the first sub-service before preprocessing.
In one possible implementation manner, if the second execution result is an execution failure, the second processing module is further configured to:
determining a second sub-service which is subjected to service processing in the at least one second sub-service;
And performing reverse service processing on the second sub-service which is subjected to service processing.
In a possible implementation manner, the second processing module is specifically configured to:
determining the execution sequence of the at least one second sub-service;
And carrying out service processing on the at least one second sub-service according to the execution sequence until each second sub-service is successfully executed, determining the second execution result as the execution success, or determining the second execution result as the execution failure until any second sub-service in the at least one second sub-service is determined to be failed to be executed.
In one possible implementation manner, for any one second sub-service, the state of the second sub-service after the anti-service processing is the same as the state of the second sub-service before the service processing is performed.
In one possible implementation manner, for any one of the first sub-services, the first processing module is specifically configured to:
acquiring service parameters corresponding to the first sub-service from the service processing request;
Judging whether the service parameters meet the service requirements corresponding to the first sub-service;
And when the service parameters are determined to meet the service requirements corresponding to the first sub-service, service resources are allocated for the first sub-service, wherein the service resources are resources required by the execution processing of the first sub-service.
In a possible implementation manner, the first processing module is further configured to, if the first processing module fails to preprocess any one of the at least one first sub-service, perform rollback processing on the first sub-service that has undergone the preprocessing, where a state of the first sub-service after performing the rollback processing is the same as a state of the first sub-service before performing the preprocessing.
In one possible implementation, the mode of the first sub-service is an attempt-acknowledge-cancel TCC mode, and the mode of the second sub-service is a SAGA mode.
In a third aspect, an embodiment of the present application provides a multi-mode service processing apparatus, including a processor and a memory;
the memory stores computer-executable instructions;
the processor executes the computer-executable instructions stored in the memory to cause the processor to perform 8
A method of multi-mode traffic handling according to any of the first aspects.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium having stored therein computer-executable instructions for implementing the multi-mode traffic processing method according to any one of the first aspects when the computer-executable instructions are executed by a processor.
In a fifth aspect, an embodiment of the present application provides a computer program product comprising a computer program which, when executed by a processor, implements the multi-mode service processing method of any one of the first aspects.
The method, the device and the equipment for processing the multi-mode service provided by the embodiment of the application can be used for preprocessing the sub-service of the TCC mode first and then processing the sub-service of the SAGA mode after the sub-service of the TCC mode is preprocessed successfully if the distributed service comprises the sub-service of the TCC mode and the sub-service of the SAGA mode. If the execution result of the sub-service in the SAGA mode is that the execution is successful, the sub-service in the TCC mode is executed, and because the sub-service in the TCC mode is preprocessed, the execution of the sub-service in the TCC mode is necessarily successful, and the consistency of service processing is further ensured. If the execution result of the sub-service in the SAGA mode is the execution failure, the sub-service in the TCC mode is carried out with rollback processing to rollback the sub-service in the TCC mode to the initial state, so that the execution service of the sub-service in the TCC mode is also the execution failure, and the consistency of service processing is further ensured.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The terms "first," "second," "third," "fourth" and the like in the description and in the claims and in the above drawings, if any, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the invention described herein may be implemented, for example, in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
For ease of understanding, concepts related to the embodiments of the present application will be described in detail first.
TCC mode includes three processes, namely, pretreatment, execution and rollback. Here, preprocessing refers to a try operation (try operation), execution processing refers to a Confirm operation (Confirm operation), and rollback processing refers to a Cancel operation (Cancel operation). Next, three kinds of processing in the TCC mode are explained, respectively.
Preprocessing-preprocessing may generally include a checking process and an allocation process of traffic resources. The checking process is used to check whether the service request meets the service requirement corresponding to the sub-service system, for example, assuming that the service request is a request to deduct the amount 1 from the account 1, the checking process may include determining whether the account 1 exists, determining whether the password of the account 1 input by the user is correct, and determining whether the current balance in the account 1 is greater than the amount 1. The allocation process of the service resources is used for allocating the resources required by the execution process for the sub-service system so as to ensure that the execution process results in successful execution. For example, assuming that the service request is a request to deduct an amount 1 from account 1, the allocation process of the service resource may include freezing the amount 1 in account 1 to ensure that the amount 1 may be successfully deducted from account 1 in a subsequent execution process.
Executing processing, namely executing processing for completing business logic processing. For example, assuming that the service request is a request to deduct the amount 1 in the account 1, performing the processing may implement deducting the amount 1 in the account 1. In TCC mode, if the pre-processing is successful, the execution process must be successful.
And rollback processing, namely, performing rollback operation (rollback operation) on the executed processing when the preprocessing or the executing processing fails, so as to cancel the executed operation and release the service resources allocated in the preprocessing stage.
SAGA mode, which is a distributed transaction realization mode based on compensation transaction, in which, the distributed business includes several sub-businesses, each of which corresponds to business process and reverse business process, wherein, the business process can also become forward business process, and the reverse business process can also become reverse compensation process. When the distributed service in SAGA mode is executed, forward service processing is sequentially executed on all sub-services, and if the forward service processing of all the sub-services is successfully executed, the distributed service execution is completed. If the forward service processing of any one of the sub-services fails to be executed, the sub-service for which the forward service processing has been performed is subjected to the reverse service processing (reverse compensation processing) so as to return the sub-service for which the forward service processing has been performed to the initial state.
The distributed service comprises a plurality of sub-services, wherein the service consistency means that the processing result of each sub-service is the same, and the processing results of the plurality of sub-services are all successful or failed in execution.
A distributed service system according to an embodiment of the present application will be described below with reference to fig. 1.
Fig. 1 is a schematic diagram of a distributed service system according to an embodiment of the present application. Referring to fig. 1, the distributed service system includes a service manager and a plurality of sub-service systems. The distributed service comprises a plurality of sub-services, and one sub-service system can be used for processing one sub-service. The service manager is used for calling and managing the sub-service systems so as to ensure that the processing results of the sub-service systems on the respective corresponding sub-services are consistent. One sub-service system can be deployed in one virtual machine, and different virtual machines can be deployed on the same physical device or on different physical devices. The service manager may be deployed on the same physical device as the sub-service system, or the service manager may be deployed on a different physical device than the sub-service system.
Optionally, if the sub-service system is in TCC mode, the sub-service system may include three interfaces, i.e., an interface for preprocessing, an interface for executing processing, and an interface for rollback processing. Accordingly, the service manager may call an interface of the sub-service system to enable the sub-service system to perform preprocessing, performing processing, or rollback processing.
Optionally, if the sub-service system is in SAGA mode, the sub-service system may include two interfaces, an interface for performing service processing and an interface for performing anti-service processing. Accordingly, the service manager may invoke an interface of the sub-service system to enable the sub-service system to perform service processing or reverse service processing.
In the related art, if the modes of the sub-service systems in the service system are different, that is, the modes of the sub-services included in the distributed service are different, the consistency of the processing results of the sub-services in the distributed service cannot be ensured, that is, the service consistency of the distributed service cannot be ensured, so that the reliability of service processing is poor.
In order to solve the above technical problems, in the embodiment of the present disclosure, if the distributed service includes a sub-service in TCC mode and a sub-service in SAGA mode, the sub-service in TCC mode may be preprocessed first, and then the sub-service in SAGA mode may be processed after the sub-service in TCC mode is preprocessed successfully. If the execution result of the sub-service in the SAGA mode is that the execution is successful, the sub-service in the TCC mode is executed, and because the sub-service in the TCC mode is preprocessed, the execution of the sub-service in the TCC mode is necessarily successful, and the consistency of service processing is further ensured. If the execution result of the sub-service in the SAGA mode is the execution failure, the sub-service in the TCC mode is carried out with rollback processing to rollback the sub-service in the TCC mode to the initial state, so that the execution service of the sub-service in the TCC mode is also the execution failure, and the consistency of service processing is further ensured.
The technical scheme shown in the application is described in detail by specific examples. The following embodiments may exist independently or in combination with each other, and for the same or similar matters, the description will not be repeated in different embodiments.
Fig. 2 is a flow chart of a multi-mode service processing method according to an embodiment of the present application. Referring to fig. 2, the method may include:
S201, acquiring a service processing request.
The execution main body of the embodiment of the application can be a distributed service system, part of the steps in the embodiment of the application can be executed by a service manager in the distributed service system, and part of the steps can be executed by a service manager calling sub-service system.
Alternatively, a service manager in a distributed service system may obtain the service processing request.
The service processing request is used for requesting to process a first service, the first service comprises at least one first sub-service and at least one second sub-service, and the modes of the first sub-service and the second sub-service are different. The mode of the first sub-service is TCC mode, and the mode of the second sub-service is SAGA mode.
The service processing request may be a service processing request from a client. For example, the service processing request may be a request to transfer a predetermined amount of money in account 1 to account 2, and assuming that the service processing request corresponds to the first service, the first service includes two sub-services, sub-service 1, in which the predetermined amount of money is deducted from account 1 and sub-service 2, in which the predetermined amount of money is deposited from account 2.
S202, preprocessing each first sub-service respectively.
Optionally, after the service manager obtains the service processing request, the service manager may call the corresponding sub-service systems respectively, so that the sub-service systems process the corresponding first sub-service.
The preprocessing is used for enabling the result of executing the processing on the first sub-service to be successful in execution, that is, if the preprocessing on the first sub-service is successful, the execution processing on the first sub-service is also necessarily successful.
The preprocessing may include a checking process and an allocation process of service resources, the checking process being configured to detect whether a service parameter in the service processing request meets a service requirement corresponding to the first sub-service. The service resource allocation process is used for dividing the service resource into service resources required when the first sub-service is executed. And if the check processing and the distribution processing of the first sub-service are successful, the first sub-service is preprocessed successfully. After the first sub-service is successfully preprocessed, the first sub-service already meets the necessary condition of successful execution, so that after the first sub-service is successfully preprocessed, the first sub-service is also successfully executed by default.
The preprocessing process of each first sub-service is the same, and in the following, the preprocessing process of any first sub-service is described, namely, the service parameters corresponding to the first sub-service are obtained in the service processing request, whether the service parameters meet the service requirements (check processing) corresponding to the first sub-service is judged, and when the service parameters are confirmed to meet the service requirements corresponding to the first sub-service, service resources are allocated to the first sub-service, wherein the service resources are resources (the allocation processing of the service resources) required by executing the processing of the first sub-service.
For example, assuming that the first sub-service is to deduct a preset amount from account 1, the service request may include account 1, the password of account 1, and the preset amount, the checking process may include checking whether account 1 exists, checking whether the password of account 1 is correct, and checking whether the amount in account 1 is greater than or equal to the preset amount. The allocation process of the service resource may include freezing a preset amount in account 1.
Optionally, the at least one first sub-service may be preprocessed in parallel, or the at least one first sub-service may be preprocessed sequentially. For example, a processing order of at least one first sub-service may be obtained, and the at least one first sub-service may be preprocessed according to the processing order.
S203, if the preprocessing of the at least one first sub-service is successful, the service processing of the at least one second sub-service is performed, and a second execution result corresponding to the at least one second sub-service is obtained.
It may be determined by the traffic manager whether the first sub-traffic was successfully pre-processed. After the service manager determines that at least one first sub-service is preprocessed, a corresponding sub-service system can be called by the service manager, so that the sub-service system performs service processing on a corresponding second sub-service.
And if the preprocessing of each first sub-service is successful, carrying out service processing on at least one second sub-service.
The second execution result corresponding to the at least one second sub-service can be obtained by determining the execution sequence of the at least one second sub-service, and performing service processing on the at least one second sub-service according to the execution sequence until each second sub-service is successfully executed, determining the second execution result as the execution success, or determining the second execution result as the execution failure until the execution failure of any second sub-service in the at least one second sub-service is determined.
For example, assuming that at least one second sub-service includes sub-service 1, sub-service 2, sub-service 3, and sub-service 4, and the 4 sub-services are executed in the order of sub-service 1, sub-service 2, sub-service 3, and sub-service 4, service processing may be sequentially performed on the 4 sub-services. And assuming that service processing is successful on all the 4 sub-services, the second execution result corresponding to the 4 sub-services is successful execution. Assuming that the sub-service 1 and the sub-service 2 are successfully processed, the sub-service 3 fails to be processed, the sub-service 4 is not processed continuously, and the second execution result is determined to be the execution failure. After determining that the execution of the second execution result fails, the sub-service 1 and the sub-service 2 may be processed in reverse so that the sub-service 1 and the sub-service 2 are returned to the initial state (state before the execution of the service), and if the sub-service 3 is also processed in part, the already processed part of the service 3 is also returned.
For any one second sub-service, the state of the second sub-service after the reverse service processing is the same as the state of the second sub-service before the service processing.
S204, executing or backing up each first sub-service according to the second executing result to obtain the corresponding first executing result of each first sub-service.
Wherein the first execution result is the same as the second execution result. The first execution result and the second execution result are successful in execution, or the first execution result and the second execution result are failed in execution.
And if the second execution result is that the execution is successful, executing the first sub-service to obtain a first execution result corresponding to each first sub-service, wherein the first execution result corresponding to each first sub-service is that the execution is successful. In this case, the first execution result and the second execution result are both successful execution.
If the second execution result is the execution failure, carrying out rollback processing on each first sub-service respectively to obtain a first execution result corresponding to each first sub-service, wherein the first execution result corresponding to each first sub-service is the execution failure. In this case, the first execution result and the second execution result are both execution failures.
The first sub-service can be rollback processed by rollback processing the preprocessing of the first sub-service to obtain a first execution result corresponding to the first sub-service, wherein the state of the first sub-service after rollback processing is the same as the state of the first sub-service before preprocessing.
In the embodiment shown in fig. 2, if the distributed service includes the sub-service in TCC mode and the sub-service in SAGA mode, the sub-service in TCC mode may be preprocessed first, and then the sub-service in SAGA mode may be preprocessed after the sub-service in TCC mode is preprocessed successfully. If the execution result of the sub-service in the SAGA mode is that the execution is successful, the sub-service in the TCC mode is executed, and because the sub-service in the TCC mode is preprocessed, the execution of the sub-service in the TCC mode is necessarily successful, and the consistency of service processing is further ensured. If the execution result of the sub-service in the SAGA mode is the execution failure, the sub-service in the TCC mode is carried out with rollback processing to rollback the sub-service in the TCC mode to the initial state, so that the execution service of the sub-service in the TCC mode is also the execution failure, and the consistency of service processing is further ensured.
On the basis of any one of the above embodiments, the following describes in detail the procedure of the above multi-mode service processing with reference to the embodiment shown in fig. 3.
Fig. 3 is a flow chart of a multi-mode service processing method according to an embodiment of the present application. Referring to fig. 3, the method may include:
s301, acquiring a service processing request.
S302, preprocessing each first sub-service respectively.
It should be noted that, the execution process of S301-S302 may refer to the execution process of S201-S202, and will not be described herein.
S303, judging whether the pretreatment of each first sub-service is successful.
If yes, S305 is executed.
If not, S304 is performed.
S304, carrying out rollback processing on the preprocessed first sub-service.
After the back-off processing is performed on the first sub-service which has been subjected to the preprocessing, the service processing is not continued on the second sub-service, and in this case, the execution result of the first sub-service and the execution result of the second sub-service are both execution failures.
S305, performing service processing on at least one second sub-service to obtain a second execution result corresponding to the at least one second sub-service.
S306, judging whether the second execution result corresponding to at least one second sub-service is successful execution.
If yes, S307 is executed.
If not, then S308 is performed.
And if the execution of each second sub-service in the at least one second sub-service is successful, determining that the second execution result is successful. If the execution of any one of the at least one second sub-service fails, determining that the second execution result is the execution failure.
It should be noted that, the execution process of S306 may refer to the execution process of S203, which is not described herein.
S307, executing processing is carried out on each first sub-service respectively, and a first executing result corresponding to each first sub-service is obtained.
If each second sub-service is successfully executed, each first sub-service is executed, and the first execution result of the execution processing of the first sub-service is that the execution is successful because the first sub-service is already preprocessed. That is, the execution results of the first sub-service and the second sub-service are successful, and the consistency of the execution results of the first sub-service and the second sub-service is ensured.
S308, determining the second sub-service which is processed in the service in the at least one second sub-service.
The second sub-service that has undergone the service processing includes a second sub-service that has completed the service processing and has executed as a result of successful execution, and a second sub-service that has completed part of the service processing and has executed as a result of failed execution.
S309, performing anti-service processing on the second sub-service which is subjected to service processing.
The anti-traffic processing refers to the process that has been performed by the second sub-traffic being withdrawn. And carrying out reverse service processing on the second sub-service, so that the state of the second sub-service can be returned to an initial state, wherein the initial state is the state before service processing.
For example, assuming that the second sub-service performs a service process of depositing a predetermined amount in account 1, the second sub-service performs an anti-service process of deducting the predetermined amount in account 1.
S310, respectively carrying out rollback processing on each first sub-service to obtain a first execution result corresponding to each first sub-service.
If the second sub-service processing fails, the rollback processing is carried out on each first sub-service respectively, so that the state of each first sub-service is rolled back to the initial state. Since only the first sub-service is preprocessed, the performing the rollback processing on the first sub-service means performing the rollback processing on the preprocessing of the first sub-service, that is, canceling the preprocessing of the first sub-service.
For example, the preprocessing of the first sub-service includes freezing a predetermined amount in account 1, and the rollback processing of the first sub-service refers to canceling the predetermined amount of the frozen account 1.
And when the second sub-service processing fails, the first sub-service is also subjected to rollback processing, so that the first execution result service corresponding to the first sub-service fails to be executed. That is, the execution result of the first sub-service and the execution result of the second sub-service are both execution failures, so that the consistency of the execution results of the first sub-service and the second sub-service is ensured.
In the embodiment shown in fig. 3, if the distributed service includes the sub-service in TCC mode and the sub-service in SAGA mode, the sub-service in TCC mode may be preprocessed first, and then the sub-service in SAGA mode may be preprocessed after the sub-service in TCC mode is preprocessed successfully. If the execution result of the sub-service in the SAGA mode is that the execution is successful, the sub-service in the TCC mode is executed, and because the sub-service in the TCC mode is preprocessed, the execution of the sub-service in the TCC mode is necessarily successful, and the consistency of service processing is further ensured. If the execution result of the sub-service in the SAGA mode is the execution failure, the sub-service in the TCC mode is carried out with rollback processing to rollback the sub-service in the TCC mode to the initial state, so that the execution service of the sub-service in the TCC mode is also the execution failure, and the consistency of service processing is further ensured.
On the basis of any one of the above embodiments, the above multi-mode service processing method will be described below by way of specific examples with reference to fig. 4 to 6.
Fig. 4 is a schematic diagram of a distributed service according to an embodiment of the present application. Referring to fig. 4, assuming that the distributed service is that a user purchases a financial product on a third party platform through an account 1, the distributed service includes 5 sub-services, wherein the 5 sub-services are respectively deducting a predetermined amount from the account 1 (sub-service 1), depositing the predetermined amount into the third party account (sub-service 2), executing a transaction process (sub-service 3), deducting the predetermined amount from the third party account (sub-service 4), and depositing the predetermined amount into the account 2 (sub-service 5). Wherein, sub-service 1, sub-service 2 and sub-service 3 are respectively in TCC mode, and sub-service 4 and sub-service 5 are respectively in SAGA mode.
The processing procedure of the distributed service shown in fig. 4 will be described with reference to fig. 5 to 6.
Fig. 5 is a schematic diagram of a processing procedure according to an embodiment of the present application. Referring to fig. 5, when the distributed service is processed, sub-service 1, sub-service 2 and sub-service 3 are preprocessed respectively. Assuming that the sub-service 1, the sub-service 2 and the sub-service 3 are all preprocessed successfully, the sub-service 4 and the sub-service 5 are processed. If the sub-service 4 and the sub-service 5 are both successfully processed, that is, the execution results of the sub-service 4 and the sub-service 5 are both successful, the sub-service 1, the sub-service 2 and the sub-service 3 are respectively processed, and the sub-service 1-sub-service 3 is preprocessed, so that the execution result of the sub-service 1-sub-service 3 is necessarily successful. Namely, the execution results of the sub-services 1-5 are all successful, and the consistency of service execution is ensured.
Fig. 6 is a schematic diagram of a processing procedure according to an embodiment of the present application. Referring to fig. 6, when the distributed service is processed, the sub-service 1, the sub-service 2 and the sub-service 3 are preprocessed respectively. Assuming that the sub-service 1, the sub-service 2 and the sub-service 3 are all preprocessed successfully, the sub-service 4 and the sub-service 5 are processed. Assuming that the sub-service 4 is successfully processed and the sub-service 5 is failed to be processed, the sub-service 4 is continuously processed in reverse so that the execution results of the sub-service 4 and the sub-service 5 are both failed to be executed. After the execution of the sub-service 4 and the sub-service 5 fails, the sub-service 1-3 are respectively processed in a rollback mode, so that the execution results of the sub-service 1-3 are all the execution failure. Namely, the execution results of the sub-services 1-5 are all successful, and the consistency of service execution is ensured.
Fig. 7 is a schematic structural diagram of a multi-mode service processing device according to an embodiment of the present application. Referring to fig. 7, the multi-mode service processing apparatus 10 may include an acquisition module 11, a first processing module 12, and a second processing module 13, wherein,
The acquiring module 11 is configured to acquire a service processing request, where the service processing request is used to request processing of a first service, and the first service includes at least one first sub-service and at least one second sub-service, where modes of the first sub-service and the second sub-service are different;
the first processing module 12 is configured to perform preprocessing on each first sub-service, where the preprocessing is used to make a result of performing processing on the first sub-service be successful in execution;
The second processing module 13 is configured to perform service processing on the at least one second sub-service if the first processing module performs pretreatment on the at least one first sub-service successfully, so as to obtain a second execution result corresponding to the at least one second sub-service;
The first processing module 12 is further configured to perform an execution process or a rollback process on each first sub-service according to the second execution result, so as to obtain a first execution result corresponding to each first sub-service, where the first execution result is the same as the second execution result.
The multi-mode service processing device provided by the embodiment of the application can execute the technical scheme shown in the embodiment of the method, and the implementation principle and the beneficial effects are similar, and are not repeated here.
In one possible implementation, the first processing module 12 is specifically configured to:
If the second execution result is that the execution is successful, executing the first sub-service to obtain a first execution result corresponding to each first sub-service, wherein the first execution result corresponding to each first sub-service is that the execution is successful;
if the second execution result is the execution failure, respectively carrying out rollback processing on each first sub-service to obtain a first execution result corresponding to each first sub-service, wherein the first execution result corresponding to each first sub-service is the execution failure.
In one possible implementation manner, for any one of the first sub-services, the first processing module 12 is specifically configured to:
And carrying out rollback processing on the preprocessing of the first sub-service to obtain a first execution result corresponding to the first sub-service, wherein the state of the first sub-service after rollback processing is the same as the state of the first sub-service before preprocessing.
In one possible implementation, if the second execution result is an execution failure, the second processing module 12 is further configured to:
determining a second sub-service which is subjected to service processing in the at least one second sub-service;
And performing reverse service processing on the second sub-service which is subjected to service processing.
In one possible embodiment, the second processing module 12 is specifically configured to:
determining the execution sequence of the at least one second sub-service;
And carrying out service processing on the at least one second sub-service according to the execution sequence until each second sub-service is successfully executed, determining the second execution result as the execution success, or determining the second execution result as the execution failure until any second sub-service in the at least one second sub-service is determined to be failed to be executed.
In one possible implementation manner, for any one second sub-service, the state of the second sub-service after the anti-service processing is the same as the state of the second sub-service before the service processing is performed.
In one possible implementation manner, for any one of the first sub-services, the first processing module 12 is specifically configured to:
acquiring service parameters corresponding to the first sub-service from the service processing request;
Judging whether the service parameters meet the service requirements corresponding to the first sub-service;
And when the service parameters are determined to meet the service requirements corresponding to the first sub-service, service resources are allocated for the first sub-service, wherein the service resources are resources required by the execution processing of the first sub-service.
In a possible implementation manner, the first processing module 12 is further configured to, if the first processing module 12 fails to perform preprocessing on any one of the at least one first sub-service, perform rollback processing on the first sub-service that has undergone the preprocessing, where a state of the first sub-service after performing rollback processing is the same as a state of the first sub-service before performing the preprocessing.
In one possible implementation, the mode of the first sub-service is an attempt-acknowledge-cancel TCC mode, and the mode of the second sub-service is a SAGA mode.
The multi-mode service processing device provided by the embodiment of the application can execute the technical scheme shown in the embodiment of the method, and the implementation principle and the beneficial effects are similar, and are not repeated here.
Fig. 8 is a schematic structural diagram of a multi-mode service processing device according to an embodiment of the present application. Referring to fig. 8, the multi-mode service processing device 20 may include a processor 21 and a memory 22. The processor 21, the memory 22, and the like are illustratively interconnected by a bus 23.
The memory 21 stores computer-executable instructions;
the processor 21 executes computer-executable instructions stored in the memory 22 such that the processor 21 performs the multi-mode traffic processing method according to any of the first aspects.
The multi-mode service processing device shown in the embodiment of fig. 8 may execute the technical solution shown in the embodiment of the method, and its implementation principle and beneficial effects are similar, and will not be described herein again.
Embodiments of the present application provide a computer readable storage medium having stored therein computer executable instructions for implementing the above-described multi-mode service processing method when the computer executable instructions are executed by a processor.
Embodiments of the present application may also provide a computer program product, including a computer program, which when executed by a processor, may implement the above-mentioned multi-mode service processing method.
All or part of the steps for implementing the method embodiments described above may be performed by hardware associated with program instructions. The foregoing program may be stored in a readable memory. The program, when executed, performs the steps comprising the method embodiments described above, and the aforementioned memory (storage medium) comprises read-only memory (ROM), RAM, flash memory, hard disk, solid state disk, magnetic tape (english: MAGNETIC TAPE), floppy disk (english: floppy disk), optical disk (english: optical disk), and any combination thereof.
Embodiments of the present application are described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processing unit of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processing unit of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various modifications and variations can be made to the embodiments of the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the embodiments of the present application fall within the scope of the claims and the equivalents thereof, the present application is also intended to include such modifications and variations.
In the present disclosure, the term "include" and variations thereof may refer to non-limiting inclusion, and the term "or" and variations thereof may refer to "and/or". The terms "first," "second," and the like in this specification are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. In the present application, "a plurality of" means two or more. "and/or" describes an association relationship of an association object, and indicates that there may be three relationships, for example, a and/or B, and may indicate that there are three cases of a alone, a and B together, and B alone. The character "/" generally indicates that the context-dependent object is an "or" relationship.