Distributed service processing method, system and device, equipment and storage medium

In a distributed microservice environment, the business call and exception response mechanisms between the first server and the second server are used to solve the problem of low business consistency between microservices, and the business exception rollback and state consistency are achieved, and the stability and accuracy of the system are improved.

CN120186232APending Publication Date: 2025-06-20SF DIGITAL TECH (SHENZHEN) TECH SERVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311763810.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-20
Publication Date
2025-06-20

AI Technical Summary

Technical Problem

In a microservice environment, in distributed service processing, the business consistency between different microservices is low, making it difficult to ensure processing accuracy and stability.

Method used

By establishing a delivery mechanism for service call request and exception response packets between the first server and the second server, rollback and state consistency in service exceptions are achieved. The specific steps include: receiving service call requests, executing local services, detecting service exceptions, rolling back services and generating exception messages, and sending exception response messages for corresponding local services to roll back.

Benefits of technology

It improves the consistency of business processing between distributed microservices, ensuring that when business exceptions occur, business rollbacks can be performed based on exceptions between the associated multi-party servers, thereby improving the stability and accuracy of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120186232A_ABST
    Figure CN120186232A_ABST
Patent Text Reader

Abstract

The invention relates to a distributed service processing method, system and device, equipment and a storage medium. The service calling request is sent to the first server when the second server executes the second local service, and the first server executes the first local service according to the service calling request and sends the first local service to the second server when detecting that the first local service generates service abnormity. And rolling back the first local service, generating an abnormal response message containing the abnormal message identifier, and sending the abnormal response message to the second server, wherein the second server rolls back the second local service according to the abnormal message identifier in the abnormal response message. Compared with a traditional method of independently executing services among a plurality of micro-services, according to the embodiment of the invention, when the first server and the second server execute the associated services and the service execution of one party is abnormal, the abnormal response message is sent to the other party, so that the service execution efficiency is improved. According to the invention, the associated multiple servers execute business rollback based on the exception, and the consistency of business processing between distributed micro-services is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of distributed technologies, and in particular, to a distributed service processing method, system, device, equipment, and storage medium. Background Art

[0002] With the development of Internet technologies, the application of microservice technologies has become increasingly widespread. In a microservice environment, a service can be split into different microservices, so that the service can run in multiple microservices in a distributed manner. To ensure the accuracy of service processing, the information consistency of services in different microservices needs to be maintained. However, processing a service through multiple microservices will lead to a decrease in the consistency between different services in different microservices.

[0003] Therefore, the current distributed service processing method has the defect of low consistency. Summary of the Invention

[0004] Based on this, it is necessary to provide a distributed service processing method, system, device, computer equipment, computer-readable storage medium, and computer program product that can improve the consistency between services for the above technical problems.

[0005] In a first aspect, the present application provides a distributed service processing method, which is applied to a first server. The method includes:

[0006] Receiving a service call request sent by a second server, and executing a corresponding first local service according to the service call request; the service call request is obtained according to a second local service executed by the second server;

[0007] When it is detected that the first local service has a service exception, rolling back the first local service and generating an exception message identifier;

[0008] Generating an exception response message according to the exception message identifier, and sending the exception response message to the second server; the second server is used to roll back a corresponding second local service according to the exception response message.

[0009] In one of the embodiments, the receiving a service call request sent by a second server and executing a corresponding first local service according to the service call request includes:

[0010] Receiving the service call request sent by the second server through a Hypertext Transfer Protocol interface; the service call request includes request parameters;

[0011] Executing a corresponding first local service according to the request parameters.

[0012] In one embodiment, the execution of the corresponding first local service according to the request parameters includes:

[0013] Obtain the corresponding local service processing policy according to the request parameters;

[0014] Execute the first local service according to the local service processing policy.

[0015] In one embodiment, the generation of the exception response message according to the exception message identifier includes:

[0016] Determine the service exception information of the first local service;

[0017] Generate the exception response message according to the exception message identifier and the service exception information.

[0018] In a second aspect, the present application provides a distributed service processing method, which is applied to a second server. The method includes:

[0019] Respond to a service request for a second local service and execute the corresponding second local service;

[0020] Generate a service call request and send it to the first server; the first server is used to execute the corresponding first local service according to the service call request, roll back the first local service and generate an exception message identifier when it detects that the first local service has a service exception, and send the exception response message generated according to the exception message identifier to the second server;

[0021] Roll back the second local service according to the exception response message.

[0022] In one embodiment, the exception response message includes an exception message identifier and service exception information; before rolling back the second local service according to the exception response message, it further includes:

[0023] If the exception message identifier is a preset exception message identifier and the service exception information is the exception information associated with the second local service, roll back the second local service according to the exception message identifier.

