Asynchronous processing method and system under micro-service architecture
By introducing asynchronous processing methods under the microservice architecture, the high R&D and operation and maintenance costs of calling and decoupling between microservice system groups are solved, and strict transaction consistency of business messages is achieved and time-consuming network links is reduced. Reduced operation and maintenance costs.
Patent Information
- Application Number
- CN202411032747.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-11-15
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Under the microservice architecture, the call and decoupling between microservice system groups in the prior art has problems such as high R&D costs, increased network link time consumption and high operation and maintenance costs, especially in distributed transactions and message middleware Deployment aspect.
By introducing asynchronous processing methods under the microservice architecture, the business system performs business actions based on system logic and generates asynchronous pending tasks, submits transactions in a unified manner, avoiding the introduction of additional frameworks or platforms and the consumption of separate server resources, and realizing the business message Production and consumption maintain strict transaction consistency.
Reduces R&D costs, reduces network link time and operation and maintenance costs, improves system reliability and scalability, and avoids the separate deployment and operation and maintenance costs of message middleware.
Smart Images

Figure CN118963926A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software engineering and information technology, and in particular to a method and system for asynchronous processing under a microservice architecture. Background Art
[0002] As digital transformation accelerates, enterprise application software needs to be more flexible to adapt to the unique business processes and management needs of different enterprises, focusing on fast calling, decoupling and reliability between microservice system groups. To this end, the software industry has explored a variety of configurable frameworks and platforms, aiming to customize software functions through configuration rather than hard coding.
[0003] One of the more mature solutions on the market is the Seata framework, which uses the TCC two-phase transaction commit mechanism. TCC is divided into three phases: Try phase: try to execute, complete all business checks, and reserve necessary business resources; Confirm phase: confirm the execution of the real business, use the business resources reserved in the Try phase, and the Confirm operation requires idempotent design, and needs to be retried after failure; Cancel phase: cancel the execution and release the business resources reserved in the Try phase. The exception handling scheme in the Cancel phase is basically the same as that in the Confirm phase, and requires idempotent design. The decoupling solution is usually to decouple the various components in the system by introducing message queues, such as RabbitMQ. Components communicate through messages. The sender sends messages to the message queue, and the receiver obtains messages from the message queue for processing. This method can achieve asynchronous communication and improve the concurrency and reliability of the system.
[0004] However, a business action of the distributed transaction framework requires the original processing function logic to be split into Try service (verification interface), Confi rm service (lock interface), and Cancel (cancel interface); this increases the system development cost and requires the idempotence of each interface; in addition, after the Cancel action fails, the transaction will still have problems and subsequent actions are still required to compensate; and this action is split from the original 1 network call to at least 2 or even 3 network service calls, and the network link time consumption is significantly increased. In terms of application decoupling, the industry often deploys independent third-party middleware, such as RabbitMQ; however, deploying MQ requires separate server resources, and if the MQ platform crashes, all services that rely on this middleware communication will be paralyzed; in addition, the MQ platform operation also has certain operation and maintenance costs. Summary of the invention
[0005] The purpose of the present invention is to provide a method and system for asynchronous processing under a microservice architecture to solve the defects existing in the calling and decoupling between microservice system groups.
[0006] To solve the above problems, the present invention first provides a method for asynchronous processing under a microservice architecture, comprising the following steps: in response to a business action execution request, the first business system executes the corresponding business action based on its system logic, and generates asynchronous pending tasks associated with it, adds it to the asynchronous task database, forms business messages that other business systems can receive accordingly, and submits transactions in a unified manner; the second business system receives the corresponding business message, obtains the asynchronous pending tasks, executes the corresponding business action, and generates asynchronous pending tasks associated with it, adds it to the asynchronous task database, forms business messages that other business systems can receive accordingly, modifies the consumed business message status, and submits transactions in a unified manner.
[0007] Furthermore, it also includes business message identification. The business message has a message type, and the message type can be identified and received by the corresponding business system.
[0008] Furthermore, the business system is configured with corresponding producible message types and is capable of generating business messages of the corresponding message types.
[0009] Furthermore, when executing a corresponding business action, the second business system can identify whether the business action is completed, and reset or delete the business message according to the completion result.
[0010] The present invention also provides a system for asynchronous processing under a microservice architecture, including: a business production module, which responds to a business action execution request, executes a corresponding business action based on its system logic, and produces asynchronous pending tasks associated with it, adds it to an asynchronous task database, forms business messages that other business systems can receive accordingly, and submits transactions in a unified manner; a business consumption module, receives the corresponding business messages, obtains the asynchronous pending tasks, executes the corresponding business actions, and produces asynchronous pending tasks associated with it, adds it to an asynchronous task database, forms business messages that other business systems can receive accordingly, modifies the status of the consumed business messages, and submits transactions in a unified manner.
[0011] Furthermore, the service consumption module also includes service message identification. The service message has a message type, and the message type can be identified and received by the corresponding service system.
[0012] Furthermore, the business production module is configured with corresponding producible message types and is capable of generating business messages of the corresponding message types.
[0013] Furthermore, when executing a corresponding business action, the second business system can identify whether the business action is completed, and reset or delete the business message according to the completion result.
[0014] According to a method and system for asynchronous processing under a microservice architecture provided by the present invention, the production and consumption of business messages of each business system maintain strict transaction consistency, without the need to introduce additional frameworks or platforms, without the need to consume server resources separately, and reducing the operation and maintenance costs of additional investment in message middleware. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0016] Figure 1 A flowchart of a method for asynchronous processing under a microservice architecture provided by an embodiment of the present invention; Figure 2 A schematic diagram of a microservice collaboration scenario for an asynchronous processing method under a microservice architecture provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to make the above-mentioned objects, features and advantages of the present invention more clearly understood, the specific embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0018] The present invention aims to solve the common problems in the enterprise software industry, that is, the original huge monolithic architecture gradually evolves into a microservice architecture. In a more complex business system, a user operation will call the interfaces of N systems one by one in most cases, and in multi-system calls, more complex distributed transaction problems will be involved. For example, the commit action of system A needs to process the business of system A by itself, and at the same time, it needs to call system B, and then call system C. The entire call link is very long. If the processing of system C fails, system AB needs to roll back the data. Although there is a distributed transaction solution, the development and operation cost of the distributed transaction solution is very high in the entire industry.
[0019] In addition, in complex business systems, a business action involves a large number of modules, resulting in a very high degree of module coupling. The maintainability and scalability of the system are very large. As the business functions of the system increase, it becomes increasingly difficult to reduce R&D costs and shorten delivery cycles.
[0020] Example 1
[0021] To solve the above problems, this embodiment provides a method for asynchronous processing under a microservice architecture, such as Figure 1 As shown, the following steps are included:
[0022] In response to the business action execution request, the first business system executes the corresponding business action based on its system logic, and generates an asynchronous pending task associated with it, adds it to the asynchronous task database, forms a business message that can be received by other business systems, and submits the transaction uniformly; the business system is configured with corresponding message types that can be produced, and can generate business messages of corresponding message types;
[0023] Business messages have message types, and the message types can be identified and received by the corresponding business systems. The second business system receives the corresponding business message, obtains the asynchronous pending tasks, executes the corresponding business actions, and produces the asynchronous pending tasks associated with it, adding them to the asynchronous task database, forming business messages that can be received by other business systems, modifying the status of consumed business messages, and submitting transactions in a unified manner. When executing the corresponding business actions, the second business system can identify whether the business actions are completed, and reset or delete the business messages according to the completion results.
[0024] Example 2
[0025] This embodiment provides a system for asynchronous processing under a microservice architecture, including:
[0026] The business production module responds to business action execution requests, executes corresponding business actions based on its system logic, and produces asynchronous pending tasks associated with it, adds them to the asynchronous task database, forms business messages that can be received by other business systems, and submits transactions in a unified manner;
[0027] The business consumption module receives the corresponding business messages, obtains the asynchronous pending tasks, executes the corresponding business actions, and produces the asynchronous pending tasks associated with it, adds them to the asynchronous task database, forms business messages that can be received by other business systems, modifies the status of consumed business messages, and submits transactions in a unified manner.
[0028] Example 3
[0029] This embodiment provides a scenario of collaboration between two microservices using the method of Embodiment 1, such as Figure 2 As shown,
[0030] Specifically, system A performs transfer business, and system B performs accounting business.
[0031] S1. When executing the balance deduction action, the A system first executes its own system logic;
[0032] S2.A system adds asynchronous pending tasks to the asynchronous task database according to the asynchronous processing method under the microservice architecture, such as asynchronous actions of account entry type;
[0033] S3.A system adds asynchronous pending tasks to the asynchronous task database according to the asynchronous processing method under the microservice architecture, such as the SMS asynchronous action associated with the S2 add action.
[0034] S4.A system can add other asynchronous pending tasks to the asynchronous task database. After all are added, other business systems can receive corresponding business messages and submit transactions in a unified manner.
[0035] Among them, the business systems that can produce business messages are all configured with corresponding message types that can be produced, and can only generate business messages of corresponding message types. In addition, the message type can be identified and received by the corresponding business system.
[0036] S5.B The system automatically identifies the message types that the current system can consume, receives the corresponding business messages, and obtains asynchronous pending tasks, such as pulling account entry type actions;
[0037] S6.B system executes the entry action;
[0038] S7.B system generates asynchronous pending tasks associated with the above tasks, such as email type asynchronous tasks; adds them to the asynchronous task database to form business messages that can be received by other business systems;
[0039] S8.B system modifies the status of consumed business messages and submits transactions uniformly.
[0040] When executing the corresponding business action, system B can identify whether the business action is completed and reset or delete the business message according to the completion result.
[0041] Specifically, for the business message production end, when the business system is started, it will automatically identify the message types that the current system can produce, add asynchronous pending tasks, and generate corresponding business messages when business actions are executed. They are stored in the asynchronous task database along with the data consistency of the business system.
[0042] For the business message consumer, when the business system is started, it will automatically identify the message types that the current system can consume, and calculate the signal volume and consumption volume according to the relevant configuration of the consumer, and lock and pull related messages. When the business action is executed, it can identify whether the corresponding action to be processed is completed, and reset or delete the message according to the result. In addition, the reset message can still be consumed again, and finally stored in the asynchronous task database with the data consistency of the business system.
[0043] When producing business messages, the message type can define whether to force production or consumption first, that is, to force control of the timing; the production and consumption ends have non-invasive access; the consumer end can define the consumption amount and isolate different message types; the consumer end can automatically retry based on exceptions and define retry rules; the production and consumption ends maintain strict transaction consistency with the business system without the need to introduce additional frameworks or platforms.
[0044] According to the method and system for asynchronous processing under the microservice architecture provided by the present invention, the production and consumption of business messages of each business system maintain strict transaction consistency, without the need to introduce additional frameworks or platforms, without the need to consume server resources separately, and reducing the operation and maintenance costs of additional investment in message middleware.
[0045] In the description of this embodiment, it should be noted that those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment method can be implemented by instructing the control device through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it may include the processes of the above-mentioned method embodiments, wherein the storage medium may be a memory, a disk, an optical disk, etc.
[0046] Although the present invention is disclosed as above, the present invention is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the scope defined by the claims.
[0047] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0048] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0049] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for asynchronous processing under a microservice architecture, It is characterized in that The following steps are involved: In response to the business action execution request, the first business system executes the corresponding business action based on its system logic, and generates an asynchronous pending task associated with it, adds it to the asynchronous task database, forms a business message that can be received by other business systems, and uniformly submits the transaction; The second business system receives its corresponding business message, obtains the asynchronous pending tasks, executes the corresponding business actions, and generates asynchronous pending tasks associated with it, adds them to the asynchronous task database, forms business messages that other business systems can receive accordingly, modifies the status of consumed business messages, and submits transactions in a unified manner.
2. The method for asynchronous processing under the microservice architecture according to claim 1, It is characterized in that It also includes business message identification. The business message has a message type, and the message type can be identified and received by the corresponding business system.
3. The method for asynchronous processing under the microservice architecture according to claim 2, It is characterized in that The business system is configured with corresponding producible message types and can generate business messages of the corresponding message types.
4. The method for asynchronous processing under the microservice architecture according to claim 1, It is characterized in that When executing the corresponding business action, the second business system can identify whether the business action is completed, and reset or delete the business message according to the completion result.
5. A system for asynchronous processing under a microservice architecture, It is characterized in that include: The business production module responds to business action execution requests, executes corresponding business actions based on its system logic, and produces asynchronous pending tasks associated with it, adds them to the asynchronous task database, forms business messages that can be received by other business systems, and submits transactions in a unified manner; The business consumption module receives the corresponding business messages, obtains the asynchronous pending tasks, executes the corresponding business actions, and produces the asynchronous pending tasks associated with it, adds them to the asynchronous task database, forms business messages that can be received by other business systems, modifies the status of consumed business messages, and submits transactions in a unified manner.
6. The system for asynchronous processing under the microservice architecture according to claim 5, It is characterized in that The service consumption module also includes service message identification. The service message has a message type, and the message type can be identified and received by the corresponding service system.
7. The system for asynchronous processing under the microservice architecture according to claim 5, It is characterized in that The business production module is configured with corresponding producible message types and can generate business messages of the corresponding message types.
8. The system for asynchronous processing under the microservice architecture according to claim 5, It is characterized in that When executing the corresponding business action, the second business system can identify whether the business action is completed, and reset or delete the business message according to the completion result.
Citation Information
Patent Citations
Distributed transaction processing method and device, message producer and consumer system
CN111367628A
Business processing method and device
CN115220877A
Business processing method and device, electronic equipment and storage medium
CN115629848A
Micro-service cluster distributed transaction processing method and related equipment thereof
CN117093588A
Kafka-based asynchronous command processing method for realizing high concurrency and high availability
CN117762495A
