A method and device for processing a service request
By receiving and retrieving the transaction completion status of microservices and constructing a corrective task execution fault method, the problem of distributed microservice transaction consistency is solved, the final consistency of data is achieved, and the operation and maintenance costs and development burden are reduced.
Patent Information
- Application Number
- CN202011302418.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-19
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2040-11-19
AI Technical Summary
In the prior art, transaction consistency of distributed microservices is difficult to guarantee, especially when the coordinator and participant are down, it is impossible to determine whether the transaction has been committed, resulting in the inability to ensure data consistency.
By receiving the transaction completion status of each service, the services whose transaction completion status is successful are retrieved, and the corrective tasks are constructed, these services are called to execute the corrective methods, and the services whose transaction completion status is successful are performed successively, adopting the chain Road tracking technology and transaction compensation mechanism to achieve final consistency of data.
After the business handles exceptions, data consistency is ensured through the corrective operation and maintenance cost, reduce the maintenance burden of developers, and improve the reliability of the system.
Smart Images

Figure CN112417042B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for processing a service request. Background Art
[0002] After the original business is split into microservices, processing a business request (such as a transaction) often requires accessing multiple microservices. Due to various reasons such as network instability, a service exception may occur. If not controlled, it is easy to cause data inconsistency due to incomplete processing or repeated data submission. Operation and maintenance personnel often need to manually correct it, resulting in high operation and maintenance costs and low efficiency.
[0003] If the maintenance of data consistency across systems is left to developers to actively maintain when developing business interfaces, due to the different habits and understanding levels of developers, it is easy for various ways of maintaining consistency to coexist, resulting in greatly increased maintenance costs.
[0004] At present, common methods for the transaction consistency problem of distributed microservices include concatenating multiple application transactions in the business processing chain into a long transaction, using the database's transaction control to perform multi-phase commit, and setting a compensating transaction mode.
[0005] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0006] All participating nodes (i.e., participants) are transaction blocking type, and the coordinator needs to specify an additional timeout mechanism for each participant. After the timeout, the entire transaction fails. If the coordinator crashes after sending a commit message, and the only participant that received this message also crashes, then even if the coordinator generates a new coordinator through the election protocol, the status of this transaction is uncertain, and it is impossible to know whether the transaction has been committed, so the transaction consistency cannot be guaranteed. Summary of the invention
[0007] In view of this, an embodiment of the present invention provides a method and apparatus for processing a service request to solve the technical problem that transaction consistency cannot be guaranteed.
[0008] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for processing a service request is provided, comprising:
[0009] Receive transaction completion status uploaded by each service, wherein the transaction completion status includes success and failure;
[0010] If there is a service whose transaction completion status is failed among the services, then retrieve a service whose transaction completion status is successful from the services;
[0011] A reversal task is constructed for the service whose transaction completion status is successful, and the service whose transaction completion status is successful is called so that the service whose transaction completion status is successful executes a reversal method.
[0012] Optionally, calling the service whose transaction completion status is successful so that the service whose transaction completion status is successful executes the reversal method includes:
[0013] According to the order of receiving the transaction completion status of the services with the transaction completion status being successful, the services with the transaction completion status being successful are called in reverse order, so that the services with the transaction completion status being successful execute the reversal method in turn.
[0014] Optionally, each service intercepts the request data and transaction completion status, and stores the request data in a cache.
[0015] Optionally, the request data includes a global serial number and service data parsed by the service from a received service request.
[0016] Optionally, in each of the services, a base class of a control layer for receiving business requests is defined, and a forward business processing method and a reverse reversal method are defined in the base class.
[0017] Optionally, constructing a reversal task for the service whose transaction completion status is successful includes:
[0018] Obtaining request data corresponding to the service whose transaction completion status is successful from the cache;
[0019] According to the request data corresponding to the service with the transaction completion status being successful, a reversal task is constructed for the service with the transaction completion status being successful.
[0020] Optionally, constructing a reversal task for the service whose transaction completion status is successful, calling the service whose transaction completion status is successful, so that the service whose transaction completion status is successful executes a reversal method, includes:
[0021] A synchronous reversal task is constructed for the service whose transaction completion status is successful, and the service whose transaction completion status is successful is called to make the service whose transaction completion status is successful synchronously execute the reversal method.
[0022] Optionally, after calling the service with the transaction completion status being successful so that the service with the transaction completion status being successful synchronously executes the reversal method, the method further includes:
[0023] Receive a result of synchronization reversal execution exception returned by the service with the transaction completion status as successful;
[0024] An asynchronous reversal task is constructed for the service whose transaction completion status is successful, and a retry time and a maximum number of retries are set, thereby obtaining an asynchronous reversal task table.
[0025] Optionally, after constructing an asynchronous reversal task for the service whose transaction completion status is successful, thereby obtaining an asynchronous reversal task table, the following steps are included:
[0026] According to the set retry time and maximum retry number, the asynchronous reversal task table is periodically scanned by a scheduled task;
[0027] The service is called according to the scanning result, so that the service executes the reversal method asynchronously.
[0028] Optionally, after calling the service according to the scanning result so that the service asynchronously executes the reversal method, the method further includes:
[0029] If the number of service calls reaches the maximum number of retries, the execution result of the asynchronous reversal is sent to the operation and maintenance personnel.
[0030] Optionally, each service includes a service caller and a service provider;
[0031] The service caller calls the service provider according to the received business request;
[0032] If the service provider fails to execute, a rollback is triggered and the result of the execution exception is returned to the service caller;
[0033] The service caller receives the result of the abnormal execution of the service provider and triggers a rollback.
[0034] In addition, according to another aspect of an embodiment of the present invention, there is provided a device for processing a service request, including:
[0035] A receiving module, used to receive the transaction completion status uploaded by each service, wherein the transaction completion status includes success and failure;
[0036] A retrieval module, configured to retrieve a service whose transaction completion status is successful from among the services if there is a service whose transaction completion status is failed among the services;
[0037] The calling module is used to construct a reversal task for the service with a successful transaction completion status, and call the service with a successful transaction completion status to make the service with a successful transaction completion status execute a reversal method.
[0038] Optionally, the calling module is further used for:
[0039] According to the order of receiving the transaction completion status of the services with the transaction completion status being successful, the services with the transaction completion status being successful are called in reverse order, so that the services with the transaction completion status being successful execute the reversal method in turn.
[0040] Optionally, each service intercepts the request data and transaction completion status, and stores the request data in a cache.
[0041] Optionally, the request data includes a global serial number and service data parsed by the service from a received service request.
[0042] Optionally, in each of the services, a base class of a control layer for receiving business requests is defined, and a forward business processing method and a reverse reversal method are defined in the base class.
[0043] Optionally, the calling module is further used for:
[0044] Obtaining request data corresponding to the service whose transaction completion status is successful from the cache;
[0045] According to the request data corresponding to the service with the transaction completion status being successful, a reversal task is constructed for the service with the transaction completion status being successful.
[0046] Optionally, the calling module is further used for:
[0047] A synchronous reversal task is constructed for the service whose transaction completion status is successful, and the service whose transaction completion status is successful is called to make the service whose transaction completion status is successful synchronously execute the reversal method.
[0048] Optionally, the calling module is further used for:
[0049] Calling the service with the transaction completion status being successful, so that the service with the transaction completion status being successful synchronously executes the reversal method, and then receiving the result of the synchronous reversal execution exception returned by the service with the transaction completion status being successful;
[0050] An asynchronous reversal task is constructed for the service whose transaction completion status is successful, and a retry time and a maximum number of retries are set, thereby obtaining an asynchronous reversal task table.
[0051] Optionally, the calling module is further used for:
[0052] Constructing an asynchronous reversal task for the service whose transaction completion status is successful, so as to obtain an asynchronous reversal task table, and then periodically scanning the asynchronous reversal task table through a timing task according to the set retry time and maximum retry times;
[0053] The service is called according to the scanning result, so that the service executes the reversal method asynchronously.
[0054] Optionally, the calling module is further used for:
[0055] After calling the service according to the scan result so that the service executes the reversal method asynchronously, if the number of times the service is called reaches the maximum number of retries, the execution result of the asynchronous reversal is sent to the operation and maintenance personnel.
[0056] Optionally, each service includes a service caller and a service provider;
[0057] The service caller calls the service provider according to the received business request;
[0058] If the service provider fails to execute, a rollback is triggered and the result of the execution exception is returned to the service caller;
[0059] The service caller receives the result of the abnormal execution of the service provider and triggers a rollback.
[0060] According to another aspect of an embodiment of the present invention, there is further provided an electronic device, including:
[0061] one or more processors;
[0062] a storage device for storing one or more programs,
[0063] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any one of the above embodiments.
[0064] According to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described in any one of the above embodiments is implemented.
[0065] An embodiment of the above invention has the following advantages or beneficial effects: because if there is a service with a failed transaction completion status, a service with a successful transaction completion status is retrieved, and a reversal task is constructed for the service with a successful transaction completion status, and the service with a successful transaction completion status is called so that the service with a successful transaction completion status executes the reversal method, the technical problem of the inability to ensure transaction consistency in the prior art is overcome. The embodiment of the present invention collects the transaction completion status through link tracking technology, and through the transaction compensation mechanism, it can ensure the final consistency of data after the business processing is abnormal.
[0066] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific implementation examples. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0068] Figure 1 is a schematic diagram of the main process of the method for processing a service request according to an embodiment of the present invention;
[0069] Figure 2 is a schematic diagram of the main process of a method for processing a service request according to a reference embodiment of the present invention;
[0070] Figure 3 is a schematic diagram of the main process of a method for processing a service request according to another reference embodiment of the present invention;
[0071] Figure 4 is a schematic diagram of main modules of an apparatus for processing a service request according to an embodiment of the present invention;
[0072] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0073] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0074] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0075] Figure 1 FIG. 1 is a schematic diagram of the main flow of a method for processing a service request according to an embodiment of the present invention. Figure 1 As shown, the method for processing a service request is applied to a link tracking tool and may include:
[0076] Step 101, receiving the transaction completion status uploaded by each service.
[0077] For each service, when the service is called, its own business code is executed. After the local transaction is completed, the service uploads the transaction completion status to the link tracking tool, where the transaction completion status includes success and failure. Optionally, the link tracking tool can be Zipkin, which receives the transaction completion status uploaded by each service.
[0078] Optionally, each service intercepts the request data and transaction completion status, and stores the request data in a cache for subsequent reversal operations, and also uploads the transaction completion status to a link tracking tool. In the embodiment of the present invention, each service intercepts and records the request data through an interceptor by collecting link data, and intercepts and records the transaction completion status after the local transaction processing is completed. The normal execution ends in the end state, and the abnormal execution ends in the failed state.
[0079] Since the subsequent reversal operation requires the request data carried in the business request, when intercepting and recording the completion status of the local transaction, the request data of each request will also be intercepted and recorded and cached. The cached request data can be cleared after the business processing or reversal is completed. The cache is used to avoid a large amount of request data causing pressure on database reading and writing.
[0080] Optionally, the request data includes a global serial number and business data parsed by the service from the received business request. Since a transaction may call multiple different services, in order to track the transaction, a global serial number field is added. This field follows the transaction request and flows between different services. As an identifier of a transaction chain, when calling a remote service, the global serial number is added to the request header information. After receiving the request, the service provider takes out the global serial number as the global serial number of the local transaction.
[0081] Optionally, the request data mainly records the service initiator and service provider of each remote call, as well as the specific request path and parameters. Since business requests are implemented in the form of post request bodies, the request parameters need to be serialized and stored, and the types of the request parameters are stored for subsequent deserialization of the request body.
[0082] For example, the complete request data may include:
[0083] operator, represents the operator number of this transaction (the operator number is only used to display information), the data is obtained from the request header information of the request
[0084] spanId, the id of the current span (a specific service call in a complete call chain)
[0085] traceId, the transaction link id
[0086] CLIENT, the client application that requested it
[0087] SERVER, the server application of the request
[0088] invokeType, the call type of this request, which is divided into Async for registering asynchronous tasks and Restful for calling regular services
[0089] reqPath, the request path of this request
[0090] reqParam, the request body parameter of this request, displayed as a serialized result
[0091] reqParamType, the request body parameter type of this request, for later deserialization
[0092] taskId, for the request to register an asynchronous task, records the registered asynchronous task id
[0093] Step 102: If there is a service whose transaction completion status is failed among the various services, then retrieve a service whose transaction completion status is successful from the various services.
[0094] After the link tracking tool receives the transaction completion status uploaded by each service, it traverses the transaction completion status uploaded by each service. If there is a service with a failed transaction completion status, whether it is one service or multiple services, the service with a successful transaction completion status is retrieved from each service.
[0095] When a service is called, it executes its own business code. After the local transaction is completed, the service uploads the transaction completion status to the link tracking tool. Therefore, the link tracking tool can obtain the transaction completion status of each service, such as success or failure.
[0096] Optionally, each service includes a service caller and a service provider. The service caller calls the service provider according to the received business request. If the service provider fails to execute, a rollback is triggered and the result of the execution exception is returned to the service caller. The service caller receives the result of the execution exception of the service provider and triggers a rollback. When the service provider fails to execute, a rollback is triggered and an exception is returned to the service caller, so that the service caller also triggers a rollback, thereby ensuring the consistency of the microservice transaction.
[0097] Step 103, constructing a reversal task for the service with a successful transaction completion status, calling the service with a successful transaction completion status, so that the service with a successful transaction completion status executes a reversal method.
[0098] After the link tracking tool retrieves the services with successful transaction completion status, it constructs a reversal task for the services with successful transaction completion status, and then calls the services with successful transaction completion status respectively, so that these services with successful transaction completion status respectively execute their corresponding reversal methods. The embodiment of the present invention ensures the consistency of microservice transactions through the consistency of internal service transactions and the transaction compensation mechanism between services.
[0099] Optionally, calling the service with a successful transaction completion status so that the service with a successful transaction completion status executes a reversal method includes: calling the services with a successful transaction completion status in reverse order according to the order in which the transaction completion status of the services with a successful transaction completion status are received, so that the services with a successful transaction completion status execute the reversal method in sequence. In an embodiment of the present invention, the link tracking tool can call these services with a successful transaction completion status in reverse order according to the order in which the transaction completion status of the services with a successful transaction completion status are received. For example, the link tracking tool first receives the transaction completion status uploaded by service B, and then receives the transaction completion status uploaded by service C, and the transaction completion status of service B and service C are both completed, then service C is called first, and then service B is called.
[0100] It should be pointed out that in some other embodiments of the present invention, there is no restriction on the order of calling services with a successful transaction completion status, and the link tracking tool may also call services with a successful transaction completion status at the same time.
[0101] In each of the services, a base class of the control layer that receives business requests is defined, and a positive business processing method and a reverse reversal method are defined in the base class. The embodiment of the present invention stipulates that for methods involving data operations, it is necessary to define the corresponding reversal method by inheriting the base class, and set the access path according to certain rules, which facilitates the positioning and addressing of the reversal method. Specifically, in order to standardize the format and request path of the reversal method, a base class of the control layer (controller layer) that accepts requests is defined, and a positive business processing method and a reverse reversal method are defined therein. It is stipulated that the controller layer must be implemented by inheriting the base class method. The advantage of this is that it provides a unified specification for the naming and addressing of the reversal method. When initiating a reversal operation, the reversal method corresponding to different business requests can be quickly and accurately located.
[0102] Optionally, constructing a reversal task for the service whose transaction completion status is successful includes: obtaining request data corresponding to the service whose transaction completion status is successful from the cache; and constructing a reversal task for the service whose transaction completion status is successful according to the request data corresponding to the service whose transaction completion status is successful. Since each service stores the request data carried in the business request in the cache, after the link tracking tool retrieves the service whose transaction completion status is successful, it can obtain the request data corresponding to the service whose transaction completion status is successful from the cache, and construct reversal tasks for these services respectively.
[0103] Optionally, step 103 may include: constructing a synchronous reversal task for the service whose transaction completion status is successful, and calling the service whose transaction completion status is successful, so that the service whose transaction completion status is successful synchronously executes the reversal method. In an embodiment of the present invention, after the link tracking tool retrieves the service whose transaction completion status is successful, it constructs a synchronous reversal task for the service whose transaction completion status is successful, and then calls the services whose transaction completion status is successful respectively, so that these services whose transaction completion status is successful respectively execute their corresponding reversal methods and complete the synchronous reversal operation, thereby ensuring the consistency of microservice transactions.
[0104] After an exception occurs in the link, the service needs to reverse the operations that have been submitted before. According to the collected request data and the recorded transaction completion status, the service needs to reversely construct a reversal task for the completed (i.e., end submitted) transactions in the link. According to the rules of local transaction interception and recording, if the local transaction ends normally, it will be recorded as end status. It should be noted that according to the previous rules for intercepting and recording transaction completion status, all transactions that record the end status must have been completed normally and the local transaction must have been submitted; and for transactions that do not have a normal end, the execution will inevitably throw an exception, thereby triggering the transaction management within the service to control the rollback of the submitted local transaction, and record the local transaction as failed in the interceptor.
[0105] Optionally, after calling the service with a successful transaction completion status so that the service with a successful transaction completion status synchronously executes the reversal method, it also includes: receiving the result of the synchronous reversal execution exception returned by the service with a successful transaction completion status; constructing an asynchronous reversal task for the service with a successful transaction completion status, and setting the retry time and the maximum number of retries, thereby obtaining an asynchronous reversal task table. If the synchronous reversal fails, the link tracking tool constructs an asynchronous reversal task for the service that failed the synchronous reversal, and sets the retry time and the maximum number of retries, thereby obtaining an asynchronous reversal task table.
[0106] Optionally, after constructing an asynchronous reversal task for the service whose transaction completion status is successful, thereby obtaining an asynchronous reversal task table, it includes: periodically scanning the asynchronous reversal task table through a timed task according to the set retry time and maximum retry times; calling the service according to the scan result so that the service asynchronously executes the reversal method. Optionally, after calling the service according to the scan result so that the service asynchronously executes the reversal method, it also includes: if the number of service calls reaches the maximum number of retries, sending the execution result of the asynchronous reversal to the operation and maintenance personnel. In an embodiment of the present invention, if the synchronous reversal is executed abnormally, it will automatically switch to asynchronous reversal, and after the asynchronous task is persisted, the reversal method will be executed asynchronously, and the time for the next retry and the maximum number of retries will be set, and a limited number of retries will be performed. If it still fails, it is necessary to notify the developer to intervene through logs or other means.
[0107] The embodiments of the present invention can ensure that after an error occurs in a certain link in the transaction chain, the previously submitted data is cleared through a reversal operation, thereby ultimately maintaining the consistency of the transaction data and making it as imperceptible to developers as possible. The data consistency of business transactions can be ensured through simple annotations and development specifications.
[0108] According to the various embodiments described above, it can be seen that the embodiment of the present invention solves the technical problem of the inability to ensure transaction consistency in the prior art by retrieving the service with a successful transaction completion status if there is a service with a failed transaction completion status, constructing a reversal task for the service with a successful transaction completion status, and calling the service with a successful transaction completion status so that the service with a successful transaction completion status executes the reversal method. The embodiment of the present invention collects the transaction completion status through link tracking technology, and through the transaction compensation mechanism, it can ensure the final consistency of data after the business processing is abnormal.
[0109] Moreover, the embodiments of the present invention also have the following advantages:
[0110] 1) No need for business development. By presetting the base class, adding interceptors to record the transaction completion status, and automatically initiating corrections for exceptions, the development is made unaware. Data consistency can be achieved by simply setting the correction method for transactions involving data operations according to the specifications.
[0111] 2) Based on the link data collection method, the completion status of the transaction is intercepted and recorded after the local transaction processing is completed in the form of an interceptor;
[0112] 3) For business requests that need to be reversed due to execution failure, the task will be automatically persisted after the synchronous reversal fails and switched to asynchronous reversal mode to ensure the normal execution of the reversal task as much as possible.
[0113] 4) After the correction task fails and reaches the maximum number of retries, the operation and maintenance personnel will be notified through logs and other means to intervene, reducing the pressure and manpower costs of operation and maintenance.
[0114] Figure 2 FIG. 1 is a schematic diagram of the main flow of a method for processing a service request according to a reference embodiment of the present invention. As another embodiment of the present invention, Figure 2 As shown, the method for processing a service request may include:
[0115] Service A receives the business request, executes its own business code, and then calls service B;
[0116] Service B executes its own business code, intercepts the request data and transaction completion status, stores the request data in the cache, returns the processing result to service A, and reports the transaction completion status to the link tracking tool Zipkin;
[0117] Service A continues to call service D, which executes its own business code and calls service E.
[0118] Service E executes its own business code, intercepts request data and transaction completion status, stores the request data in the cache, returns the processing result to service D, and reports the transaction completion status to the link tracking tool Zipkin;
[0119] The D service executes abnormally, intercepts the request data and transaction completion status, stores the request data in the cache, returns an exception to the A service, and reports the transaction completion status to the link tracking tool Zipkin;
[0120] A service has a call exception, triggering local transaction management and performing a rollback operation on the committed transaction;
[0121] The link tracking tool Zipkin retrieves services whose transaction completion status is end, such as service B and service E, and then obtains the request data corresponding to service B and service E from the cache, constructs reversal tasks for service B and service E respectively, and the link tracking tool Zipkin calls service B and service E to enable service B and service E to execute their respective reversal methods.
[0122] In addition, the specific implementation content of the method for processing a service request in a reference embodiment of the present invention has been described in detail in the method for processing a service request described above, so the repeated content will not be described here.
[0123] Figure 3 FIG. 1 is a schematic diagram of the main flow of a method for processing a service request according to another reference embodiment of the present invention. As another embodiment of the present invention, Figure 3 As shown, the method for processing a service request is applied to a link tracking tool and may include:
[0124] Step 301: Receive the transaction completion status uploaded by each service, wherein the transaction completion status includes success and failure.
[0125] Step 302: If there is a service whose transaction completion status is failed among the various services, then retrieve a service whose transaction completion status is successful from the various services.
[0126] Step 303: Obtain request data corresponding to the service whose transaction completion status is success from the cache.
[0127] Step 304: construct a synchronization reversal task for the service whose transaction completion status is successful according to the request data corresponding to the service whose transaction completion status is successful.
[0128] Step 305: Call the service whose transaction completion status is successful, so that the service whose transaction completion status is successful synchronously executes the reversal method.
[0129] Step 306: Receive the result of the synchronous reversal execution exception returned by the service with the transaction completion status as successful.
[0130] Step 307, construct an asynchronous reversal task for the service whose transaction completion status is successful, and set a retry time and a maximum number of retries, thereby obtaining an asynchronous reversal task table.
[0131] Step 308: Periodically scan the asynchronous reversal task table through a scheduled task according to the set retry time and maximum retry times.
[0132] Step 309: calling a service according to the scanning result, so that the service asynchronously executes the reversal method.
[0133] Step 310: If the number of service calls reaches the maximum number of retries, the execution result of the asynchronous reversal is sent to the operation and maintenance personnel.
[0134] In addition, the specific implementation content of the method for processing a service request in another reference embodiment of the present invention has been described in detail in the method for processing a service request described above, so the repeated content will not be described here.
[0135] Figure 4 is a schematic diagram of the main modules of the device for processing a service request according to an embodiment of the present invention. Figure 4As shown, the device 400 for processing business requests includes a receiving module 401, a retrieval module 402 and a calling module 403; the receiving module 401 is used to receive the transaction completion status uploaded by each service, wherein the transaction completion status includes success and failure; the retrieval module 402 is used to retrieve the service with a successful transaction completion status from each service if there is a service with a failed transaction completion status among the services; the calling module 403 is used to construct a reversal task for the service with a successful transaction completion status, and call the service with a successful transaction completion status, so that the service with a successful transaction completion status executes the reversal method.
[0136] Optionally, the calling module 403 is further used to:
[0137] According to the order of receiving the transaction completion status of the services with the transaction completion status being successful, the services with the transaction completion status being successful are called in reverse order, so that the services with the transaction completion status being successful execute the reversal method in turn.
[0138] Optionally, each service intercepts the request data and transaction completion status, and stores the request data in a cache.
[0139] Optionally, the request data includes a global serial number and service data parsed by the service from a received service request.
[0140] Optionally, in each of the services, a base class of a control layer for receiving business requests is defined, and a forward business processing method and a reverse reversal method are defined in the base class.
[0141] Optionally, the calling module 403 is further used to:
[0142] Obtaining request data corresponding to the service whose transaction completion status is successful from the cache;
[0143] According to the request data corresponding to the service with the transaction completion status being successful, a reversal task is constructed for the service with the transaction completion status being successful.
[0144] Optionally, the calling module 403 is further used to:
[0145] A synchronous reversal task is constructed for the service whose transaction completion status is successful, and the service whose transaction completion status is successful is called to make the service whose transaction completion status is successful synchronously execute the reversal method.
[0146] Optionally, the calling module 403 is further used to:
[0147] Calling the service with the transaction completion status being successful, so that the service with the transaction completion status being successful synchronously executes the reversal method, and then receiving the result of the synchronous reversal execution exception returned by the service with the transaction completion status being successful;
[0148] An asynchronous reversal task is constructed for the service whose transaction completion status is successful, and a retry time and a maximum number of retries are set, thereby obtaining an asynchronous reversal task table.
[0149] Optionally, the calling module 403 is further used to:
[0150] Constructing an asynchronous reversal task for the service whose transaction completion status is successful, so as to obtain an asynchronous reversal task table, and then periodically scanning the asynchronous reversal task table through a timing task according to the set retry time and maximum retry times;
[0151] The service is called according to the scanning result, so that the service executes the reversal method asynchronously.
[0152] Optionally, the calling module 403 is further used to:
[0153] After calling the service according to the scan result so that the service executes the reversal method asynchronously, if the number of times the service is called reaches the maximum number of retries, the execution result of the asynchronous reversal is sent to the operation and maintenance personnel.
[0154] Optionally, each service includes a service caller and a service provider;
[0155] The service caller calls the service provider according to the received business request;
[0156] If the service provider fails to execute, a rollback is triggered and the result of the execution exception is returned to the service caller;
[0157] The service caller receives the result of the abnormal execution of the service provider and triggers a rollback.
[0158] According to the various embodiments described above, it can be seen that the embodiment of the present invention solves the technical problem of the inability to ensure transaction consistency in the prior art by retrieving the service with a successful transaction completion status if there is a service with a failed transaction completion status, constructing a reversal task for the service with a successful transaction completion status, and calling the service with a successful transaction completion status so that the service with a successful transaction completion status executes the reversal method. The embodiment of the present invention collects the transaction completion status through link tracking technology, and through the transaction compensation mechanism, it can ensure the final consistency of data after the business processing is abnormal.
[0159] It should be noted that the specific implementation content of the device for processing a service request in the present invention has been described in detail in the method for processing a service request described above, so the repeated content will not be described again here.
[0160] Figure 5 An exemplary system architecture 500 is shown to which the method for processing a service request or the apparatus for processing a service request according to the embodiments of the present invention can be applied.
[0161] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0162] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, 503, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0163] The terminal devices 501 , 502 , and 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0164] Server 505 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using terminal devices 501, 502, and 503. The backend management server may analyze and process the received data such as item information query requests, and feed back the processing results to the terminal device.
[0165] It should be noted that the method for processing a service request provided in the embodiment of the present invention is generally executed by the server 505 , and accordingly, the device for processing a service request is generally disposed in the server 505 .
[0166] It should be understood that Figure 5 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0167] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device suitable for implementing an embodiment of the present invention. Figure 6The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0168] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0169] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.
[0170] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.
[0171] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0172] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0173] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a receiving module, a retrieval module and a calling module, wherein the names of these modules do not constitute a limitation on the modules themselves in some cases.
[0174] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device implements the following method: receiving the transaction completion status uploaded by each service, wherein the transaction completion status includes success and failure; if there is a service with a failed transaction completion status among the services, then retrieving the service with a successful transaction completion status from the services; constructing a reversal task for the service with a successful transaction completion status, and calling the service with a successful transaction completion status, so that the service with a successful transaction completion status executes the reversal method.
[0175] According to the technical solution of the embodiment of the present invention, if there is a service with a failed transaction completion status, the service with a successful transaction completion status is retrieved, and a reversal task is constructed for the service with a successful transaction completion status, and the service with a successful transaction completion status is called, so that the service with a successful transaction completion status executes the reversal method. Therefore, the technical problem of the inability to ensure transaction consistency in the prior art is overcome. The embodiment of the present invention collects the transaction completion status through link tracking technology, and through the transaction compensation mechanism, it can ensure the final consistency of data after the business processing is abnormal.
[0176] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for processing a service request, characterized in that: Applied to a link tracking tool, the method comprises: Receive transaction completion status uploaded by each service, wherein the transaction completion status includes success and failure; If there is a service whose transaction completion status is failed among the services, then retrieve a service whose transaction completion status is successful from the services; Constructing a reversal task for the service whose transaction completion status is successful, calling the service whose transaction completion status is successful, so that the service whose transaction completion status is successful executes a reversal method; Constructing a reversal task for the service whose transaction completion status is successful, including: Obtaining request data corresponding to the service whose transaction completion status is successful from the cache; According to the request data corresponding to the service with the transaction completion status being successful, construct a reversal task for the service with the transaction completion status being successful; Calling the service whose transaction completion status is successful, so that the service whose transaction completion status is successful executes the reversal method, including: In accordance with the order of receiving the transaction completion status of the service with the transaction completion status being successful, the services with the transaction completion status being successful are called in reverse order, so that the services with the transaction completion status being successful execute the reversal method in turn; Among them, each service intercepts request data and transaction completion status, and stores the request data in a cache, wherein the request data includes a global serial number and business data parsed by the service from the received business request; in each service, a base class of a control layer for receiving business requests is defined, and a forward business processing method and a reverse reversal method are defined in the base class; after an exception occurs in the link, each service performs a reversal operation on the previously submitted operations, and according to the collected request data and the recorded transaction completion status, a reversal task is constructed in reverse for the completed transactions in the link.
2. The method according to claim 1, characterized in that Constructing a reversal task for the service whose transaction completion status is successful, calling the service whose transaction completion status is successful, so that the service whose transaction completion status is successful executes a reversal method, including: A synchronous reversal task is constructed for the service whose transaction completion status is successful, and the service whose transaction completion status is successful is called to make the service whose transaction completion status is successful synchronously execute the reversal method.
3. The method according to claim 2, characterized in that After calling the service with the transaction completion status being successful so that the service with the transaction completion status being successful synchronously executes the reversal method, the method further includes: Receive a result of synchronization reversal execution exception returned by the service with the transaction completion status as successful; An asynchronous reversal task is constructed for the service whose transaction completion status is successful, and a retry time and a maximum number of retries are set, thereby obtaining an asynchronous reversal task table.
4. The method according to claim 3, characterized in that: After constructing an asynchronous reversal task for the service whose transaction completion status is successful, thereby obtaining an asynchronous reversal task table, the following steps are included: According to the set retry time and maximum retry number, the asynchronous reversal task table is periodically scanned by a scheduled task; The service is called according to the scanning result, so that the service executes the reversal method asynchronously.
5. The method according to claim 4, characterized in that After calling the service according to the scanning result so that the service asynchronously executes the reversal method, the method further includes: If the number of service calls reaches the maximum number of retries, the execution result of the asynchronous reversal is sent to the operation and maintenance personnel.
6. The method according to claim 1, characterized in that Each of the services includes a service caller and a service provider; The service caller calls the service provider according to the received business request; If the service provider fails to execute, a rollback is triggered and the result of the execution exception is returned to the service caller; The service caller receives the result of the abnormal execution of the service provider and triggers a rollback.
7. A device for processing a service request, characterized in that: Set in a link tracking tool, the device includes: A receiving module, used to receive the transaction completion status uploaded by each service, wherein the transaction completion status includes success and failure; A retrieval module, configured to retrieve a service whose transaction completion status is successful from among the services if there is a service whose transaction completion status is failed among the services; A calling module, used for constructing a reversal task for the service whose transaction completion status is successful, and calling the service whose transaction completion status is successful, so that the service whose transaction completion status is successful executes a reversal method; The calling module is also used for: Obtaining request data corresponding to the service whose transaction completion status is successful from the cache; According to the request data corresponding to the service with the transaction completion status being successful, construct a reversal task for the service with the transaction completion status being successful; The calling module is also used for: In accordance with the order of receiving the transaction completion status of the service with the transaction completion status being successful, the services with the transaction completion status being successful are called in reverse order, so that the services with the transaction completion status being successful execute the reversal method in turn; Among them, each service intercepts request data and transaction completion status, and stores the request data in a cache, wherein the request data includes a global serial number and business data parsed by the service from the received business request; in each service, a base class of a control layer for receiving business requests is defined, and a forward business processing method and a reverse reversal method are defined in the base class; after an exception occurs in the link, each service performs a reversal operation on the previously submitted operations, and according to the collected request data and the recorded transaction completion status, a reversal task is constructed in reverse for the completed transactions in the link.
8. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
9. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.