[0024] In a third aspect, the present application provides a distributed service processing system, which includes: a first server and a second server;

[0025] The second server is used to respond to a service request for a second local service, execute the corresponding second local service; generate a service call request and send it to the first server;

[0026] The first server is configured to execute a corresponding first local service according to the service call request. When it detects that the first local service has a service exception, it rolls back the first local service and generates an exception message identifier, and sends an exception response message generated according to the exception message identifier to the second server;

[0027] The first server is configured to roll back the second local service according to the exception response message.

[0028] In a fourth aspect, the present application provides a distributed service processing device, which is applied to a first server. The device includes:

[0029] A receiving module, configured to receive a service call request sent by a second server and execute a corresponding first local service according to the service call request; the service call request is obtained according to a second local service executed by the second server;

[0030] A first processing module, configured to roll back the first local service and generate an exception message identifier when it detects that the first local service has a service exception;

[0031] A first sending module, configured to generate an exception response message according to the exception message identifier and send the exception response message to the second server; the second server is configured to roll back a corresponding second local service according to the exception response message.

[0032] In a fifth aspect, the present application provides a distributed service processing device, which is applied to a second server. The device includes:

[0033] A response module, configured to execute a corresponding second local service in response to a service request for the second local service;

[0034] A second sending module, configured to generate a service call request and send it to the first server; the first server is configured to execute a corresponding first local service according to the service call request, roll back the first local service and generate an exception message identifier when it detects that the first local service has a service exception, and send an exception response message generated according to the exception message identifier to the second server;

[0035] A second processing module, configured to roll back the second local service according to the exception response message.

[0036] In a sixth aspect, the present application provides a computer device, including a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, the steps of the above method are implemented.

[0037] In a seventh aspect, the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented.

[0038] In an eighth aspect, the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, the steps of the above method are implemented.

[0039] In the above distributed service processing method, system, device, computer equipment, storage medium and computer program product, when the second server executes the second local service, it sends a service call request to the first server. The first server executes the first local service according to the service call request, and when it detects that the first local service has a service exception, it rolls back the first local service and generates an exception response message containing an exception message identifier and sends it to the second server. The second server rolls back the second local service according to the exception message identifier in the exception response message. Compared with the traditional independent execution of services among multiple microservices, in the embodiments of the present application, when the first server and the second server execute related services, when an exception occurs in the execution of one party's service, by sending an exception response message to the other party, all related multiple servers roll back the service based on the exception, improving the consistency of service processing among distributed microservices. Description of the Drawings

[0040] Figure 1 It is an application environment diagram of the distributed service processing method in an embodiment;

[0041] Figure 2 It is a schematic flowchart of the distributed service processing method in an embodiment;

[0042] Figure 3 It is a schematic flowchart of the distributed service processing method in another embodiment;

[0043] Figure 4 It is a schematic flowchart of the distributed service processing method in yet another embodiment;

[0044] Figure 5 It is a structural block diagram of the distributed service processing device in an embodiment;

[0045] Figure 6 It is a structural block diagram of the distributed service processing device in another embodiment;

[0046] Figure 7 It is an internal structural diagram of the computer equipment in an embodiment. Detailed Embodiments

[0047] In order to make the objectives, technical solutions and advantages of the present application clearer and more understandable, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0048] The distributed service processing method provided by the embodiments of the present application can be applied to an application environment as Figure 1 shown. Among them, the first server communicates with the second server through a network. The first data storage system and the second data storage system can store the data that the first server and the second server need to process respectively. The first data storage system and the second data storage system can be integrated on the first server and the second server respectively, or can be placed on the cloud or other network servers. The second server can execute corresponding local services, and call the local services in the first server based on the local services. When an exception occurs during the execution of the local services by the first server, the local services can be rolled back and a corresponding exception response message can be sent to the second server, and the second server rolls back the corresponding local services according to the exception response message. Among them, both the first server and the second server can be implemented by an independent server or a server cluster composed of multiple servers.

[0049] In one embodiment, as Figure 2 shown, a distributed service processing method is provided. Taking the method applied to the Figure 1 first server as an example, the method includes the following steps:

[0050] Step S202: Receive a service call request sent by the second server, and execute the corresponding first local service according to the service call request; the service call request is obtained according to the second local service executed by the second server.

[0051] Among them, both the first server and the second server can be a type of microservice. The first server and the second server can be used to execute distributed services. And both the first server and the second server can execute corresponding local services, and the first server and the second server can call each other to implement the processing of distributed services, that is, there can be an association between the local services executed by the first server and the local services executed by the second server. Among them, the second server can initiate the second local service, and the second local service can be executed through the corresponding local service processing strategy in the second server. Among them, the second local service can be started by receiving a service request, for example, a user or other server sends a service request to the second server, etc.

