Service calling method and device
By obtaining the service call relationship information set and using multiple threads to call services, the problem of inflexible combination service methods in the existing technology is solved, efficient and flexible service calls are achieved, and code rewriting and process platform dependence are avoided.
Patent Information
- Application Number
- CN202010974484.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-16
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2040-09-16
AI Technical Summary
In the prior art, the combined service method is not flexible. When a user requests to call multiple services, he needs to change the process platform and rewrite the code, and it is impossible to easily call multiple services involved in the business.
By obtaining the service call relationship information set of the target service, multiple threads are used to call multiple services involved in the target service in turn, achieving efficient and flexible service calls without relying on the process platform for encapsulation of combined services.
It realizes efficient and flexible calls to multiple services involved in the target business requested by the user, avoids code rewriting and process platform dependence, and improves business call efficiency.
Smart Images

Figure CN112099973B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present specification relate to the field of data processing technology, and in particular to a service calling method and device. Background Art
[0002] Since the system scale of large commercial banks is often very large, the number of transaction businesses in all product systems can sometimes reach tens of thousands. Therefore, in order to adapt to the rapid growth of business and the iterative updates of the system, the system gradually shifts from a centralized architecture to a distributed service architecture, and all transaction interfaces are service-oriented. The distributed service architecture effectively solves the problems of performance expansion, agile iterative upgrades, etc. in the centralized architecture. However, when users request some services, they need to call multiple services to complete them, that is, multiple services involved in the business need to be combined to realize a business process.
[0003] The combined service method in the prior art usually implements the combined management of services through a process platform. The basic principle of its implementation is to use the function of the process platform to encapsulate multiple services involved in a business into one service for business call, thereby realizing the integrated call of services. The existing combined service method mainly relies on the process platform. If the process platform is replaced, the code of the combined service needs to be rewritten for each business, which is not flexible. In addition, when the combined service corresponding to the existing business changes or a new business emerges, the combined service code of the business needs to be rewritten, which makes it impossible to conveniently call multiple services involved in the business using the existing combined service method.
[0004] To address the above problems, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present specification provide a service calling method and device to solve the problem of conveniently calling multiple services involved in a business in the prior art.
[0006] An embodiment of the present specification provides a service calling method, comprising: in response to a target business request initiated by a user, obtaining a service calling relationship information set of the target business; wherein the service calling relationship information set of the target business includes calling relationships of multiple services involved in the target business; and according to the calling relationships of the multiple services involved in the target business, using multiple threads to sequentially call the multiple services involved in the target business.
[0007] The embodiment of this specification also provides a service calling device, including: a processing module, used to respond to a target business request initiated by a user, and obtain a service calling relationship information set of the target business; wherein the service calling relationship information set of the target business includes the calling relationship of multiple services involved in the target business; and a calling module, used to use multiple threads to call the multiple services involved in the target business in sequence according to the calling relationship of the multiple services involved in the target business.
[0008] The embodiment of the present specification also provides a computer-readable storage medium on which computer instructions are stored, and when the instructions are executed, the steps of the service calling method are implemented.
[0009] The embodiment of this specification provides a service calling method, which can obtain a service calling relationship information set of the target business in response to a target business request initiated by a user. Since the service calling relationship information set of the target business includes the calling relationship of multiple services involved in the target business, multiple services involved in the target business can be called in sequence using multiple threads according to the calling relationship of multiple services involved in the target business, without relying on any process platform for encapsulation of combined services, and multiple services involved in the target business requested by the user can be efficiently and flexibly called. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The drawings described herein are used to provide a further understanding of the embodiments of this specification, constitute a part of the embodiments of this specification, and do not constitute a limitation of the embodiments of this specification. In the drawings:
[0011] Figure 1 It is a structural diagram of a service calling system provided according to an embodiment of this specification;
[0012] Figure 2 It is a schematic diagram of the steps of the service calling method provided in the embodiment of this specification;
[0013] Figure 3 It is a structural diagram of a service calling device provided according to an embodiment of this specification;
[0014] Figure 4 It is a structural diagram of a service calling device provided according to an embodiment of this specification. DETAILED DESCRIPTION
[0015] The principles and spirit of the embodiments of this specification will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement the embodiments of this specification, and are not intended to limit the scope of the embodiments of this specification in any way. On the contrary, these embodiments are provided to make the disclosure of the embodiments of this specification more thorough and complete, and to fully convey the scope of the disclosure to those skilled in the art.
[0016] Those skilled in the art know that the implementation of the embodiments of this specification can be implemented as a system, device, method or computer program product. Therefore, the embodiments disclosed in this specification can be specifically implemented in the following forms, namely: complete hardware, complete software (including firmware, resident software, microcode, etc.), or a combination of hardware and software.
[0017] Although the processes described below include multiple operations that occur in a particular order, it should be clear that these processes may include more or fewer operations, which may be performed sequentially or in parallel (eg, using parallel processors or a multi-threaded environment).
[0018] In a scenario example of the present application, a service calling system is provided, such as Figure 1 As shown, it may include: a terminal device 101 and a server 102, and a user may initiate a target service request through the terminal device 101. The server 102 may respond to the user submitting the target service request, obtain the service call relationship information set of the target service, and use multiple threads to sequentially call multiple services involved in the target service according to the call relationship of multiple services involved in the target service, so as to realize efficient and flexible calling of multiple services involved in the target service without relying on any process platform. In some scenario examples, the server 102 may also feed back the execution results of multiple services involved in the called target service to the terminal device 101.
[0019] The terminal device 101 may be a terminal device or software operated by a user. Specifically, the terminal device may be a terminal device such as a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart watch or other wearable device, or a robot device, etc. Of course, the terminal device 101 may also be software that can run in the terminal device. For example: system applications, payment applications, browsers, WeChat applets and other application software.
[0020] The server 102 can be a single server or a server cluster. Of course, the server function can also be realized through cloud computing technology. The server 102 can be connected to multiple terminal devices, or it can be a server with a powerful information set library. It can obtain the service call relationship information set of the target business based on the target business request initiated by the user, and use multiple threads to call the multiple services involved in the target business in sequence according to the call relationship of the multiple services involved in the target business, so that it can realize the flexible call of multiple services involved in the target business efficiently without relying on any process platform.
[0021] See also Figure 2 This embodiment can provide a service calling method. The service calling method can be used to call multiple services involved in the target business in sequence using multiple threads based on the target business request initiated by the user according to the calling relationship of multiple services involved in the target business, so as to realize efficient and flexible calling of multiple services involved in the target business. The above service calling method can include the following steps.
[0022] S201: In response to a target service request initiated by a user, obtain a service call relationship information set of the target service; wherein the service call relationship information set of the target service includes call relationships of multiple services involved in the target service.
[0023] In this embodiment, in response to the target service request issued by the user, the service call relationship information set of the target service is obtained. In some embodiments, it can be a server for processing service requests and resource scheduling in an institution such as a bank that responds to the target service request issued by the user, or it can be a process that responds to the target service request issued by the user. The specific information can be determined according to the actual situation, and this application does not limit this.
[0024] In this embodiment, the target service request may be a request issued by a user for a target service, and the target service request may be transmitted in the form of a message. The target service may be a service that a user desires to achieve. In a scenario example, the target service may include: transfer, deposit, withdrawal, balance inquiry, credit card application, loan application, etc. Of course, the target service is not limited to the above examples. The technical personnel in the relevant field may make other changes under the inspiration of the technical essence of the embodiments of this specification, but as long as the functions and effects achieved are the same or similar to those of the embodiments of this specification, they shall be covered within the protection scope of the embodiments of this specification.
[0025] In this embodiment, since the completion of a business may require calling multiple services in a certain order, after receiving the target business request initiated by the user, a service call relationship information set of the target business can be obtained, wherein the service call relationship information set of the target business includes the call relationship of multiple services involved in the target business. In the case where the target business is a transfer business, the multiple services involved in the transfer business may include but are not limited to: transfer function, registration information, accumulated quota and other services.
[0026] In this embodiment, the multiple services involved in the target business and the call relationship of the multiple services involved in the target business can be determined according to the service call relationship information set of the target business. The call relationship of the multiple services can be the calling mode, sequence, etc. of each service. The service calling mode can include at least one of the following: serial and parallel. Among them, when the service calling mode is serial, it is characterized that the service is synchronous calling, and when the service calling mode is parallel, it is characterized that the service is asynchronous calling. Synchronous calling is a blocking calling mode, that is, the main caller code is blocked and waits until the callee returns. Assuming that the page needs to do three things: A, B, and C, the synchronous calling mode is generally to do B after A, and then do C after B; while asynchronous calling is to start doing A, and start doing B before A is finished, and start doing C before B is finished. If all three things take 5s, it takes at least 15s to complete by using the synchronous calling mode, while it may be completed in at least 5s if it is asynchronous, so the efficiency of asynchronous calling is higher than that of synchronous calling. However, asynchronous calling is only applicable to the situation where the services to be called are not related to each other. If there are associations and interdependencies, for example, B must be called after A is executed, and C must be called after B is executed, then a synchronous call method is required.
[0027] In this embodiment, the service call relationship information set of the target business may also include characteristic information related to each service, such as: service ID (identity), whether to wait synchronously, etc. The service ID may be a character string, and a service may be uniquely identified by the service ID; the whether to wait synchronously may be used to identify whether the calls of multiple services involved in the target business are synchronously waiting for processing results.
[0028] In one embodiment, the service call relationship information sets of each service that can be provided in the system can be pre-stored in a preset database. When the initiated target service request is received, the service call relationship information set of the target service can be obtained from the preset database according to the target service request. Among them, the above-mentioned preset database can be a database storing business data in a bank or other institution. Of course, it can be understood that other possible ways can also be used to obtain the service call relationship information set of the above-mentioned target service, for example, searching for the service call relationship information set of the target service in a web page according to certain search conditions. The specific method can be determined according to the actual situation, and the embodiments of this specification are not limited to this.
[0029] In some embodiments, the target service request may include identification information of the target service, so that the service to be processed can be uniquely determined according to the identification information of the target service.
[0030] S202: according to the calling relationship of multiple services involved in the target business, use multiple threads to sequentially call multiple services involved in the target business.
[0031] In this embodiment, since the service call relationship information set of the target business includes the call relationships of multiple services involved in the target business, multiple services involved in the target business can be called sequentially using multiple threads according to the call relationships of multiple services involved in the target business.
[0032] In this embodiment, the plurality of threads and the plurality of services may correspond one to one, that is, one thread may be used to call and process one service. Of course, in the case of synchronous calling, one thread may be used to call and process one service, which may be determined according to actual conditions, and this application does not limit this.
[0033] In this embodiment, the above-mentioned multiple threads can be created simultaneously or in sequence. For example, when confirming that the current service has been successfully called or successfully executed, a thread for the next service of the current service can be created, and the above steps can be repeated cyclically until the multiple services involved in the target business have been called. Of course, the method of using multiple threads to sequentially call multiple services involved in the target business is not limited to the above examples. Technicians in the relevant field may make other changes under the inspiration of the technical essence of the embodiments of this specification, but as long as the functions and effects achieved are the same or similar to the embodiments of this specification, they should be covered within the protection scope of the embodiments of this specification.
[0034] In this embodiment, the thread is a term in operating system technology, and is the smallest unit that the operating system can perform computational scheduling. It is included in the process and is the actual operation unit in the process. A process is a memory area that contains certain resources. The operating system uses the process to divide its work into some functional units. One or more execution units contained in the process are called threads. A thread refers to a single sequential control flow in the process. Multiple threads can be run in parallel in a process, and each thread can execute different tasks in parallel.
[0035] From the above description, it can be seen that the embodiments of this specification achieve the following technical effects: in response to a target business request initiated by a user, a service call relationship information set of the target business can be obtained. Since the service call relationship information set of the target business contains the call relationship of multiple services involved in the target business, multiple services involved in the target business can be called in sequence using multiple threads according to the call relationship of multiple services involved in the target business, without relying on any process platform to encapsulate the combined service, so that multiple services involved in the target business requested by the user can be efficiently and flexibly called.
[0036] In one embodiment, based on the calling relationship of multiple services involved in the target business, multiple services involved in the target business are called in sequence using multiple threads, which may include: creating a thread of the current service based on the calling relationship of multiple services involved in the target business, wherein the current service is the service that needs to be called currently. Furthermore, based on the reflection mechanism, the thread of the current service may be used to call the current service, and when it is determined that the current service is a synchronous call based on the service calling relationship information set of the target business, the thread of the next service of the current service may be created based on the calling relationship of multiple services involved in the target business when it is determined that the current service has been successfully executed. The thread of the next service of the current service may be used as the thread of the current service until the calls of multiple services involved in the target business are completed.
[0037] In this implementation, there is a one-to-one correspondence between the multiple services and the multiple threads. Each created thread is only used to process its corresponding service, and the resources of the thread can be released after the corresponding service is successfully executed.
[0038] In this embodiment, since a synchronous call needs to wait for the current service to be executed before calling the next service, when it is determined that the current service is a synchronous call, a thread for the next service of the current service can be created based on the calling relationship of multiple services involved in the target business when it is determined that the current service has been successfully executed. The thread of the next service of the current service can then be used to call and execute the next service of the current service, and the above steps can be repeated until all multiple services involved in the target business have been called.
[0039] In this embodiment, reflection refers to a type of application whose reflection mechanism can be self-described and self-controlled. That is, such applications use a certain mechanism to achieve self-representation and examination of their own behavior, and can adjust or modify the state and related semantics of the behavior described by the application according to the state and results of their own behavior. In one embodiment, the current service can be called by the thread of the current service based on the reflection mechanism.
[0040] In one embodiment, in the process of using multiple threads to sequentially call multiple services involved in the target business, if it is determined that one service has not been successfully called or executed, the thread processing can be terminated, and the compensation services of the multiple services involved in the target business can be sequentially called by multiple threads in the reverse order of the calling order of the multiple services involved in the target business.
[0041] In this embodiment, the compensation services of the multiple services involved in the target business are called in the reverse order of the calling order of the multiple services involved in the target business, so as to ensure the continuity and consistency of the data. The above compensation service can be a directional service for a service, and can also be called a reversal service (a remedial measure taken when the system considers that a failure may occur), wherein the calling of the above compensation service needs to be in a serial manner.
[0042] In one embodiment, after the current service is called by the thread of the current service based on the reflection mechanism, the following may be included: when the current service is determined to be an asynchronous call according to the service call relationship information set of the target business, a thread of the next service of the current service is created according to the call relationship of multiple services involved in the target business. Furthermore, the thread of the next service of the current service may be used as the thread of the current service until the calls of multiple services involved in the target business are completed.
[0043] In this embodiment, since the asynchronous call can call the next service of the current service without waiting for the current service to be successfully executed, after determining that the current service has been successfully called, the thread of the next service of the current service can be created according to the calling relationship of multiple services involved in the target business, and the thread of the next service of the current service can be used to call the next service of the current service. The above steps can be executed in a loop until all multiple services involved in the target business have been called.
[0044] In one embodiment, messages may be used to transmit information. Therefore, before the service is called by the thread of the current service based on the reflection mechanism, the method may further include: reading the message configuration information set of the current service, wherein the message configuration information set includes configuration information of the input message and the output message of the current service configured in the form of metadata. Furthermore, the request message and the target response message of the current service may be constructed according to the message configuration information set of the current service, wherein the request message and the target response message are transmitted in the form of MAP.
[0045] In this embodiment, the MAP is a container for storing a number of elements, which are composed of a pair of a key value and a mapping value, and can be used to flexibly store and retrieve data. The MAP can provide a one-to-one (the first one can be called a keyword, each keyword can only appear once in the MAP, and the second one is called the value of the keyword) data processing capability.
[0046] In this embodiment, the message configuration information set of each service can be pre-configured and stored in a preset database. The message is a data unit exchanged and transmitted in the network, that is, a data block to be sent by a station at one time. The message contains the complete data information to be sent, and its length is inconsistent, and the length is unlimited and variable. The above-mentioned message configuration information set can be displayed and stored in the form of a table, image or text, and the message configuration information set can be stored in a preset database for easy reading and modification. Among them, the above-mentioned preset database can be a database for storing business data in a bank or other institution.
[0047] In this embodiment, since a standard format of a message is required before the message is transmitted, the above-mentioned message configuration information set may include configuration information of the input message and output message of the current service, wherein the configuration information of the input message and output message of the current service may be used to characterize the standard format of the request message that needs to be sent to call the current service and the standard format of the corresponding message generated when the current service is successfully executed. Of course, it is understandable that the above-mentioned message configuration information set may also include other information, such as: service ID (identity identification), the above-mentioned service ID may be a string, and a service may be uniquely identified by the service ID.
[0048] In this embodiment, the request message and target response message of the current service can be constructed according to the configuration information of the input message and the output message of the current service. The target response message can be a message that needs to be generated when the current service is successfully executed, so that it can be judged whether the current service is successfully executed according to the target response message.
[0049] In this embodiment, the above-mentioned input message and output message can be configured in the form of metadata. The metadata and its types adopt a unified naming and definition specification. Each metadata has a unique name, and its definition type adopts a unified data standard. Metadata is mainly information that describes data attributes, and is used to support functions such as indicating storage location, historical data, resource search, and file records. Its most essential and abstract definition is: data about data, which is a widely existing phenomenon and has specific definitions and applications in many fields. Of course, it can be understood that in some embodiments, other methods can also be used to configure the above-mentioned input message and output message. The specific method can be determined according to actual conditions, and this application does not limit this.
[0050] In this implementation, correspondingly, based on the reflection mechanism, using the thread of the current service to call the current service may include: based on the reflection mechanism, using the request message and thread of the current service to call the current service.
[0051] In one embodiment, since resources for processing the target business request need to be allocated before processing the target business request, before obtaining the service call relationship information set of the target business in response to the target business request initiated by the user, it can also include: calling a service call process according to the target business request, wherein the service call process is used to execute the call processing of multiple services involved in the target business. Further, in the case where the target business request involves an asynchronous call, an asynchronous service receiving process can be called, wherein the asynchronous service receiving process is used to receive the result returned by the asynchronously called service, and information is exchanged between the service calling process and the asynchronous service receiving process through a message mechanism.
[0052] In this embodiment, the service calling process can be used to call multiple services involved in implementing the target business according to the service calling relationship information set of the target business. Since the asynchronous call can call the next service immediately without waiting for the call result of the current service, the asynchronous service receiving process is required to receive the result returned by the asynchronously called service, so as to determine whether the asynchronously called service is successfully executed.
[0053] In this embodiment, in order to enable the asynchronous service receiving process to send the result returned by the received asynchronously called service to the service calling process, the service calling process and the asynchronous service receiving process exchange information through a message mechanism.
[0054] Among them, since all events that occur can be represented by messages, messages are used to tell the operating system what happened, and the parameters of the message contain important information. The message mechanism can be used to maintain a message queue for the asynchronous service receiving process. After the asynchronous service receiving process receives the result returned by the asynchronously called service, the asynchronous service receiving process can convert the event into a message and put the message into the message queue. Furthermore, the message can be taken out of the message queue through the message loop. The task of the message loop is to retrieve the message from the message queue and then pass the message to the appropriate process.
[0055] In one embodiment, based on the calling relationship of multiple services involved in the target business, multiple services involved in the target business are called in sequence using multiple threads, which may include: the service calling process creates a thread of the current service based on the calling relationship of multiple services involved in the target business, wherein the current service is the service that needs to be called currently. Further, the thread of the current service calls the current service based on a reflection mechanism, and when it is determined that the current service is a synchronous call based on the service calling relationship information set of the target business, the thread of the current service sends the calling result of the current service to the service calling process upon receiving the calling result of the current service. When the service calling process determines that the current service has been successfully executed based on the calling result of the current service, it creates a thread of the next service of the current service based on the calling relationship of multiple services involved in the target business, and uses the thread of the next service of the current service as the thread of the current service until the calls of multiple services involved in the target business are completed.
[0056] In this implementation, there is a one-to-one correspondence between the multiple services and the multiple threads. Each created thread is only used to process its corresponding service, and the resources of the thread can be released after the corresponding service is successfully executed.
[0057] In this embodiment, since a synchronous call needs to wait for the current service to be executed before calling the next service, when it is determined that the current service is a synchronous call, a thread for the next service of the current service can be created based on the calling relationship of multiple services involved in the target business when it is determined that the current service has been successfully executed. The thread of the next service of the current service can then be used to call and execute the next service of the current service, and the above steps can be repeated until all multiple services involved in the target business have been called.
[0058] In one embodiment, after the thread of the current service calls the current service based on the reflection mechanism, the service calling process can determine the calling order of multiple services involved in the target business according to the service calling relationship information set of the target business when it is determined that the current service is not successfully executed. Further, the service calling process sequentially calls the compensation services of each service involved in the target business using multiple threads in the reverse order of the calling order of the multiple services involved in the target business.
[0059] In this embodiment, the compensation services of the multiple services involved in the target business are called in the reverse order of the calling order of the multiple services involved in the target business, so as to ensure the continuity and consistency of the data. The above compensation service can be a directional service for a service, and can also be called a reversal service (a remedial measure taken when the system considers that a failure may occur), wherein the calling of the above compensation service needs to be in a serial manner.
[0060] In one embodiment, in order to enable each called service-related information to be queried, after the thread of the current service calls the current service based on the reflection mechanism, it may also include: when it is determined that the current service is a synchronous call according to the service call relationship information set of the target business, the thread of the current service generates a service flow for the current service according to the call result of the current service when receiving the call result of the current service, and stores the service flow of the current service in a preset database.
[0061] In this embodiment, the above service flow can be used to characterize the calling and execution of the service. In some embodiments, the above service flow may include but is not limited to: service ID, input message, output message, service execution result, and ID of the previous calling service of the current service.
[0062] In this embodiment, the preset database may be a database storing business data in a bank or other institution.
[0063] In one embodiment, after the thread of the current service calls the current service based on the reflection mechanism, it may also include: when the current service is determined to be an asynchronous call according to the service call relationship information set of the target business, the thread of the current service sends the call result of the current process to the service call process, and when the service call process determines that the current process has been successfully called according to the call result of the current process, the thread of the next service of the current service may be created according to the call relationship of multiple services involved in the target business. Furthermore, the thread of the next service of the current service may be used as the thread of the current service until the calls of multiple services involved in the target business are completed.
[0064] In this embodiment, the above call result can be used to indicate whether the service is successfully called, and the call result can be used to indicate whether the service is successfully executed. In the asynchronous call scenario, after confirming that the current service has been successfully called, the thread of the next service of the current service can be created through the service call process according to the call relationship of multiple services involved in the target business.
[0065] In this embodiment, since the asynchronous call can call the next service of the current service without waiting for the current service to be successfully executed, after determining that the current service has been successfully called, the thread of the next service of the current service can be created according to the calling relationship of multiple services involved in the target business, and the thread of the next service of the current service can be used to call the next service of the current service. The above steps can be executed in a loop until all multiple services involved in the target business have been called.
[0066] In one embodiment, after the thread of the current service sends the call result of the current process to the service calling process, it may also include: when the asynchronous service receiving process determines that the call result returned by the thread of the current service has been successfully received, the asynchronous service receiving process generates a response message of the current service according to the service call relationship information set of the target business and the call result of the current service. Further, the asynchronous service receiving process puts the response message of the current service into the target message queue, and the service calling process determines whether the current service is successfully executed according to the response message of the current service in the target message queue. When it is determined that the current service is successfully executed, the call process of the current service is terminated.
[0067] In this embodiment, since the service call relationship information set of the target business includes a pre-configured output message, a response message of the current service can be generated according to the service call relationship information set of the target business and the call result of the current service.
[0068] In this embodiment, when the asynchronous service receiving process successfully receives the call result returned by the thread of the current service, it can make a preliminary judgment on the call result returned by the thread of the current service in advance. Since the output message configured in the service call relationship information set of the target business is the message that responds normally when the current service is successfully executed, when it is determined that the current service is successfully executed, the response message of the current service can be directly generated according to the service call relationship information set of the target business and the call result of the current service; when it is determined that the current service is not successfully executed, the output message configured in the service call relationship information set of the target business can be adjusted according to the call result of the current service, thereby generating a response message of the current service.
[0069] In this implementation, when it is determined that the current service is successfully executed, the thread resources of the current service may be released, thereby terminating the calling process of the current service.
[0070] In one embodiment, in order for the service calling process to determine whether the current service is successfully executed according to the response message of the current service in the target message mechanism, it may also include: if it is determined that the current service is not successfully executed, the calling order of multiple services involved in the target business is determined according to the service calling relationship information set of the target business, and the service calling process sequentially calls the compensation service of the characteristic service involved in the target business using multiple threads in the reverse order of the calling order of the multiple services involved in the target business. Among them, the characteristic service is the service involved in the target business that needs to call the compensation service.
[0071] In this embodiment, the service calling process calls the compensation service of at least one feature service involved in the target business in sequence using multiple threads in reverse order of the calling order of the multiple services involved in the target business, which may include: the service calling process reads multiple service flow lines involved in the target business from a preset database, and further, recreates multiple threads in sequence according to the service flow lines of each feature service in reverse order of the calling order of the multiple services involved in the target business, and calls the compensation service of the feature service involved in the target business in sequence using the recreated multiple threads in sequence.
[0072] In this embodiment, the compensation service of the feature service involved in the target business is called in sequence by using the recreated multiple threads, which may include: the thread of the target feature service determines the compensation service ID of the target feature service according to the target feature service ID in the service flow of the target feature service. Further, based on the reflection mechanism, the compensation service of the target feature service may be called according to the compensation service ID of the target feature service until the compensation service call of at least one feature service involved in the target business is completed.
[0073] In this embodiment, since the thread of the current service can generate a service flow of the current service according to the call result of the current service when receiving the call result of the current service, and store the service flow of the current service in the preset database, before calling the compensation service, multiple service flows of the target business history records can be obtained from the preset database.
[0074] In this embodiment, the above service flow can be used to characterize the calling and execution of the service. In some embodiments, the above service flow may include but is not limited to: service ID, input message, output message, service execution result, and ID of the previous calling service of the current service.
[0075] In this embodiment, since multiple threads are recreated based on the service flow of each feature service, there is no service flow record for the services that are not called among the multiple services involved in the target business. Therefore, it is only necessary to execute the compensation services in reverse order starting from the failed service, without executing the corresponding compensation services from the last service among the multiple services involved in the target business.
[0076] In this embodiment, a compensation service information set can be pre-set and stored in a preset database to configure the correspondence between each service and its compensation service. The compensation service information set may include: service ID, service name, whether compensation service is required (identifying whether the service requires compensation service), compensation service ID (if no compensation service is required, it is not configured, that is, the compensation service ID can be directly the ID of the service).
[0077] In this embodiment, the compensation service ID of the target feature service can be determined according to the compensation service information set and the target feature service ID, so that the compensation service of the target feature service can be called according to the compensation service ID of the target feature service.
[0078] In this embodiment, since the service flow of the feature service includes the input message and output message of the service, before calling the compensation service of the target feature service, the request message and response message of the compensation service of the target feature service can also be constructed according to the service flow of the feature service. Correspondingly, the compensation service of the target feature service can be called according to the constructed request message.
[0079] In this embodiment, after calling the compensation service of the target feature service, you can wait for the calling result of the compensation service. When it is determined that the compensation service of the target feature service is successfully executed, you can continue to call the compensation service of the next feature service in reverse order until the compensation services of all feature services involved in the target business have been successfully executed.
[0080] In one embodiment, if the compensation service fails to execute, the call can continue to be attempted, or a prompt of abnormal execution of the target business can be directly returned to the user end, or relevant information of the failure of the target business execution can be fed back to the corresponding processing personnel to manually confirm the cause of the execution failure. The specific cause can be determined based on actual conditions, and this application does not limit this.
[0081] Based on the same inventive concept, a service calling device is also provided in the embodiments of this specification, such as the following embodiments. Since the principle of solving the problem by the service calling device is similar to that of the service calling method, the implementation of the service calling device can refer to the implementation of the service calling method, and the repeated parts will not be repeated. As used below, the term "unit" or "module" can be a combination of software and / or hardware that implements the predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable. Figure 3 is a structural block diagram of a service calling device according to an embodiment of this specification, such as Figure 3 As shown, it may include: a processing module 301 and a calling module 302. The structure is described below.
[0082] The processing module 301 may be used to respond to a target service request initiated by a user and obtain a service call relationship information set of the target service; wherein the service call relationship information set of the target service includes call relationships of multiple services involved in the target service;
[0083] The calling module 302 may be used to sequentially call multiple services involved in the target business using multiple threads according to the calling relationship of multiple services involved in the target business.
[0084] The embodiment of this specification also provides an electronic device, which can be specifically referred to in Figure 4 The electronic device composition structure diagram of the service calling method provided by the embodiment of the present specification is shown, and the electronic device may specifically include an input device 41, a processor 42, and a memory 43. Among them, the input device 41 can be specifically used to input a target service request. The processor 42 can be specifically used to respond to a target service request initiated by a user, and obtain a service call relationship information set of the target service; wherein the service call relationship information set of the target service includes the call relationship of multiple services involved in the target service; according to the call relationship of multiple services involved in the target service, multiple services involved in the target service are called in sequence using multiple threads. The memory 43 can be specifically used to store parameters such as the service call relationship information set.
[0085] In this embodiment, the input device can specifically be one of the main devices for information exchange between the user and the computer system. The input device can include a keyboard, a mouse, a camera, a scanner, a light pen, a handwriting input board, a voice input device, etc.; the input device is used to input the original data and the program for processing these numbers into the computer. The input device can also obtain and receive data transmitted from other modules, units, and devices. The processor can be implemented in any appropriate manner. For example, the processor can take the form of a computer-readable medium, a logic gate, a switch, an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a programmable logic controller, and an embedded microcontroller, etc., such as a microprocessor or a processor and a computer-readable program code (such as software or firmware) that can be executed by the (micro) processor. The memory can specifically be a memory device used to store information in modern information technology. The memory can include multiple levels. In a digital system, anything that can store binary data can be a memory; in an integrated circuit, a circuit with a storage function without a physical form is also called a memory, such as a RAM, a FIFO, etc.; in a system, a storage device with a physical form is also called a memory, such as a memory stick, a TF card, etc.
[0086] In this embodiment, the functions and effects specifically realized by the electronic device can be explained in comparison with other embodiments and will not be described in detail here.
[0087] The embodiment of the present specification also provides a computer storage medium based on the service calling method, and the computer storage medium stores computer program instructions, which can achieve the following when executed: in response to a target business request initiated by a user, obtaining a service calling relationship information set of the target business; wherein the service calling relationship information set of the target business includes calling relationships of multiple services involved in the target business; and according to the calling relationships of multiple services involved in the target business, using multiple threads to sequentially call multiple services involved in the target business.
[0088] In this embodiment, the storage medium includes, but is not limited to, a random access memory (RAM), a read-only memory (ROM), a cache, a hard disk (HDD), or a memory card. The memory may be used to store computer program instructions. The network communication unit may be an interface for network connection communication set in accordance with the standard specified by the communication protocol.
[0089] In this embodiment, the functions and effects specifically implemented by the program instructions stored in the computer storage medium can be explained in comparison with other embodiments and will not be repeated here.
[0090] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of this specification can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of this specification are not limited to any specific combination of hardware and software.
[0091] Although the embodiments of this specification provide method operation steps as described in the above embodiments or flowcharts, more or fewer operation steps may be included in the method based on routine or no creative labor. In the steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided by the embodiments of this specification. When the device or terminal product of the method described in practice is executed, it can be executed in sequence or in parallel according to the method shown in the embodiments or drawings (for example, a parallel processor or a multi-threaded processing environment).
[0092] It should be understood that the above description is for illustration and not for limitation. By reading the above description, many embodiments and many applications beyond the examples provided will be apparent to those skilled in the art. Therefore, the scope of the embodiments of this specification should not be determined with reference to the above description, but should be determined with reference to the full scope of the aforementioned claims and the equivalents possessed by these claims.
[0093] The above is only a preferred embodiment of the embodiment of this specification, and is not intended to limit the embodiment of this specification. For those skilled in the art, the embodiment of this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the embodiment of this specification shall be included in the protection scope of the embodiment of this specification.
Claims
1. A service calling method, characterized in that: include: In response to a target service request initiated by a user, a service call relationship information set of the target service is obtained; wherein the service call relationship information set of the target service includes call relationships of multiple services involved in the target service; According to the calling relationship of the multiple services involved in the target business, the multiple services involved in the target business are called in sequence by using multiple threads; According to the calling relationship of multiple services involved in the target business, multiple services involved in the target business are called in sequence using multiple threads, including: The service calling process creates a thread of the current service according to the calling relationship of multiple services involved in the target business; wherein the current service is the service that needs to be called currently; The thread of the current service reads the message configuration information set of the current service; wherein the message configuration information set includes configuration information of the input message and the output message of the current service configured in the form of metadata; the metadata and the corresponding types adopt a unified naming and definition specification; The thread of the current service constructs a request message and a target response message of the current service according to the message configuration information set of the current service; wherein the request message and the target response message are transmitted in a MAP manner; The thread of the current service calls the current service based on a reflection mechanism by using the request message and thread of the current service; The service calling process, when determining that the current service is a synchronous call according to the service calling relationship information set of the target business, releases the resources of the thread of the current service when determining that the current service has been successfully executed, and creates a thread of the next service of the current service according to the calling relationship of multiple services involved in the target business; Using the thread of the next service of the current service as the thread of the current service until multiple service calls involved in the target business are completed; Before the method responds to a target service request initiated by a user and obtains a service call relationship information set of the target service, the method further includes: Calling a service calling process according to the target business request; wherein the service calling process is used to execute calling processing of multiple services involved in the target business; In the case where the target business request involves an asynchronous call, an asynchronous service receiving process is called; wherein the asynchronous service receiving process is used to receive the result returned by the asynchronously called service, and the service calling process and the asynchronous service receiving process exchange information through a message mechanism.
2. The method according to claim 1, characterized in that After calling the current service by using the thread of the current service based on the reflection mechanism, the method further includes: When it is determined according to the service call relationship information set of the target business that the current service is an asynchronous call, creating a thread of the next service of the current service according to the call relationship of multiple services involved in the target business; The thread of the next service of the current service is used as the thread of the current service until the multiple service calls involved in the target business are completed.
3. The method according to claim 1, characterized in that According to the calling relationship of multiple services involved in the target business, multiple services involved in the target business are called in sequence using multiple threads, including: The service calling process creates a thread of the current service according to the calling relationship of multiple services involved in the target business; wherein the current service is the service that needs to be called currently; The thread of the current service calls the current service based on the reflection mechanism; When it is determined that the current service is a synchronous call according to the service call relationship information set of the target business, the thread of the current service sends the call result of the current service to the service call process upon receiving the call result of the current service; The service calling process, when determining that the current service has been successfully executed according to the calling result of the current service, creates a thread of the next service of the current service according to the calling relationship of multiple services involved in the target business; The thread of the next service of the current service is used as the thread of the current service until the multiple service calls involved in the target business are completed.
4. The method according to claim 3, characterized in that: After the thread of the current service calls the current service based on the reflection mechanism, the method further includes: In the case where it is determined that the current service is not successfully executed, determining a calling sequence of multiple services involved in the target business according to the service calling relationship information set of the target business; The service calling process sequentially calls the compensation services of the services involved in the target business using multiple threads in the reverse order of the calling sequence of the multiple services involved in the target business.
5. The method according to claim 3, characterized in that: After the thread of the current service calls the current service based on the reflection mechanism, the method further includes: When the service calling process determines that the current service is a synchronous call according to the service calling relationship information set of the target business, the thread of the current service generates a service flow of the current service according to the calling result of the current service when receiving the calling result of the current service; The service flow of the current service is stored in a preset database.
6. The method according to claim 5, characterized in that The service flow includes: service ID, input message, output message, service execution result, and ID of the last called service of the current service.
7. The method according to claim 3, characterized in that After the thread of the current service calls the current service based on the reflection mechanism, the method further includes: When it is determined that the current service is an asynchronous call according to the service call relationship information set of the target business, the thread of the current service sends a call result of the thread of the current service to the service call process; The service calling process, when determining according to the calling result of the thread of the current service that the thread of the current service has been successfully called, creates a thread of the next service of the current service according to the calling relationship of multiple services involved in the target business; The thread of the next service of the current service is used as the thread of the current service until the multiple service calls involved in the target business are completed.
8. The method according to claim 6, characterized in that After the thread of the current service sends the calling result of the thread of the current service to the service calling process, the method further includes: When the asynchronous service receiving process determines that the calling result returned by the thread of the current service is successfully received, the asynchronous service receiving process generates a response message of the current service according to the service calling relationship information set of the target business and the calling result of the current service; The asynchronous service receiving process puts the response message of the current service into the target message queue; The service calling process determines whether the current service is successfully executed according to the response message of the current service in the target message queue; When it is determined that the current service is successfully executed, the calling process of the current service is terminated.
9. The method according to claim 8, characterized in that After the service calling process determines whether the current service is successfully executed according to the response message of the current service in the target message queue, the process further includes: In the case where it is determined that the current service is not successfully executed, determining a calling sequence of multiple services involved in the target business according to the service calling relationship information set of the target business; The service calling process uses multiple threads to sequentially call the compensation service of at least one feature service involved in the target business in reverse order of the calling order of multiple services involved in the target business; wherein the feature service is a service involved in the target business that needs to call the compensation service.
10. The method according to claim 9, characterized in that The service calling process sequentially calls the compensation service of at least one characteristic service involved in the target business using multiple threads in the reverse order of the calling sequence of multiple services involved in the target business, including: The service calling process reads multiple service flows involved in the target business from a preset database; Re-create multiple threads according to the service flow of each characteristic service in reverse order of the calling sequence of multiple services involved in the target business, and call the compensation services of the characteristic services involved in the target business in sequence by using the re-created multiple threads; Among them, the compensation service of the feature service involved in the target business is called in sequence by using multiple recreated threads, including: the thread of the target feature service determines the compensation service ID of the target feature service according to the target feature service ID in the service flow of the target feature service; based on the reflection mechanism, the compensation service of the target feature service is called according to the compensation service ID of the target feature service until the compensation service call of at least one feature service involved in the target business is completed.
11. A service calling device, characterized in that: include: A processing module, configured to obtain a service call relationship information set of the target service in response to a target service request initiated by a user; wherein the service call relationship information set of the target service includes call relationships of multiple services involved in the target service; A calling module, used to call the multiple services involved in the target business in sequence using multiple threads according to the calling relationship of the multiple services involved in the target business; The calling module is specifically used for: Using the service calling process to create a thread of the current service according to the calling relationship of multiple services involved in the target business; wherein the current service is the service that needs to be called currently; Using the thread of the current service to read the message configuration information set of the current service; wherein the message configuration information set includes configuration information of the input message and the output message of the current service configured in the form of metadata; the metadata and the corresponding types adopt a unified naming and definition specification; Using the thread of the current service according to the message configuration information set of the current service, constructing the request message and the target response message of the current service; wherein the request message and the target response message are transmitted in a MAP manner; Using the thread of the current service based on the reflection mechanism, using the request message and thread of the current service to call the current service; When the service calling process determines that the current service is a synchronous call according to the service calling relationship information set of the target business, and when it is determined that the current service has been successfully executed, a thread of the next service of the current service is created according to the calling relationship of multiple services involved in the target business; Using the thread of the next service of the current service as the thread of the current service until multiple service calls involved in the target business are completed; The device is also used to: call a service calling process according to the target business request; wherein the service calling process is used to execute the calling processing of multiple services involved in the target business; and when the target business request involves an asynchronous call, call an asynchronous service receiving process; wherein the asynchronous service receiving process is used to receive the result returned by the asynchronously called service, and the service calling process and the asynchronous service receiving process exchange information through a message mechanism.
12. A computer-readable storage medium, characterized in that: Computer instructions are stored thereon, and when the instructions are executed, the steps of the method according to any one of claims 1 to 10 are implemented.
Citation Information
Patent Citations
Method and device for keeping data consistency
CN111277639A
Service execution method and device, computer equipment and storage medium
CN111580793A