Asynchronous transaction processing method, device, storage medium and computer equipment
By setting annotation information in the asynchronous method of asynchronous transactions and storing it to the database, the problem of excessive resource occupation in the engineering system when handling asynchronous transactions is solved, and the successful execution of asynchronous transactions and effective reduction of resources is achieved.
Patent Information
- Application Number
- CN202211114478.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-14
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2042-09-14
AI Technical Summary
When handling asynchronous transactions in engineering systems, resource usage is too high, and traditional processing methods cannot effectively handle asynchronous transactions across threads, across databases and across applications.
By setting annotation information in the asynchronous method of an asynchronous transaction, and storing it in the database when the method execution fails, and when the calculation resource is idle, the asynchronous method is scheduled and executed from the database.
This method ensures that asynchronous transactions can be successfully executed without setting up message middleware, reducing the resource usage of the engineering system when handling asynchronous transactions, and adapts to most system scenarios, and is highly scalable.
Smart Images

Figure CN115499493B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer information processing, and in particular to an asynchronous transaction processing method, device, storage medium and computer equipment. Background Art
[0002] Transactions are an important part of the engineering system and an important guarantee for maintaining data atomicity. When a request to create a resource comes in, in order to ensure the data atomicity of this request, the engineering system must ensure that all data operations must be executed successfully or all failed.
[0003] Under normal circumstances, the engineering system only needs to place the database operation in a spring transaction to achieve the atomicity of the operation. However, because there are some relatively complex and time-consuming business processes in the engineering system, asynchronous threads are required to process or cross-database operations, and even cross-system processing logic is required. These businesses are all asynchronous transactions. In this case, if a single spring transaction is used, these asynchronous transactions cannot be processed. The current spring transaction can only solve the atomic transaction operation performed by the current thread based on the current only database. Any cross-thread, cross-database and cross-application asynchronous transactions cannot be handled by traditional transaction processing methods.
[0004] To solve the above problems, the traditional processing strategy is to add message-oriented middleware between multiple systems. Message-oriented middleware generally has producer confirmation function, message confirmation function and dead letter queue, which ensures that asynchronous transactions will achieve eventual consistency to the greatest extent. However, adding such message middleware will make the system too large. When the engineering system encounters logic that only requires asynchronous thread processing because it is time-consuming, adding a large middleware component will be very unreasonable and will cause the engineering system to have excessive resource usage when processing asynchronous transactions. Summary of the invention
[0005] In view of this, the present application provides an asynchronous transaction processing method, apparatus, storage medium and computer equipment, the main purpose of which is to solve the problem of excessive resource usage when the engineering system processes asynchronous transactions.
[0006] According to a first aspect of the present invention, there is provided an asynchronous transaction processing method, which is applied to a microservice application system, and the method comprises:
[0007] Monitoring the execution of an asynchronous method for processing asynchronous transactions in the microservice application system, wherein the asynchronous method has preset annotation information, and the annotation information includes an execution annotation;
[0008] Determine whether the asynchronous method is executed successfully, and determine whether the annotation information of the asynchronous method is an execution annotation;
[0009] If the asynchronous method fails to execute, and the annotation information of the asynchronous method is an execution annotation, the asynchronous method is stored in a database;
[0010] The asynchronous method is scheduled and executed from the database.
[0011] According to a second aspect of the present invention, there is provided an asynchronous transaction processing device, the device comprising:
[0012] A data monitoring module, used to monitor the execution of an asynchronous method for processing asynchronous transactions in the microservice application system, wherein the asynchronous method has pre-set annotation information, and the annotation information includes an execution annotation;
[0013] A data judgment module, used to judge whether the asynchronous method is executed successfully, and to judge whether the annotation information of the asynchronous method is an execution annotation;
[0014] A data retrieval module, configured to store the asynchronous method in a database if the asynchronous method fails to execute and the annotation information of the asynchronous method is an execution annotation;
[0015] A data execution module is used to schedule and execute the asynchronous method from the database.
[0016] According to a third aspect of the present invention, there is provided a storage medium on which a computer program is stored, and when the program is executed by a processor, the above-mentioned asynchronous transaction processing method is implemented.
[0017] According to a fourth aspect of the present invention, there is provided a computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned asynchronous transaction processing method when executing the program.
[0018] The present invention provides an asynchronous transaction processing method, device, storage medium and computer equipment. By setting annotation information in the asynchronous method of the asynchronous transaction, and when the asynchronous method fails to execute, it is judged whether the asynchronous transaction corresponding to the asynchronous method is an asynchronous transaction that must be executed successfully based on the annotation information. If the annotation information of the asynchronous method is an execution annotation, it is judged that the asynchronous transaction corresponding to the asynchronous method is an asynchronous transaction that must be executed successfully, and the asynchronous method is stored in the database. When the computing resources are idle, the asynchronous method is scheduled and executed from the database. The technical solution of the present application is based on adding annotation information to the asynchronous method, and storing and calling the asynchronous method based on the delay queue in the database to complete the processing of the asynchronous transaction, so that the framework of the technical solution is neat and clear, and the setting is simple. It can ensure that the asynchronous transaction can be successfully executed without setting up the message middleware, so that the engineering system can effectively reduce the resources occupied when solving asynchronous transactions. At the same time, the technical solution of the present application can adapt to most system scenarios and has strong scalability.
[0019] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0021] Figure 1 A schematic diagram of an asynchronous transaction in the same system provided by an embodiment of the present invention is shown;
[0022] Figure 2 A schematic diagram of an asynchronous transaction across databases in the same system provided by an embodiment of the present invention is shown;
[0023] Figure 3 A schematic diagram of a cross-system asynchronous transaction provided by an embodiment of the present invention is shown;
[0024] Figure 4 A schematic diagram of a process flow of an asynchronous transaction processing method provided by an embodiment of the present invention is shown;
[0025] Figure 5 One of the structural schematic diagrams of the asynchronous transaction processing device provided by an embodiment of the present invention is shown;
[0026] Figure 6 The second flowchart of the asynchronous transaction processing device provided by the embodiment of the present invention is shown. DETAILED DESCRIPTION
[0027] The present invention will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict.
[0028] In the engineering system, when a request to create a resource arrives, in order to ensure the data atomicity of this request, the engineering system must ensure that all data operations must be executed successfully or all failed. Under normal circumstances, the engineering system only needs to place the database operation in a spring transaction to achieve the atomicity of the operation. However, because there are some relatively complex and time-consuming business processes in the engineering system, asynchronous threads are required to process or cross-database operations, and even cross-system processing logic is required. These businesses are all asynchronous transactions. Among them, asynchronous transactions include asynchronous transactions in the same system, asynchronous transactions across databases in the same system, and asynchronous transactions across systems.
[0029] like Figure 1 As shown in the figure, the asynchronous transactions in the same system are executed by the main thread in the system and executed by the asynchronous thread, and the two use the same database. Figure 2 As shown, the asynchronous transaction across databases in the same system is mainly used to implement transactions executed based on different databases. Figure 3 A schematic diagram of cross-system asynchronous transactions is given, such as Figure 3 As shown in the figure, it is necessary to establish a call interface between the main threads of the two systems to implement asynchronous transaction execution between the systems. In the face of these situations, it is impossible to handle these asynchronous transactions if a single spring transaction is used. The current spring transaction can only solve the atomic transaction operation performed by the current thread based on the current only database. Any cross-thread, cross-database and cross-application asynchronous transactions cannot be handled by the traditional transaction processing method. In response to the above problems, the traditional processing strategy is to add message-oriented middleware between multiple systems. Message middleware generally has producer confirmation function, message confirmation function and dead letter queue, which ensures that asynchronous transactions will achieve ultimate consistency to the greatest extent. However, adding such message middleware will make the system too large. When the engineering system encounters logic that only requires asynchronous thread processing because of time-consuming, adding a large middleware component will be very unreasonable, and will cause the engineering system to have excessive resource usage when processing asynchronous transactions.
[0030] In view of the above problems, in one embodiment, Figure 4 As shown, an asynchronous transaction processing method is provided, which is described by taking the method applied to a computer device as an example, and includes the following steps:
[0031] 101. Monitor the execution status of an asynchronous method for processing asynchronous transactions in the microservice application system, wherein the asynchronous method has pre-set annotation information, and the annotation information includes execution annotations.
[0032] Wherein, the microservice application system can be a computer system or engineering system used by the user. Meanwhile, before executing the method provided in this embodiment, it is necessary to import the basic resource information about executing this method into the microservice application system. First, the jar file related to spring is introduced into the microservice application system, wherein the spring framework is an open source J2EE application framework, which is a lightweight container for managing the life cycle of beans, and the jar file (Java Archive, Java Archive) is a software package file format, which is usually used to aggregate a large number of Java class files, related metadata and resource files into one file, so as to develop Java platform application software or libraries. Subsequently, the system opens a declarative transaction to realize transaction control in units of methods. After that, the microservice application system introduces the jar file containing the basic resource information for executing this method, and adds annotation information @MiceDelay to the specified asynchronous method, wherein, for the necessary asynchronous method of the asynchronous transaction that does not allow execution failure, the execution annotation in the annotation information can be set on it, which is used to indicate that the system locks the asynchronous method when processing the transaction, and provides an execution object for subsequent work. When the annotation information is an execution annotation, the save flag in the annotation information @MiceDelay may correspond to "yes", ie, "Y", to mark the necessary asynchronous method that does not allow the execution of failed asynchronous transactions.
[0033] Specifically, the execution status of the asynchronous method for processing the asynchronous transaction is detected in real time, including execution success and execution failure. At the same time, the annotation information set on the asynchronous method is monitored to determine whether the save flag in the annotation information @MiceDelay corresponds to "Y".
[0034] 102. Determine whether the asynchronous method is executed successfully, and determine whether the annotation information of the asynchronous method is an execution annotation.
[0035] Specifically, after the main thread is processed, the asynchronous transaction is started, and the error information returned by the asynchronous method can be obtained to determine whether the asynchronous method is successfully executed. In the case of failure of the asynchronous method, the annotation information set on the asynchronous method can be identified to determine whether the annotation information is an execution annotation. At the same time, the execution failure flag can also be set on the asynchronous method that failed to execute, which is convenient for subsequent identification work.
[0036] 103. If the asynchronous method fails to execute, and the annotation information of the asynchronous method is an execution annotation, the asynchronous method is stored in a database.
[0037] Specifically, when the asynchronous method fails to execute and the annotation information of the asynchronous method is @MiceDelay(save="Y"), the information corresponding to the asynchronous method that failed to execute is stored in the storage queue of the database as delay information, so as to facilitate the subsequent scheduled scheduling of the asynchronous method for re-execution. At the same time, after the information corresponding to the asynchronous method is stored in the storage queue of the database, the information that the delay mechanism proxy class has been entered can be returned to the main thread.
[0038] 104. Schedule and execute the asynchronous method from the database.
[0039] Specifically, based on a preset time interval or in response to a user's execution operation, the delay information can be retrieved from a database of the system for re-execution to execute the asynchronous method and complete the asynchronous transaction.
[0040] The present invention provides an asynchronous transaction processing method, which sets annotation information in an asynchronous method of an asynchronous transaction, and when the asynchronous method fails to execute, determines whether the asynchronous transaction corresponding to the asynchronous method is an asynchronous transaction that must be executed successfully based on the annotation information. If the annotation information of the asynchronous method is an execution annotation, the asynchronous transaction corresponding to the asynchronous method is determined to be a necessary asynchronous transaction that must be processed successfully, and the asynchronous method is stored in a database as delay information. When computing resources are idle, the asynchronous method is scheduled and executed from the database. The technical solution of the present application is based on adding annotation information to the asynchronous method, and storing and calling the asynchronous method based on the queue in the database to complete the processing of the asynchronous transaction, so that the framework of the technical solution is neat and clear, and the setting is simple. It can ensure that the asynchronous transaction can be successfully processed without setting up a message middleware, so that the engineering system can effectively reduce the resources occupied when solving asynchronous transactions. At the same time, the technical solution of the present application can adapt to most system scenarios and has strong scalability.
[0041] In one embodiment, step 104 can be implemented by the following steps: first, identify the number of microservice application systems that execute the asynchronous method. Specifically, for cross-system asynchronous transactions, the main threads of multiple microservice application systems need to execute the asynchronous transactions, and the number of microservice application systems can be determined based on the number of microservice application systems to which the main threads that execute the asynchronous transactions belong. If the number of the microservice application systems is greater than or equal to two, the interface call information between the microservice application systems is obtained. Specifically, when the microservice application system that executes the asynchronous transaction is greater than one, it can be considered that the asynchronous transaction executed at this time is a cross-system asynchronous transaction, and then the interface call information between the microservice application systems is obtained, providing basic conditions for the subsequent establishment of the logic of asynchronous thread processing. Then, based on the interface call information, a cross-system processing interface between the microservice application systems is established, thereby establishing the logic of asynchronous thread processing. Finally, based on the cross-system processing interface, the asynchronous method is scheduled from the database of the microservice application system and the asynchronous method is executed. The cross-system processing logic established based on the cross-system processing interface in this embodiment can realize the execution of cross-system asynchronous transactions.
[0042] In one embodiment, step 104 can also be implemented by the following steps: based on a preset detection interval, data detection is performed on the database. Among them, the detection interval can be set based on the actual situation, and is used to periodically detect whether there is information corresponding to the asynchronous method in the database, that is, to determine whether there is delay information. Specifically, when processing asynchronous transactions, it is possible to periodically detect whether there is delay information in the database based on the scheduling mechanism introduced by the cross-system processing interface. If the data information corresponding to the asynchronous method exists in the database, the asynchronous method is scheduled and executed from the database. Specifically, based on the introduced scheduling mechanism, the delay information stored in the database is executed through regular scheduling, and the asynchronous method of the asynchronous transaction that failed to execute previously is executed, so that the asynchronous transaction can be successfully processed, thereby ensuring the atomicity of the asynchronous transaction request data.
[0043] In one embodiment, the annotation information also includes a default annotation, wherein the default annotation is used to mark non-essential asynchronous methods that allow execution failure in asynchronous methods. The specific form of the default annotation can be that the save corresponding to @MiceDelay is empty. When performing the method of asynchronous thread processing in the same system, it can be judged if the asynchronous method of the asynchronous transaction is a non-essential asynchronous method, that is, the asynchronous transaction can allow processing failure, such as unimportant processing logic, logging, sending emails, etc. The default annotation can be set on the asynchronous method of the above-mentioned asynchronous transaction in advance for system recognition. Further, before the asynchronous method is stored in the database, the method also includes: if the asynchronous method fails to execute and the annotation information of the asynchronous method is the default annotation, the asynchronous method is discarded. Specifically, if the annotation information of the asynchronous method that fails to execute is the default annotation, that is, save is empty, it can be defaulted to asynchronous execution only, and the delay information is not saved in the database after the execution fails, and it does not need to be executed again. In an embodiment of the present application, a default annotation can be set on a non-essential asynchronous method in advance, and the asynchronous method is discarded after the execution fails to save computing resources.
[0044] In one embodiment, after step 104, the above-mentioned asynchronous transaction processing method may further include the following steps: if the asynchronous method fails to execute, the steps in step 103 are executed again until the asynchronous method is successfully executed. Specifically, if the delay information retrieved from the storage queue fails to execute again, the delay information is stored in the storage queue again, waiting for the next processing. In an embodiment of the present application, if the delay information fails to execute, the delay information is stored in the database, waiting for the scheduling mechanism to retrieve and execute again after the next detection interval. If the execution fails again, the above steps are repeated until the delay information is executed successfully to ensure the atomicity of the transaction.
[0045] In one embodiment, step 101 can be implemented by the following steps: first, set up an aspect programming, and wrap the asynchronous method with the annotation information in the aspect proxy of the aspect programming. Among them, aspect programming (AspectOriented Programming.AOP) is a technology that realizes the unified maintenance of program functions through pre-compilation and dynamic proxy during operation. It can isolate various parts of the business logic and add additional functions without modifying the source code of each business logic, so that the coupling between the various parts of the business logic is reduced, the reusability of the program is improved, and the development efficiency is improved. Specifically, when the application starts, an AOP will be generated, and the asynchronous method with annotation information will be wrapped in the spring aspect proxy class, so that the monitoring function can be added for the asynchronous method without modifying the source code. Then, the execution of the asynchronous method in the aspect proxy is monitored. Specifically, the asynchronous method with annotation information in the proxy class is monitored. If the asynchronous method of the asynchronous transaction fails to execute, and the asynchronous method has an execution annotation, the request data of the asynchronous transaction and the asynchronous method package object are placed in the delay queue to wait for execution again. If the asynchronous method of an asynchronous transaction fails to execute, and the asynchronous method has a default annotation, the request data of the asynchronous transaction and the asynchronous method are discarded. In an embodiment of the present application, by setting the aspect programming method to monitor the asynchronous method, a monitoring function can be added to the asynchronous transaction execution method without modifying the source code of the asynchronous transaction execution method processing logic, thereby improving work efficiency and keeping the code tidy.
[0046] In one embodiment, the asynchronous transaction processing method may further include the following steps: based on a preset detection interval, the database is tested for data, and if the database contains data information corresponding to the asynchronous method, an alarm message is issued. Specifically, based on the detection interval, the delay information stored in the database may be scheduled to be executed regularly, and when the delay information stored in the database is found, an alarm message is issued to notify the engineer to check the failure of the asynchronous method execution, find out the cause and deal with it in a timely manner.
[0047] The asynchronous transaction processing method provided in the above embodiment sets annotation information in the asynchronous method of the asynchronous transaction, and monitors the execution of the asynchronous method based on aspect programming. When the asynchronous method fails to execute, it is determined based on the annotation information whether the asynchronous transaction corresponding to the asynchronous method is an asynchronous transaction that must be executed successfully. If the annotation information of the asynchronous method is an execution annotation, it is determined that the asynchronous transaction corresponding to the asynchronous method is an asynchronous transaction that must be executed successfully, and the asynchronous method is stored in the database as delay information. Based on a preset time interval or when the computing resources are idle, the asynchronous method is scheduled and executed from the database, and when the asynchronous method fails to execute, the engineer is notified to find out the cause of the failure in time. The technical solution of the present application is based on adding annotation information to the asynchronous method, and storing and calling the asynchronous method based on the queue in the database to complete the processing of the asynchronous transaction, so that the framework of the technical solution is neat and clear, and the setting is simple. It can ensure that the asynchronous transaction can be successfully executed without setting up the message middleware, so that the engineering system can effectively reduce the resources occupied when solving asynchronous transactions. At the same time, the technical solution of the present application can adapt to most system scenarios, has strong scalability, and can distinguish between unnecessary asynchronous methods and necessary asynchronous methods in the system. It will not waste too many resources for unnecessary asynchronous methods, and has security and stability for necessary asynchronous methods. It can be freely set based on actual conditions, and is efficient and flexible.
[0048] Further, as Figure 4 The specific implementation of the method shown in the embodiment provides an asynchronous transaction processing device, such as Figure 5 As shown, the device includes: a data monitoring module 51, a data judgment module 52, a data retrieval module 53 and a data execution module 54.
[0049] The data monitoring module 51 may be used to monitor the execution of an asynchronous method for processing asynchronous transactions in the microservice application system, wherein the asynchronous method has pre-set annotation information, and the annotation information includes an execution annotation;
[0050] The data judgment module 52 can be used to judge whether the asynchronous method is executed successfully, and judge whether the annotation information of the asynchronous method is an execution annotation;
[0051] The data retrieval module 53 is configured to store the asynchronous method in a database if the asynchronous method fails to execute and the annotation information of the asynchronous method is an execution annotation;
[0052] The data execution module 54 can be used to schedule and execute the asynchronous method from the database.
[0053] In a specific application scenario, the data monitoring module 51 can be specifically used to set up an aspect programming, package the asynchronous method with the annotation information in the aspect proxy of the aspect programming, and monitor the execution status of the asynchronous method in the aspect proxy.
[0054] In a specific application scenario, the data execution module 54 can be specifically used to identify the number of the microservice application systems that execute the asynchronous method; if the number of the microservice application systems is greater than or equal to two, obtain interface call information between the microservice application systems; based on the interface call information, establish a cross-system processing interface between the microservice application systems; based on the cross-system processing interface, schedule the asynchronous method from the database of the microservice application system and execute the asynchronous method.
[0055] In a specific application scenario, the data execution module 54 can also be specifically used to perform data detection on the database based on a preset detection interval; if the database contains data information corresponding to the asynchronous method, the asynchronous method is scheduled and executed from the database.
[0056] In a specific application scenario, the data execution module 54 can also be specifically used to issue an alarm prompt message if there is data information corresponding to the asynchronous method in the database.
[0057] Furthermore, the annotation information also includes default annotations. In specific application scenarios, such as Figure 6 As shown, the device further includes a discarding execution module 63, which can be specifically used to discard the asynchronous method if the execution of the asynchronous method fails and the annotation information of the asynchronous method is a default annotation.
[0058] In a specific application scenario, the device also includes an execution reversal module 66, which can be used to re-execute the step of storing the asynchronous method in a database if the asynchronous method fails to execute and the annotation information of the asynchronous method is an execution annotation, until the asynchronous method is executed successfully.
[0059] It should be noted that for other corresponding descriptions of the functional units involved in the asynchronous transaction processing device provided in this embodiment, reference can be made to Figure 4 The corresponding description in will not be repeated here.
[0060] Based on the above Figure 4 The method shown in the embodiment also provides a storage medium on which a computer program is stored. When the program is executed by a processor, the above-mentioned Figure 4 The asynchronous transaction processing method shown.
[0061] Based on this understanding, the technical solution of the present application can be embodied in the form of a software product. The software product to be identified can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present application.
[0062] Based on the above Figure 4 The method shown, and Figure 5 and Figure 6 In order to achieve the above-mentioned purpose, the embodiment of the asynchronous transaction processing device shown in the figure also provides an entity device for asynchronous transaction processing, which can be a personal computer, a server, a smart phone, a tablet computer, a smart watch, or other network devices, etc. The entity device includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-mentioned Figure 4 The method shown.
[0063] Optionally, the physical device may also include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), etc.
[0064] Those skilled in the art will appreciate that the physical device structure for asynchronous transaction processing provided in this embodiment does not constitute a limitation on the physical device, and may include more or fewer components, or a combination of certain components, or different arrangements of components.
[0065] The storage medium may also include an operating system and a network communication module. The operating system is a program that manages the hardware of the physical device and the software resources to be identified, and supports the operation of the information processing program and other software and / or programs to be identified. The network communication module is used to realize the communication between the components inside the storage medium, and the communication with other hardware and software in the information processing physical device.
[0066] Through the description of the above implementation methods, the technicians in this field can clearly understand that the present application can be implemented by means of software plus the necessary general hardware platform, or by hardware. By applying the technical solution of the present application, first, the execution of the asynchronous method for processing asynchronous transactions in the microservice application system is monitored, wherein the asynchronous method has pre-set annotation information, and the annotation information includes an execution annotation; then, it is determined whether the asynchronous method is executed successfully, and whether the annotation information of the asynchronous method is an execution annotation; if the asynchronous method fails to execute, and the annotation information of the asynchronous method is an execution annotation, the asynchronous method is stored in the database; finally, the asynchronous method is scheduled and executed from the database. Compared with the prior art, the above method is based on adding annotation information to the asynchronous method, and based on the queue storage and calling of the asynchronous method in the database, to complete the processing of the asynchronous transaction, so that the framework of the technical solution is neat and clear, and the setting is simple. It can ensure that the asynchronous transaction can be successfully executed without setting up the message middleware, so that the engineering system can effectively reduce the occupied resources when solving asynchronous transactions. At the same time, the technical solution of the present application can adapt to most system scenarios, has strong scalability, and can distinguish between unnecessary asynchronous methods and necessary asynchronous methods in the system. It will not waste too many resources for unnecessary asynchronous methods, and has security and stability for necessary asynchronous methods. It can be freely set based on actual conditions, and is efficient and flexible.
[0067] Those skilled in the art will appreciate that the accompanying drawings are only schematic diagrams of a preferred implementation scenario, and the modules or processes in the accompanying drawings are not necessarily necessary for implementing the present application. Those skilled in the art will appreciate that the modules in the devices in the implementation scenario can be distributed in the devices of the implementation scenario according to the description of the implementation scenario, or can be changed accordingly and located in one or more devices different from the present implementation scenario. The modules of the above-mentioned implementation scenario can be combined into one module, or can be further split into multiple submodules.
[0068] The above serial numbers of this application are only for description and do not represent the advantages and disadvantages of the implementation scenarios. The above disclosure is only a few specific implementation scenarios of this application, but this application is not limited to them, and any changes that can be thought of by technicians in this field should fall within the scope of protection of this application.
Claims
1. An asynchronous transaction processing method, applied to a microservice application system, characterized in that: The method comprises: Monitoring the execution of an asynchronous method for processing asynchronous transactions in the microservice application system, wherein the asynchronous method has preset annotation information, and the annotation information includes an execution annotation; Determine whether the asynchronous method is executed successfully, and determine whether the annotation information of the asynchronous method is an execution annotation; If the asynchronous method fails to execute, and the annotation information of the asynchronous method is an execution annotation, the asynchronous method is stored in a database; Scheduling and executing the asynchronous method from the database, wherein scheduling and executing the asynchronous method from the database comprises: Identifying the number of the microservice application systems executing the asynchronous method; If the number of the microservice application systems is greater than or equal to two, obtaining interface call information between the microservice application systems; Based on the interface call information, a cross-system processing interface between the microservice application systems is established; Based on the cross-system processing interface, the asynchronous method is scheduled from a database of the microservice application system and executed.
2. The method according to claim 1, characterized in that The scheduling and executing of the asynchronous method from the database further includes: Based on a preset detection interval, performing data detection on the database; If data information corresponding to the asynchronous method exists in the database, the asynchronous method is scheduled and executed from the database.
3. The method according to claim 1, characterized in that The annotation information also includes default annotations; Before storing the asynchronous method in a database if the asynchronous method fails to execute and the annotation information of the asynchronous method is an execution annotation, the method further includes: If the asynchronous method fails to execute and the annotation information of the asynchronous method is the default annotation, the asynchronous method is discarded.
4. The method according to any one of claims 1 to 3, characterized in that: After scheduling and executing the asynchronous method from the database, the method further includes: If the asynchronous method fails to execute, the step of storing the asynchronous method in a database if the asynchronous method fails to execute and the annotation information of the asynchronous method is an execution annotation is executed again until the asynchronous method is successfully executed.
5. The method according to any one of claims 1 to 3, characterized in that: The monitoring of the execution of the asynchronous method for processing asynchronous transactions in the microservice application system includes: Set up an aspect programming, and wrap the asynchronous method with the annotation information in the aspect proxy of the aspect programming; The execution status of the asynchronous method in the aspect proxy is monitored.
6. The method according to claim 2, characterized in that After performing data detection on the database based on the preset detection interval, the method further includes: If data information corresponding to the asynchronous method exists in the database, an alarm prompt message is issued.
7. An asynchronous transaction processing device, characterized in that: The device comprises: A data monitoring module, used to monitor the execution of an asynchronous method for processing asynchronous transactions in a microservice application system, wherein the asynchronous method has pre-set annotation information, and the annotation information includes an execution annotation; A data judgment module, used to judge whether the asynchronous method is executed successfully, and to judge whether the annotation information of the asynchronous method is an execution annotation; A data retrieval module, configured to store the asynchronous method in a database if the asynchronous method fails to execute and the annotation information of the asynchronous method is an execution annotation; A data execution module is used to identify the number of the microservice application systems that execute the asynchronous method; if the number of the microservice application systems is greater than or equal to two, obtain interface call information between the microservice application systems; based on the interface call information, establish a cross-system processing interface between the microservice application systems; based on the cross-system processing interface, schedule the asynchronous method from the database of the microservice application system and execute the asynchronous method.
8. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Business execution method and server
CN105912455A