[0052] During the execution of the second local service by the second server, due to the distributed principle, it is necessary to call the local services of other servers for collaborative processing, such as the local service of the first server. The second server can generate a corresponding service call request based on the second local service and send the service call request to the first server. When the first server receives the service call request, it can execute the corresponding first local service according to the service call request. Among them, the first local service can also be a part of the distributed service, and the first local service can be a service associated with the second local service. For example, the first local service can be a logistics order statistics service, and the second local service can be a logistics order generation service. When the logistics order generation service generates a logistics order, it needs to call the logistics order statistics service in the first server for order statistics, such as quantity and item type statistics.

[0053] Step S204, when it is detected that a service exception occurs in the first local service, roll back the first local service and generate an exception message identifier.

[0054] Among them, when the first server executes the above first local service, it can continuously detect the execution status of the first local service. When the first server detects that a service exception occurs in the first local service, for example, the first local service throws a system exception. At this time, the first server can process the above first local service with an exception, such as rolling back the above first local service so that the above first local service rolls back to the state before the exception occurs. And, the first server can also generate an exception message identifier when an exception occurs in the first local service. Among them, the exception message identifier can be used to indicate that an exception occurs in the local service in the first server, and the specific content of the exception message identifier can be obtained according to the identifier content set by the first server in advance for local service exceptions, such as numerical information set by the first server in advance for local service exceptions.

[0055] Step S206, generate an exception response message according to the exception message identifier, and send the exception response message to the second server; the second server is used to roll back the corresponding second local service according to the exception response message.

[0056] Among them, when the first server detects an abnormality in the first local service, it can capture the abnormality corresponding to the first local service through unified exception interception and generate a corresponding message. For example, when the first server captures the service abnormality of the above-mentioned first local service, it generates a corresponding exception response message. Among them, the exception response message includes an exception message identifier and the specific exception information of the above-mentioned service exception. Among them, the exception message identifier can represent the identifier of the type of exception. The first server can also send the above-mentioned exception response report message to the second server. The second server can be the server that calls the local service in the first server. A second local service can be running in the second server. Then, after receiving the above-mentioned exception response message, the second server can roll back the second local service corresponding to the first local service according to the exception response message. The first local service can be a service called by the second local service. The second server rolls back the second local service to a time point before the first local service has an abnormality, so as to ensure that the state of the second local service is consistent with the state of the first local service after being rolled back, so that the states of each local service in the distributed service are consistent, and the consistency of the distributed service is improved.

[0057] In the above-mentioned distributed service processing method, when the second server executes the second local service, it sends a service call request to the first server. The first server executes the first local service according to the service call request. When it detects that the first local service generates a service exception, it rolls back the first local service and generates an exception response message containing an exception message identifier and sends it to the second server. The second server rolls back the second local service according to the exception message identifier in the exception response message. Compared with the traditional method of independently executing services between multiple microservices, in the embodiment of the present application, when the first server and the second server execute related services, when an abnormality occurs in the execution of one party's service, by sending an exception response message to the other party, all related multi-party servers roll back the service based on the exception, improving the consistency of service processing between distributed microservices.

[0058] In one embodiment, step S202 includes: receiving a service call request sent by the second server through a Hypertext Transfer Protocol interface; the service call request includes request parameters for the first local service of the first server; and executing the corresponding first local service according to the request parameters.

[0059] In this embodiment, the second server may initiate a call to the local service in the first server. An http (Hypertext Transfer Protocol) interface may be set in the first server, and the second server may call the local service in the first server through the http interface. For example, the second server generates request parameters for the first local service in the first server according to the service requirements of the second local service, and sends a service call request to the first server by calling the http interface. The first server may receive the service call request sent by the second server through the http protocol, obtain the request parameters in the service call request, and execute the corresponding first local service according to the request parameters in the service call request.

[0060] Specifically, the first local service and the second local service may be logistics services. For example, the first local service may be a logistics order statistics service, and the second local service may be a logistics order generation service. Then, the second server may generate request parameters for the logistics order statistics service according to the service requirements of the logistics order generation service, and send a service call request for logistics order statistics to the first server through the http interface. The request parameters may include data such as the order numbers of the logistics orders. Thus, the first server receives the service call request for the logistics order statistics service through the http protocol, and executes the logistics order statistics service according to the request parameters therein, such as performing logistics order statistics based on the order numbers of the logistics orders.

[0061] Both the first server and the second server may be a kind of microservices. The first server and the second server may be implemented based on the springboot technology. Spring Boot is a brand-new framework, and its design purpose is to simplify the initial setup and development process of new Spring applications. This framework uses a specific way for configuration, so that developers no longer need to define boilerplate configurations. When the second server calls the http interface of the first server, it may be called through the FeignClient method. FeignClient is a declarative pseudo Http client. Through FeignClient, mutual remote calls between services can be realized, such as the second server calling some interfaces exposed by the first server. Specifically, the second server may call the http interface in the first server through the FeignClient, so that the first server can receive the service call request sent by the second server, and execute the corresponding first local service according to the request parameters in the service call request.

[0062] Through this embodiment, the first server can receive service invocation requests sent by other servers in the distributed system through the Hypertext Transfer Protocol, thereby realizing the collaborative execution of services in the distributed system and improving the consistency of service execution in the distributed system.

[0063] In one embodiment, step S202 includes: obtaining a corresponding local service processing policy according to the request parameters in the service invocation request; and executing the first local service according to the local service processing policy.

[0064] In this embodiment, the service invocation request may include request parameters for the first local service. Among them, the request parameters may be requests generated when the second local service needs to use the functions of the first local service during the execution of the service. After receiving the service invocation request, the first server can obtain the corresponding local service processing policy according to the request parameters in the service invocation request. Among them, the first server may include multiple local services and multiple local service processing policies, and there may be a one-to-one correspondence between the local services and the local service processing policies. For example, taking the request parameters corresponding to the above-mentioned logistics order statistics service as an example, after the first server receives a call request for the logistics order statistics service, it can obtain the local service processing policy corresponding to the logistics order statistics service based on the request parameters therein, which may specifically include, but are not limited to, strategies such as algorithms for logistics order statistics. The local service processing policy corresponding to the request parameters may be a processing policy for the first local service, and the first server executes the first local service according to the local service processing policy, thereby realizing the startup of the first local service in the first server and realizing the execution of the corresponding local service by the first server through the call of the second server.

[0065] Through this embodiment, the first server can determine the corresponding local service processing policy based on the call of the second server, thereby starting and executing the corresponding first local service in the first server, enabling the collaborative execution of the first local service and the second local service, and improving the consistency of service execution in the distributed system.

[0066] In one embodiment, step S206 includes: determining the service exception information of the first local service; and generating an exception response message according to the exception message identifier and the service exception information.

[0067] In this embodiment, when the above-mentioned first local service throws an exception, the first server can generate a corresponding exception response message according to the exception. Among them, the first server can determine the exception type of the exception according to the service exception information of the exception thrown by the above-mentioned first local service. In addition, the first server can also generate an exception message identifier, indicating that an exception has occurred in the first local service in the first server. After generating the exception message identifier, the first server can generate a corresponding exception response message according to the exception message identifier and the above-mentioned service exception information.

[0068] Specifically, when an exception occurs in the first local service in the first server, the first server can capture the service exception information in the first server through unified exception interception and convert the service exception information into a unified exception response message. Among them, the above-mentioned exception response message can be a message in json format. Then the exception response message corresponding to the above-mentioned first local service can be specifically expressed as: {"code": "0001", "data": ""}, where code represents the exception message identifier, and the specific content of the exception message identifier can be various, and different contents can represent different exception types. For example, the above code: 0001 represents a system exception, that is, an exception occurs in the local service; in some embodiments, code: 0000 represents a successful response of the local service, that is, no exception occurs. The above data represents specific service data, such as the above-mentioned service exception information, and the service data can include but is not limited to objects in formats such as strings, numbers, and json. Then the first server can send the above-generated exception response message, that is, the above {"code": "0001", "data": ""}, to the second server.

[0069] Through this embodiment, the first server can generate a corresponding exception response message by combining the exception message identifier and the service exception information, so that when an exception occurs in the first local service, the second server that calls the first local service in the first server can be notified through the exception response message, so that the second server can perform corresponding processing on the second local service being executed according to the exception response message, improving the consistency of business processing of each server in the distributed service.

[0070] In one embodiment, as Figure 3 shown, a distributed service processing method is provided. Taking the method applied to Figure 1 the second server as an example for description, the method includes the following steps:

[0071] Step S302, in response to a service request for the second local service, execute the corresponding second local service.

[0072] Among them, the second local service can be a service in the second server. The second server can execute the corresponding second local service by responding to a service request. Among them, the second local service can be started by receiving a service request. For example, a user or another server sends a service request to the second server, etc. The first server and the second server can call each other to implement the processing of distributed services, that is, the local services executed by the first server and the local services executed by the second server can be related. The second server can include multiple local services and multiple local service processing strategies, and the local services and the local service processing strategies can correspond one by one. After receiving a service request, the second server can determine the corresponding local service processing strategy according to the local service corresponding to the request, and then execute the corresponding second local service based on the local service strategy.

[0073] Step S304, generate a service call request and send it to the first server; the first server is used to execute the corresponding first local service according to the service call request. When it detects that the first local service generates a service exception, roll back the first local service and generate an exception message identifier, and send the exception response message generated according to the exception message identifier to the second server.

[0074] Among them, during the execution of the second local service by the second server, due to the distributed principle, it is necessary to call the local services of other servers for collaborative processing, such as the local service of the first server, etc. The second server can generate a corresponding service call request based on the second local service and send the service call request to the first server. When the first server receives the service call request, it can execute the corresponding first local service according to the service call request. Among them, the first local service can also be a part of the distributed service, and the first local service can be a service related to the second local service.

[0075] When the first server executes the above-mentioned first local service, it can continuously detect the execution status of the first local service. When the first server detects that the first local service generates a service exception, for example, when the first local service throws a system exception, at this time, the first server can process the above-mentioned first local service with an exception, for example, roll back the above-mentioned first local service so that the above-mentioned first local service rolls back to the state before the exception occurs. And, the first server can also generate an exception message identifier when the first local service generates an exception. Among them, the exception message identifier can be used to indicate that a local service in the first server generates an exception, and the specific content of the exception message identifier can be obtained according to the identifier content set by the first server in advance for local service exceptions. For example, it can be numerical information set by the first server in advance for local service exceptions, etc.

[0076] When the first server detects an exception in the first local service, it can capture the exception corresponding to the first local service through unified exception interception and generate a corresponding message. For example, the first server can capture the service exception of the above-mentioned first local service and generate an exception response message. Among them, the exception response message includes an exception message identifier and the specific exception information of the above service exception. Among them, the exception message identifier can represent the identifier of the type of exception. The first server can also send the above exception response report to the second server.

[0077] Step S306, roll back the second local service according to the exception response message.

[0078] Among them, after receiving the above exception response message, the second server can obtain the exception message identifier in the exception response message and roll back the second local service corresponding to the above first local service according to the exception message identifier in the exception response message. Among them, the first local service can be a service called by the second local service. The second server rolls back the second local service to a time point before the first local service has an exception, so as to ensure that the state of the second local service is consistent with the state of the first local service after being rolled back, so that the states of each local service in the distributed service are consistent, and the consistency of the distributed service is improved.

[0079] In the above distributed service processing method, when the second server executes the second local service, it sends a service call request to the first server. The first server executes the first local service according to the service call request, and when it detects that the first local service generates a service exception, it rolls back the first local service and generates an exception response message containing an exception message identifier and sends it to the second server. The second server rolls back the second local service according to the exception message identifier in the exception response message. Compared with the traditional independent execution of services between multiple microservices, in the embodiment of the present application, when the first server and the second server execute related services, when an exception occurs in the execution of one party's service, by sending an exception response message to the other party, all related multiple-party servers perform service rollback based on the exception, improving the consistency of service processing between distributed microservices.

[0080] In one embodiment, step S304 includes: calling the Hypertext Transfer Protocol interface of the first server; sending the service call request to the first server through the Hypertext Transfer Protocol interface.

[0081] In this embodiment, when the second local service in the second server invokes the first local service in the first server, it can be achieved by invoking the Hypertext Transfer Protocol interface of the first server. After generating the above service invocation request, the second server can invoke the Hypertext Transfer Protocol interface of the first server and send the service invocation request to the first server through the Hypertext Transfer Protocol interface. Specifically, the second server can be invoked in the way of FeignClient. The second server can invoke the Hypertext Transfer Protocol interface in the first server through the above FeignClient, so that the first server can receive the service invocation request sent by the second server and execute the corresponding first local service according to the request parameters in the service invocation request.

[0082] Through this embodiment, the second server can realize the invocation of the local service in the first server by invoking a specific interface in the first server, thereby achieving the effect of improving the execution consistency of each service in the distributed system.

[0083] In one embodiment, before rolling back the second local service according to the exception response message, it further includes: if the exception message identifier is a preset exception message identifier and the service exception information is the exception information associated with the second local service, roll back the second local service according to the exception message identifier.

[0084] In this embodiment, the above exception response message further includes service exception information. After receiving the exception response message returned by the first server, the second server can obtain the exception message identifier and service exception information in the exception response message. And determine the corresponding exception according to the specific content of the exception message identifier. If the second server determines that the above exception message identifier is a preset exception message identifier and the above service exception information is the exception information associated with the second local service, for example, the exception information of the first local service associated with the second local service, then the second server can roll back the above second local service according to the above service exception information, so that the second local service is rolled back to the state before the time point when the first local service has an exception.

[0085] Specifically, after receiving the exception response message, the second server can identify the exception message identifier and the service exception information therein. Among them, the exception response message can be specifically expressed as {"code": "0001", "data": ""}. Then, when the second server detects that the exception message identifier is 0001, it determines that the preset exception message identifier is detected, and further detects whether the service exception information is the exception information corresponding to the first local service. If so, since the service invoked by the second local service is the first local service, the second server can roll back the second local service according to the above service exception information; if not, it means that the above service exception information is not the exception of the first local service invoked by the second local service, and the second server can not perform a rollback process on the second local service.

[0086] Through this embodiment, the second server can roll back the second local service according to the exception response message returned by the first server, so as to achieve the effect of improving the service execution consistency of each service in the distributed system.

[0087] In one embodiment, rolling back the second local service according to the exception response message includes: parsing the exception response message through a decoder to obtain the exception message identifier and the service exception information corresponding to the first local service, and rolling back the second local service according to the service exception information and the exception message identifier.

[0088] In this embodiment, a decoder can be set in the second server. After receiving the exception response message, the second server can parse the exception response message through the above decoder, so as to obtain the exception message identifier in the exception response message and the service exception information corresponding to the exception of the first local service, so that the second local service can perform a rollback according to the service exception information. Taking the first local service as the logistics order statistics service and the second local service as the logistics order generation service as an example, when an exception occurs in the logistics order statistics service, the first server sends an exception response message including the exception message identifier and the logistics order statistics service exception information to the second server. The second server decodes the exception response message through the decoder and detects whether the service exception information therein is the exception information of the logistics order statistics service invoked by the logistics order generation service. If not, it does not process; if so, the second server rolls back the second local service based on the above exception message identifier. Among them, when the second server detects that the service exception information is the exception information of the logistics order statistics service invoked by the logistics order generation service, the second server performs a rollback, which can avoid the problem of inaccurate rollback of the second server and improve the accuracy of synchronous rollback between the first server and the second server. Moreover, the second server performs synchronous rollback based on the service exception information in the first server, which also improves the service execution consistency of each service in the distributed system.

[0089] Specifically, the above decoder can be a Feign decoder. The Feign decoder can be a component inside FeignClient, and its function is to parse the response message of the Hypertext Transfer Protocol and convert the response message into a Java object. Among them, the second server can customize the decoder, so that the second server can convert the above abnormal response message into a local system exception through the above Feign decoder, for example, convert it into an exception corresponding to the second local service in the second server. For example, the second server identifies the abnormal response message through the Feign decoder and gets {"code": "0001", "data": ""}. And by identifying the abnormal message identifier code, it gets code = "0001", so that a local system exception is thrown in the second server through the decoder, enabling the second local service to respond to the exception and perform a transaction rollback, so that the first local service in the first server and the second local service in the second server both perform rollbacks simultaneously.

[0090] Through this embodiment, the second server can parse the abnormal response message through the decoder and convert the exception therein into a local exception in the second server, enabling the corresponding local service to perform a rollback based on this exception, improving the consistency of business execution among various services in the distributed system.

[0091] In one embodiment, as Figure 4 shown, Figure 4 is a schematic flowchart of a distributed service processing method in another embodiment. In this embodiment, it can include two microservices, namely microservice A and microservice B. Among them, microservice A can be the above second server, and microservice B can be the above first server. Both the first server and the second server can be implemented through the springboot technology. Among them, the distributed service processing can include the following steps: The second server can receive a service request. After receiving the service request, the second server can call the local service processing strategy and start the corresponding local service based on this local service processing strategy, such as the above second local service. During the execution of the second local service, the second server can call the Hypertext Transfer Protocol interface in the first server through FeignClient. After receiving the service call request sent by the second server, the first server can obtain the request parameters in the service call request and call the corresponding local service processing strategy based on these request parameters, and start to execute the corresponding local service based on the local service processing strategy, such as the above first local service.

[0092] When the first server detects that an exception occurs in the first local service, the first server can order the first local service to perform a rollback operation. At the same time, the first server can capture the exception in the system through the unified exception interception, convert it into a unified response message, for example, generate a corresponding exception response message based on the above exception message identifier and business exception information. And return the exception response message to the second server. After receiving the exception response message, the second server can parse the exception response message through the Feign decoder to obtain the exception message identifier and business exception information in the exception response message. Furthermore, when the second server identifies that the exception message identifier is the preset exception message identifier, it throws a local system exception for the second local service through the decoder, and performs a business rollback on the second local service based on the thrown exception. Thus, the related local services in the first server and the second server are both rolled back simultaneously, ensuring the consistency between local services.

[0093] Through the above embodiments, when the first server and the second server execute related services, when an exception occurs in the execution of one party's service, by sending an exception response message to the other party, the related multi-party servers all perform service rollbacks based on the exception, improving the consistency of service processing between distributed microservices. Moreover, the above method for processing services is non-invasive to the service system, reducing the usage cost of distributed transactions, and allowing the service system to ensure the consistency of distributed transactions at a low cost in the initial stage of the system architecture.

[0094] It should be understood that although each step in the flowcharts involved in the above embodiments is displayed in sequence according to the indication of the arrows, these steps do not necessarily need to be executed in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages. These steps or stages do not necessarily need to be executed at the same time, but can be executed at different times. The execution order of these steps or stages does not necessarily need to be sequential, but can be executed alternately or in turn with at least a part of other steps or steps or stages in other steps.

[0095] In one embodiment, a distributed service processing system is further provided. The system includes: a first server and a second server; wherein:

[0096] The second server is used to respond to a service request for the second local service, execute the corresponding second local service; generate a service call request and send it to the first server;

[0097] A first server is configured to execute a corresponding first local service according to a service call request. When it detects that the first local service has a service exception, it rolls back the first local service and generates an exception message identifier, and sends an exception response message generated based on the exception message identifier to a second server;

[0098] The first server is configured to roll back a second local service according to the exception response message.

[0099] Among them, the implementation solution provided by this system to solve the problem is similar to the implementation solution described in the above method. Therefore, the specific limitations in the embodiments of the above distributed service processing system can be referred to the limitations on the distributed service processing method in the above text, and will not be elaborated here.

[0100] Based on the same inventive concept, an embodiment of the present application further provides a distributed service processing device for implementing the above-mentioned distributed service processing method. The implementation solution provided by this device to solve the problem is similar to the implementation solution described in the above method. Therefore, the specific limitations in one or more embodiments of the distributed service processing device provided below can be referred to the limitations on the distributed service processing method in the above text, and will not be elaborated here.

[0101] In one embodiment, as Figure 5 shown, a distributed service processing device is provided, including: a receiving module 500, a first processing module 502, and a first sending module 504, where:

[0102] The receiving module 500 is configured to receive a service call request sent by the second server and execute a corresponding first local service according to the service call request; the service call request is obtained according to the second local service executed by the second server.

[0103] The first processing module 502 is configured to roll back the first local service and generate an exception message identifier when it detects that the first local service has a service exception.

[0104] The first sending module 504 is configured to generate an exception response message according to the exception message identifier and send the exception response message to the second server; the second server is configured to roll back the corresponding second local service according to the exception response message.

[0105] In one embodiment, the above first processing module 502 is specifically configured to receive the service call request sent by the second server through a Hypertext Transfer Protocol interface; the service call request includes request parameters; and execute the corresponding first local service according to the request parameters.

[0106] In one embodiment, the above first processing module 502 is specifically configured to obtain a corresponding local service processing policy according to the request parameters; and execute the first local service according to the local service processing policy.

[0107] In one embodiment, the first sending module 504 is specifically configured to determine service exception information of a first local service; and generate an exception response message according to an exception message identifier and the service exception information.

[0108] In one embodiment, as Figure 6 shown, a distributed service processing apparatus is provided, including: a response module 600, a second sending module 602, and a second processing module 604, where:

[0109] The response module 600 is configured to execute a corresponding second local service in response to a service request for a second local service.

[0110] The second sending module 602 is configured to generate a service call request and send it to a first server; the first server is configured to execute a corresponding first local service according to the service call request, and when it detects that a service exception occurs in the first local service, roll back the first local service and generate an exception message identifier, and send an exception response message generated according to the exception message identifier to a second server.

[0111] The second processing module 604 is configured to roll back the second local service according to the exception response message.

[0112] In one embodiment, the second sending module 602 is specifically configured to call a Hypertext Transfer Protocol interface of the first server; and send the service call request to the first server through the Hypertext Transfer Protocol interface.

[0113] In one embodiment, the apparatus further includes: a rollback module, configured to, if the exception message identifier is a preset exception message identifier, and the service exception information is exception information associated with the second local service, roll back the second local service according to the exception message identifier.

[0114] In one embodiment, the second processing module 604 is configured to parse the exception response message through a decoder to obtain the exception message identifier and the service exception information corresponding to the first local service, and roll back the second local service according to the service exception information and the exception message identifier.

[0115] Each module in the above-mentioned distributed service processing apparatus can be implemented in whole or in part by software, hardware, and their combination. Each of the above modules can be embedded in or independent of a processor in a computer device in the form of hardware, or stored in a memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0116] In one embodiment, a computer device is provided. The computer device can be a server, and its internal structure diagram can be as Figure 7As shown in the figure. The computer device includes a processor, a memory, and a network interface connected by a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store local business data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, it implements a distributed service processing method.

[0117] Those skilled in the art can understand that Figure 7 the structure shown in the figure is only a block diagram of some structures related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.

[0118] In one embodiment, a computer device is provided, including a memory and a processor. A computer program is stored in the memory. When the processor executes the computer program, the above-mentioned distributed service processing method is implemented.

[0119] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by the processor, the above-mentioned distributed service processing method is implemented.

[0120] In one embodiment, a computer program product is provided, including a computer program. When the computer program is executed by the processor, the above-mentioned distributed service processing method is implemented.

[0121] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or fully authorized by all parties.

[0122] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in the present application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., and are not limited thereto. The processors involved in the embodiments provided in the present application can be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, data processing logics based on quantum computing, etc., and are not limited thereto.

[0123] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this specification.

[0124] The above-described embodiments merely represent several implementation manners of the present application. The description thereof is relatively specific and detailed, but it should not be construed as a limitation on the patent scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims

1. A distributed service processing method, characterized in that, Applied to a first server, the method includes: Receiving a service invocation request sent by a second server, and executing a corresponding first local service according to the service invocation request; the service invocation request is obtained according to a second local service executed by the second server; When it is detected that a service exception occurs in the first local service, rolling back the first local service and generating an exception message identifier; Generating an exception response message according to the exception message identifier, and sending the exception response message to the second server; the second server is used to roll back a corresponding second local service according to the exception response message.

2. The method according to claim 1, characterized in that, The step of receiving a service invocation request sent by a second server and executing a corresponding first local service according to the service invocation request includes: Receiving the service invocation request sent by the second server through a Hypertext Transfer Protocol interface; the service invocation request includes request parameters; Executing a corresponding first local service according to the request parameters.

3. The method according to claim 2, characterized in that, The step of executing a corresponding first local service according to the request parameters includes: Obtaining a corresponding local service processing policy according to the request parameters; Executing the first local service according to the local service processing policy.

4. The method according to any one of claims 1 to 3, characterized in that, The step of generating an exception response message according to the exception message identifier includes: Determining service exception information of the first local service; Generating the exception response message according to the exception message identifier and the service exception information.

5. A distributed service processing method, characterized in that, Applied to a second server, the method includes: Responding to a service request for a second local service, and executing a corresponding second local service; Generating a service invocation request and sending it to the first server; the first server is used to execute a corresponding first local service according to the service invocation request, when it is detected that a service exception occurs in the first local service, rolling back the first local service and generating an exception message identifier, and sending an exception response message generated according to the exception message identifier to the second server; Rolling back the second local service according to the exception response message.

6. The method according to claim 5, characterized in that, The exception response message further includes service exception information; before rolling back the second local service according to the exception response message, it further includes: If the exception message identifier is a preset exception message identifier, and the service exception information is exception information associated with the second local service, rolling back the second local service according to the exception message identifier.

7. A distributed service processing system, characterized in that, The system includes: a first server and a second server; The second server is used to respond to a service request for a second local service, and execute a corresponding second local service; generate a service invocation request and send it to the first server; The first server is used to execute a corresponding first local service according to the service invocation request, when it is detected that a service exception occurs in the first local service, rolling back the first local service and generating an exception message identifier, and sending an exception response message generated according to the exception message identifier to the second server; The first server is used to roll back the second local service according to the exception response message.

8. A distributed service processing device, characterized in that, Applied to a first server, the apparatus includes: A receiving module, configured to receive a service invocation request sent by a second server and execute a corresponding first local service according to the service invocation request; the service invocation request is obtained based on a second local service executed by the second server; A first processing module, configured to roll back the first local service and generate an exception message identifier when it detects that the first local service has a service exception; A first sending module, configured to generate an exception response message according to the exception message identifier and send the exception response message to the second server; the second server is configured to roll back a corresponding second local service according to the exception response message.

9. A distributed service processing device, characterized in that, Applied to a second server, the apparatus includes: A response module, configured to execute a corresponding second local service in response to a service request for the second local service; A second sending module, configured to generate a service invocation request and send it to a first server; the first server is configured to execute a corresponding first local service according to the service invocation request, roll back the first local service and generate an exception message identifier when it detects that the first local service has a service exception, and send an exception response message generated according to the exception message identifier to the second server; A second processing module, configured to roll back the second local service according to the exception response message.

10. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

11. A computer-readable storage medium, having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, the steps of the method according to any one of claims 1 to 6 are implemented.

12. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, the steps of the method according to any one of claims 1 to 6 are implemented.