CN112099973A - Service calling method and device - Google Patents

Service calling method and device Download PDF

Info

Publication number
CN112099973A
CN112099973A CN202010974484.5A CN202010974484A CN112099973A CN 112099973 A CN112099973 A CN 112099973A CN 202010974484 A CN202010974484 A CN 202010974484A CN 112099973 A CN112099973 A CN 112099973A
Authority
CN
China
Prior art keywords
service
calling
target
current
thread
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010974484.5A
Other languages
Chinese (zh)
Inventor
黄廷科
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Construction Bank Corp
Original Assignee
China Construction Bank Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Construction Bank Corp filed Critical China Construction Bank Corp
Priority to CN202010974484.5A priority Critical patent/CN112099973A/en
Publication of CN112099973A publication Critical patent/CN112099973A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4812Task transfer initiation or dispatching by interrupt, e.g. masked

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the specification provides a service calling method and a service calling device, wherein the method comprises the following steps: responding to a target service request initiated by a user, and acquiring a service calling relation information set of the target service; the service calling relation information of the target service collectively comprises the calling relations of a plurality of services related to the target service; and according to the calling relation of the plurality of services related to the target service, using a plurality of threads to sequentially call the plurality of services related to the target service. In the embodiment of the description, the method and the device can efficiently and flexibly invoke a plurality of services related to the target service requested by the user without depending on any process platform for encapsulating the combined service.

Description

Service calling method and device
Technical Field
The embodiment of the specification relates to the technical field of data processing, in particular to a service calling method and device.
Background
Because the system scale of large commercial bank enterprises is often very large, the transaction business number of all product systems can reach tens of thousands sometimes, therefore, in order to adapt to the rapid growth of business and the iterative update of the system, the system gradually shifts from a centralized architecture to a distributed service architecture, all transaction interfaces are completely served, and the distributed service architecture effectively solves the problems of performance expansion, agile iterative upgrade and the like in the centralized architecture, but a user needs to call a plurality of services to complete when requesting some businesses, namely, a plurality of services related to the business need to be combined to realize a business process.
In the combined service method in the prior art, the combined management of services is usually realized through a flow platform, and the basic principle of the realization is that a plurality of services related to a service are encapsulated into one service to be called by the service through the function of the flow platform, so that the integrated calling of the service is realized. The existing combined service method mainly depends on a process platform, and codes of the combined service need to be rewritten for each business if the process platform is replaced, so that the method has no flexibility. And when the combined service corresponding to the existing service is changed or a new service appears, the combined service code of the service needs to be rewritten, so that a plurality of services related to the service cannot be called conveniently by adopting the existing combined service method.
In view of the above problems, no effective solution has been proposed.
Disclosure of Invention
The embodiment of the specification provides a service calling method and device, and aims to solve the problem that a plurality of services related to a service are called conveniently in the prior art.
An embodiment of the present specification provides a service invocation method, including: responding to a target service request initiated by a user, and acquiring a service calling relation information set of the target service; the service calling relation information of the target service collectively comprises the calling relations of a plurality of services related to the target service; and according to the calling relation of the plurality of services related to the target service, using a plurality of threads to sequentially call the plurality of services related to the target service.
An embodiment of the present specification further provides a service invocation device, including: the processing module is used for responding to a target service request initiated by a user and acquiring a service calling relation information set of the target service; the service calling relation information of the target service collectively comprises the calling relations of a plurality of services related to the target service; and the calling module is used for calling the plurality of services related to the target service in sequence by using a plurality of threads according to the calling relation of the plurality of services related to the target service.
The present specification also provides a computer readable storage medium, on which computer instructions are stored, which when executed implement the steps of the service invocation method.
The embodiment of the present specification provides a service invocation method, which can respond to a target service request initiated by a user and obtain a service invocation relationship information set of the target service. Since the service invocation relation information of the target service centrally contains the invocation relation of the plurality of services related to the target service, the plurality of services related to the target service can be invoked in sequence by using the plurality of threads according to the invocation relation of the plurality of services related to the target service, the packaging of the combined service is not required to be carried out depending on any process platform, and the plurality of services related to the target service requested by the user can be flexibly invoked efficiently.
Drawings
The accompanying drawings, which are included to provide a further understanding of the embodiments of the disclosure, are incorporated in and constitute a part of this specification, and are not intended to limit the embodiments of the disclosure. In the drawings:
fig. 1 is a schematic structural diagram of a service invocation system provided according to an embodiment of the present specification;
FIG. 2 is a schematic diagram illustrating steps of a service invocation method provided in accordance with an embodiment of the present specification;
FIG. 3 is a schematic structural diagram of a service invocation device provided according to an embodiment of the present specification;
fig. 4 is a schematic structural diagram of a service invocation device provided according to an embodiment of the present specification.
Detailed Description
The principles and spirit of the embodiments of the present specification will be described with reference to a number of exemplary embodiments. It should be understood that these embodiments are presented merely to enable those skilled in the art to better understand and to implement the embodiments of the present description, and are not intended to limit the scope of the embodiments of the present description in any way. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
As will be appreciated by one skilled in the art, implementations of the embodiments of the present description may be embodied as a system, an apparatus, a method, or a computer program product. Therefore, the disclosure of the embodiments of the present specification can be embodied in the following forms: entirely hardware, entirely software (including firmware, resident software, micro-code, etc.), or a combination of hardware and software.
Although the flow described below includes operations that occur in a particular order, it should be appreciated that the processes may include more or less operations that are performed sequentially or in parallel (e.g., using parallel processors or a multi-threaded environment).
In an example scenario of the present application, a service invocation system is provided, as shown in fig. 1, which may include: a terminal device 101 and a server 102, and a user can initiate a target service request through the terminal device 101. The server 102 may obtain a service invocation relationship information set of the target service in response to a target service request submitted by a user, and sequentially invoke a plurality of services related to the target service by using a plurality of threads according to the invocation relationship of the plurality of services related to the target service, thereby efficiently and flexibly invoking the plurality of services related to the target service without depending on any process platform. In some scenario examples, the server 102 may also feed back execution results of a plurality of services related to the invoked target service to the terminal device 101.
The terminal device 101 may be a terminal device or software used by a user. Specifically, the terminal device may be a terminal device such as a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart watch, or other wearable devices, or may be a robot device. Of course, the terminal apparatus 101 may be software that can be run in the above terminal apparatus. For example: system applications, payment applications, browsers, wechat applets, and the like.
The server 102 may be a single server or a server cluster, and certainly, the functions of the server may also be implemented by a cloud computing technology. The server 102 may be connected to a plurality of terminal devices, or may be a server having a strong information set library, and may obtain a service invocation relationship information set of a target service based on a target service request initiated by a user, and sequentially invoke a plurality of services related to the target service by using a plurality of threads according to the invocation relationships of the plurality of services related to the target service, thereby implementing flexible invocation of the plurality of services related to the target service efficiently without depending on any process platform.
Referring to fig. 2, the present embodiment can provide a service invocation method. The service calling method can be used for calling a plurality of services related to the target service in sequence by using a plurality of threads according to the calling relation of the plurality of services related to the target service based on the target service request initiated by the user, thereby realizing the flexible calling of the plurality of services related to the target service with high efficiency. The service invocation method may include the following steps.
S201: responding to a target service request initiated by a user, and acquiring a service calling relation information set of a target service; the service calling relation information of the target service collectively comprises calling relations of a plurality of services related to the target service.
In the present embodiment, a service invocation relationship information set of a target service is obtained in response to a target service request issued by a user. In some embodiments, a server for processing a service request and resource scheduling in an organization such as a bank may respond to a target service request sent by a user, or a process may respond to a target service request sent by a user, which may be determined specifically according to an actual situation, and the present application does not limit this.
In this embodiment, the target service request may be a request sent by a user for a target service, and the target service request may be transmitted in a form of a message. The target service may be a service that a user desires to implement, and in an example scenario, the target service may include: the target business is not limited to the above examples, and persons skilled in the art may make other changes within the spirit of the embodiments of the present disclosure, but the functions and effects of the business are all covered by the scope of the embodiments of the present disclosure.
In this embodiment, since it may be necessary to call a plurality of services according to a certain sequence to complete one service, after receiving a target service request initiated by a user, a service call relationship information set of the target service may be obtained, where the service call relationship information set of the target service includes call relationships of a plurality of services related to the target service. In the case that the target transaction is a transfer transaction, the plurality of services involved in the transfer transaction may include, but are not limited to: transfer function, registration information, accumulated credit, etc.
In this embodiment, a plurality of services related to the target service and call relations of the plurality of services related to the target service may be determined according to the service call relation information set of the target service, where the call relations of the plurality of services may be a manner, a sequence, and the like of calling each service, and the manner of calling the service may include at least one of the following: serial, parallel. The service calling mode is serial, the service is represented as synchronous calling, and the service calling mode is parallel, the service is represented as asynchronous calling. Synchronous invocation is a blocking type invocation mode, namely, a main caller code always blocks and waits until a callee returns, and a page is supposed to do three things: A. b, C, the synchronous calling mode is generally that B is done after A is done, and C is done after B is done; and the asynchronous call is to start to do A, and can start to do B when A is not finished, and can start to do C when B is not finished. If all three events take 5s, the synchronous call needs a minimum of 15s to complete, and if asynchronous, the synchronous call needs a minimum of 5s to complete, so the efficiency of asynchronous call is higher compared with synchronous call. But asynchronous calls are only applicable to situations where there is no correlation between the services that need to be called. If there are associated, interdependent cases, for example: b must adopt a call after the execution of A is completed, C must adopt a call after the execution of B is completed, and a synchronous call mode is adopted.
In this embodiment, the service invocation relationship information set of the target service may further include feature information related to each service, for example: service ID (identity), whether to synchronize a waiting identity, etc. The service ID can be a character string, and one service can be uniquely identified through the service ID; the synchronous waiting identifier may be used to identify whether the call of the plurality of services related to the target service is synchronous waiting for the processing result.
In an embodiment, the service invocation relationship information sets of each service that can be provided in the system may be all stored in a preset database in advance, and when an initiated target service request is received, the service invocation relationship information set of the target service may be acquired from the preset database according to the target service request. The preset database may be a database for storing business data in a bank or other institutions. It is understood that, the service invocation relation information set of the target service may also be obtained in other possible manners, for example, the service invocation relation information set of the target service is searched in a web page according to a certain search condition, which may be determined specifically according to an actual situation, and this is not limited in this embodiment of the present specification.
In some embodiments, the target service request may include identification information of the target service, so that the service to be processed may be uniquely determined according to the identification information of the target service.
S202: and according to the calling relation of the plurality of services related to the target service, using the plurality of threads to sequentially call the plurality of services related to the target service.
In the present embodiment, since the service call relationship information of the target service collectively includes the call relationships of the plurality of services related to the target service, the plurality of services related to the target service can be sequentially called by the plurality of threads in accordance with the call relationships of the plurality of services related to the target service.
In this embodiment, the plurality of threads and the plurality of services may be in a one-to-one correspondence, that is, one thread may be used to call and process one service. Of course, a thread may be used to call and process a service when a synchronous call is executed, which may be determined according to the actual situation, and is not limited in this application.
In this embodiment, the multiple threads may be created simultaneously or sequentially, for example, when it is determined that the current service is successfully invoked or executed, a thread of a service next to the current service may be created, and the above steps may be repeated until all of the multiple services related to the target service have been invoked. Of course, the manner of sequentially invoking multiple services related to the target service by using multiple threads is not limited to the above example, and other modifications may be made by those skilled in the art within the spirit of the embodiments of the present disclosure, but the functions and effects implemented by the embodiments of the present disclosure are all within the scope of the embodiments of the present disclosure.
In this embodiment, the thread (thread) is a term in the operating system technology, is the smallest unit that the operating system can perform operation scheduling, is included in a process, and is the actual operation unit in the process. A process (process) is a memory area containing some resources, an operating system divides its work into some functional units by using the process, one or more execution units contained in the process are called threads (threads), one thread refers to a single sequential control flow in the process, a plurality of threads can be in parallel in one process, and each thread can execute different tasks in parallel.
From the above description, it can be seen that the embodiments of the present specification achieve the following technical effects: the service invocation relation information set of the target service can be obtained in response to a target service request initiated by a user. Since the service invocation relation information of the target service centrally contains the invocation relation of the plurality of services related to the target service, the plurality of services related to the target service can be invoked in sequence by using the plurality of threads according to the invocation relation of the plurality of services related to the target service, and the packaging of the combined service is not required to be carried out depending on any process platform, so that the plurality of services related to the target service requested by the user can be flexibly invoked efficiently.
In one embodiment, sequentially calling the plurality of services related to the target service by using the plurality of threads according to the calling relationship of the plurality of services related to the target service may include: and creating a thread of the current service according to the calling relationship of the plurality of services related to the target service, wherein the current service is the service which needs to be called currently. Further, the current service may be called by using a thread of the current service based on a reflection mechanism, and when it is determined that the current service is a synchronous call according to the service call relationship information set of the target service, a thread of a next service of the current service may be created according to call relationships of a plurality of services related to the target service when it is determined that the current service has been successfully executed. The thread of the next service to the current service may be taken as the thread of the current service until the plurality of service calls involved by the target service are completed.
In this embodiment, the plurality of services and the plurality of threads are in one-to-one correspondence, each created thread is only used for processing the corresponding service, and the resource of the thread can be released after the corresponding service is successfully executed.
In this embodiment, since the 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 the synchronous call, a thread of the next service of the current service can be created according to the call relationship of the services related to the target service when it is determined that the current service has been successfully executed, so that the thread of the next service of the current service can be used to call and execute the next service of the current service, and the above steps can be repeated until all the services related to the target service are called.
In this embodiment, reflection refers to a class of applications, the reflection mechanism being self-describing and self-controlling. Namely, such applications implement self-representation and monitoring (evolution) of their own behavior by using some mechanism, and can adjust or modify the state and related semantics of the behavior described by the application according to the state and result of their own behavior. In one embodiment, the current service may be invoked with a thread of the current service based on a reflection mechanism.
In one embodiment, in the process of sequentially calling the plurality of services related to the target service by using the plurality of threads, if it is determined that one service is not successfully called or is not successfully executed, the processing of the threads may be ended, and the compensation services of the plurality of services related to the target service may be sequentially called by using the plurality of threads in a reverse order of the calling order of the plurality of services related to the target service.
In the present embodiment, the compensation service of the plurality of services related to the target service is called in the reverse order of the calling order of the plurality of services related to the target service, and the continuity and consistency of data can be ensured. The compensation service may be a direction service of one service, and may also be referred to as a correction service (a remedy method adopted when the system considers that the system may fail), wherein the call of the compensation service needs to adopt a serial mode.
In one embodiment, after invoking the current service by using the thread of the current service based on the reflection mechanism, the method may further include: and under the condition that the current service is determined to be asynchronously called according to the service calling relation information set of the target service, creating a thread of a next service of the current service according to the calling relations of a plurality of services related to the target service. Further, the thread of the next service of the current service can be used as the thread of the current service until the plurality of service calls related to the target service are completed.
In this embodiment, since asynchronous calling can call the next service of the current service without waiting for the current service to be successfully executed, after it is determined that the current service is successfully called, a thread of the next service of the current service can be created according to the calling relationship of the plurality of services related to the target service, and the thread of the next service of the current service is used to call the next service of the current service, and the above steps can be executed in a loop until all the plurality of services related to the target service are called.
In one embodiment, the message may be used to transmit information, and therefore, before invoking the service by using the thread of the current service based on the reflection mechanism, the method may further include: reading a message configuration information set of the current service, wherein the message configuration information set comprises configuration information configured by adopting a metadata mode for an input message and an output message of the current service. Further, a request message and a target response message of the current service can 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 an MAP manner.
In this embodiment, the MAP is a container for storing several elements, and these elements are all composed of key value (key value) and mapping value pairs, and can be used for flexibly storing and retrieving data. The MAP may provide one-to-one (where the first may be referred to as a key, each key may only appear once in the MAP, and the second is referred to as the value of the key) data processing capability.
In this embodiment, a message configuration information set of a service may be configured in advance for each service and stored in a preset database, where the message is a data unit exchanged and transmitted in a network, that is, a data block to be sent by a station at a time, and the message includes complete data information to be sent, and the length of the message is not consistent, and is not limited and can be changed. The message configuration information set can be displayed and stored in the form of a table, an image or a text, and the message configuration information set can be stored in a preset database so as to be read and modified conveniently. The preset database may be a database for storing business data in a bank or other institutions.
In this embodiment, since the standard format of the packet is required before packet transmission, the packet configuration information set may include configuration information of an input packet and an output packet of the current service, where the configuration information of the input packet and the output packet of the current service may be used to represent the standard format of a request packet that needs to be sent when the current service is called and the standard format of a corresponding packet generated when the current service is successfully executed. It is understood that the message configuration information set may further include other information, for example: a service ID (identity), which may be a character string, by which a service can be uniquely identified.
In this embodiment, the request packet and the target response packet of the current service may be constructed according to the configuration information of the input packet and the output packet of the current service. The target response message may be a message that needs to be generated when the current service is successfully executed, so that whether the current service is successfully executed or not can be determined according to the target response message.
In this embodiment, the input packet and the output packet may be configured in a metadata manner, the metadata and the type thereof adopt a unified naming and definition specification, each metadata has a unique name, and the definition type thereof adopts a unified data standard. Metadata is information that describes attributes of data and is used to support functions such as indicating storage locations, history data, resource lookups, file records, etc. Its most essential, abstract definition is: data about data, is a ubiquitous phenomenon, and has its specific definition and application in many fields. It is to be understood that, in some embodiments, the input packet and the output packet may be configured in other manners, which may be determined according to actual situations, and the present application is not limited thereto.
In this embodiment, correspondingly, based on the reflection mechanism, invoking the current service by using the thread of the current service may include: and calling the current service by using the request message and the thread of the current service based on a reflection mechanism.
In an embodiment, since the resource for processing the target service request needs to be allocated before processing the target service request, before acquiring the service invocation relationship information set of the target service in response to the target service request initiated by the user, the method may further include: and calling a service calling process according to the target service request, wherein the service calling process is used for executing calling processing of a plurality of services related to the target service. Further, the asynchronous service receiving process may be invoked in a case where the target service request involves an asynchronous call, where the asynchronous service receiving process is configured to receive a 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.
In this embodiment, the service calling process may call a plurality of services related to the target service according to the service calling relationship information set of the target service. Since the asynchronous call can immediately call the next service without waiting for the call result of the current service, it is necessary to receive the result returned by the service of the asynchronous call by the asynchronous service reception process to determine whether the service of the asynchronous call is successfully executed.
In this embodiment, in order to enable the asynchronous service receiving process to send the received result returned by the asynchronously called service to the service calling process, information is exchanged between the service calling process and the asynchronous service receiving process through a message mechanism.
All the time of occurrence can be represented by a message, the message is used for telling an operating system what happens, and the parameters of the message contain important information. A message queue may be maintained for the asynchronous service receiving process using the message mechanism, and after the asynchronous service receiving process receives a result returned by the asynchronously invoked service, the asynchronous service receiving process may convert the event to a message and place the message in the message queue. Further, messages may be retrieved from the message queue through a message loop, the task of which is to retrieve messages from the message queue and then pass the messages to the appropriate process.
In one embodiment, sequentially calling the plurality of services related to the target service by using the plurality of threads according to the calling relationship of the plurality of services related to the target service may include: and the service calling process creates a thread of the current service according to the calling relation of the plurality of services related to the target service, wherein the current service is the service which needs to be called currently. Furthermore, the thread of the current service calls the current service based on a reflection mechanism, and when the thread of the current service receives the calling result of the current service and determines that the current service is synchronously called according to the service calling relation information set of the target service, the thread of the current service sends the calling result of the current service to the service calling process. And the service calling process establishes a thread of the next service of the current service according to the calling relation of the plurality of services related to the target service under the condition that the current service is determined to be successfully executed according to the calling result of the current service, and takes the thread of the next service of the current service as the thread of the current service until the plurality of services related to the target service are called completely.
In this embodiment, the plurality of services and the plurality of threads are in one-to-one correspondence, each created thread is only used for processing the corresponding service, and the resource of the thread can be released after the corresponding service is successfully executed.
In this embodiment, since the 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 the synchronous call, a thread of the next service of the current service can be created according to the call relationship of the services related to the target service when it is determined that the current service has been successfully executed, so that the thread of the next service of the current service can be used to call and execute the next service of the current service, and the above steps can be repeated until all the services related to the target service are called.
In one embodiment, after the thread of the current service calls the current service based on the reflection mechanism, the service calling process may determine, according to the service calling relationship information set of the target service, a calling order of the plurality of services related to the target service in case that it is determined that the current service is not successfully executed. Furthermore, the service calling process uses a plurality of threads to call the compensation service of each service related to the target service in turn according to the reverse order of the calling order of the plurality of services related to the target service.
In the present embodiment, the compensation service of the plurality of services related to the target service is called in the reverse order of the calling order of the plurality of services related to the target service, and the continuity and consistency of data can be ensured. The compensation service may be a direction service of one service, and may also be referred to as a correction service (a remedy method adopted when the system considers that the system may fail), wherein the call of the compensation service needs to adopt a serial mode.
In one embodiment, in order to make each called service related information be queried, after the thread of the current service calls the current service based on the reflection mechanism, the method may further include: and under the condition that the current service is determined to be synchronously called according to the service calling relation information set of the target service, when the thread of the current service receives the calling result of the current service, generating the service flow of the current service according to the calling result of the current service, and storing the service flow of the current service into a preset database.
In this embodiment, the service flow may be used to characterize the calling and executing conditions of the service, and in some embodiments, the service flow may include, but is not limited to: service ID, input message, output message, service execution result, and ID of last call service of current service.
In this embodiment, the preset database may be a database storing business data in a bank or other institutions.
In one embodiment, after the thread of the current service calls the current service based on the reflection mechanism, the method further includes: and under the condition that the current service is determined to be asynchronously called according to the service calling relation information set of the target service, the thread of the current service sends the calling result of the current process to the service calling process, and under the condition that the service calling process determines that the current process is successfully called according to the calling result of the current process, the thread of the next service of the current service can be established according to the calling relations of a plurality of services related to the target service. Further, the thread of the next service of the current service can be used as the thread of the current service until the plurality of service calls related to the target service are completed.
In this embodiment, the invoking result may be used to characterize whether the service is successfully invoked, and the invoking result may be used to characterize whether the service is successfully executed. In the asynchronous calling scenario, after confirming that the current service has been successfully called, a thread of a next service of the current service can be created by the service calling process according to the calling relationship of the plurality of services related to the target service.
In this embodiment, since asynchronous calling can call the next service of the current service without waiting for the current service to be successfully executed, after it is determined that the current service is successfully called, a thread of the next service of the current service can be created according to the calling relationship of the plurality of services related to the target service, and the thread of the next service of the current service is used to call the next service of the current service, and the above steps can be executed in a loop until all the plurality of services related to the target service are called.
In one embodiment, after the thread of the current service sends the invocation result of the current process to the service invocation process, the method further includes: and when the asynchronous service receiving process determines that the calling result returned by the thread of the current service is successfully received, generating a response message of the current service according to the service calling relation information set of the target service and the calling 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. And in the case that the current service is determined to be successfully executed, ending the calling process of the current service.
In this embodiment, since the service invocation relation information set of the target service includes the output packet configured in advance, the response packet of the current service can be generated according to the service invocation relation information set of the target service and the invocation result of the current service.
In this embodiment, when the asynchronous service receiving process successfully receives the call result returned by the currently served thread, the asynchronous service receiving process may preliminarily determine the call result returned by the currently served thread. Because the output message configured in the service calling relationship information set of the target service is a message which normally responds under the condition that the current service is successfully executed, the response message of the current service can be directly generated according to the service calling relationship information set of the target service and the calling result of the current service under the condition that the current service is determined to be successfully executed; and under the condition that the current service is determined not to be successfully executed, the output message configured in the service calling relation information set of the target service can be adjusted according to the calling result of the current service, so that a response message of the current service is generated.
In this embodiment, when it is determined that the current service is successfully executed, the thread resource of the current service may be released, and the call flow of the current service may be ended.
In one embodiment, after the service invoking process determines whether the current service is successfully executed according to the response message of the current service in the target message mechanism, the method may further include: and under the condition that the current service is determined not to be successfully executed, determining the calling sequence of the plurality of services related to the target service according to the service calling relation information set of the target service, and calling the compensation service of the characteristic service related to the target service by the plurality of threads in sequence by the service calling process according to the reverse sequence of the calling sequence of the plurality of services related to the target service. Wherein, the characteristic service is a service related to the target service and needing to call the compensation service.
In this embodiment, the service invocation process sequentially invokes, by using a plurality of threads, a compensation service of at least one feature service related to the target service in a reverse order of the invocation order of the plurality of services related to the target service, may include: the service calling process reads the plurality of service flow lines related to the target service from the preset database, further, the plurality of threads can be created again according to the service flow lines of the feature services in sequence according to the reverse order of the calling sequence of the plurality of services related to the target service, and the plurality of created threads are used for calling the compensation services of the feature services related to the target service in sequence.
In this embodiment, the sequentially invoking, by the plurality of created threads, the compensation service of the feature service related to the target service may include: and the thread of the target characteristic service determines the compensation service ID of the target characteristic service according to the target characteristic service ID in the service flow of the target characteristic service. Further, the compensation service of the target feature service may be invoked according to the compensation service ID of the target feature service based on the reflection mechanism until the invocation of the compensation service of the at least one feature service related to the target service is completed.
In this embodiment, when the thread of the current service receives the call result of the current service, the service flow of the current service may be generated according to the call result of the current service, and the service flow of the current service may be stored in the preset database. Therefore, multiple service pipelines of the target business history can be obtained from the preset database before the compensation service is called.
In this embodiment, the service flow may be used to characterize the calling and executing conditions of the service, and in some embodiments, the service flow may include, but is not limited to: service ID, input message, output message, service execution result, and ID of last call service of current service.
In the present embodiment, since the plurality of threads are created anew from the service flow of each feature service, and there is no record of the service flow in the services related to the target service that are not called, it is only necessary to execute the compensation service in reverse order from the service that failed to be executed, and it is not necessary to execute the corresponding compensation service from the last service among the plurality of services related to the target service.
In this embodiment, a compensation service information set may be preset and stored in a preset database, so as to configure the corresponding relationship between each service and its compensation service. Compensating the service information set may include: service ID, service name, whether a compensation service is needed (identifying whether the service needs a compensation service), compensation service ID (not configured if no compensation service is needed, i.e. the ID of the compensation service can be directly the ID of the service).
In this embodiment, the compensation service ID of the target feature service may 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 may be invoked according to the compensation service ID of the target feature service.
In this embodiment, since the service flow of the feature service includes the input packet and the output packet of the service, before the compensation service of the target feature service is called, the request packet and the response packet of the compensation service of the target feature service may be constructed according to the service flow of the feature service. Correspondingly, the compensation service of the target characteristic service can be called according to the constructed request message.
In this embodiment, after the compensation service of the target feature service is invoked, the invocation result of the compensation service may be waited, and in the case that it is determined that the compensation service of the target feature service is successfully executed, the compensation service of the next feature service may be invoked continuously in the reverse order until the compensation services of all feature services related to the target service have been successfully executed.
In an embodiment, if the execution of the compensation service fails, the attempt to call may be continued, or a prompt indicating that the execution of the target service is abnormal may be directly returned to the user side, or related information of the execution failure of the target service may also be fed back to a corresponding processing person, and the reason of the execution failure may be determined in a manual manner, which may be determined specifically according to an actual situation, and the application does not limit this.
Based on the same inventive concept, the embodiment of the present specification further provides a service invocation device, such as the following embodiments. Because the principle of the service calling device for solving the problem 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 repeated details are not repeated. As used hereinafter, the term "unit" or "module" may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated. Fig. 3 is a block diagram of a structure of a service invocation device according to an embodiment of the present specification, and as shown in fig. 3, the service invocation device may include: the processing module 301 and the calling module 302 describe the configuration below.
The processing module 301 may be configured to respond to a target service request initiated by a user, and obtain a service invocation relationship information set of a target service; the service calling relation information of the target service comprises calling relations of a plurality of services related to the target service in a centralized manner;
the invoking module 302 may be configured to invoke, by using a plurality of threads, a plurality of services related to the target service in sequence according to the invoking relationship of the plurality of services related to the target service.
The embodiment of the present specification further provides an electronic device, which may specifically refer to a schematic structural diagram of an electronic device based on the service invocation method provided by the embodiment of the present specification, shown in fig. 4, where the electronic device may specifically include an input device 41, a processor 42, and a memory 43. The input device 41 may be specifically configured to input a target service request. The processor 42 may be specifically configured to respond to a target service request initiated by a user, and obtain a service invocation relationship information set of the target service; the service calling relation information of the target service comprises calling relations of a plurality of services related to the target service in a centralized manner; and according to the calling relation of the plurality of services related to the target service, using the plurality of threads to sequentially call the plurality of services related to the target service. The memory 43 may be specifically configured to store parameters such as a service invocation relationship information set.
In this embodiment, the input device may be one of the main apparatuses for information exchange between a user and a computer system. The input devices may include a keyboard, mouse, camera, scanner, light pen, handwriting input panel, voice input device, etc.; the input device is used to input raw data and a program for processing the data into the computer. The input device can also acquire and receive data transmitted by other modules, units and devices. The processor may be implemented in any suitable way. For example, the processor may take the form of, for example, a microprocessor or processor and a computer-readable medium that stores computer-readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, an Application Specific Integrated Circuit (ASIC), a programmable logic controller, an embedded microcontroller, and so forth. The memory may in particular be a memory device used in modern information technology for storing information. The memory may include multiple levels, and in a digital system, memory may be used as long as binary data can be stored; in an integrated circuit, a circuit without a physical form and with a storage function is also called a memory, such as a RAM, a FIFO and the like; in the system, the storage device in physical form is also called a memory, such as a memory bank, a TF card and the like.
In this embodiment, the functions and effects specifically realized by the electronic device can be explained by comparing with other embodiments, and are not described herein again.
Embodiments of the present specification further provide a computer storage medium based on a service invocation method, where the computer storage medium stores computer program instructions, and when the computer program instructions are executed, the computer storage medium may implement: responding to a target service request initiated by a user, and acquiring a service calling relation information set of a target service; the service calling relation information of the target service comprises calling relations of a plurality of services related to the target service in a centralized manner; and according to the calling relation of the plurality of services related to the target service, using the plurality of threads to sequentially call the plurality of services related to the target service.
In this embodiment, the storage medium includes, but is not limited to, a Random Access Memory (RAM), a Read-Only Memory (ROM), a Cache (Cache), a Hard Disk Drive (HDD), or a Memory Card (Memory Card). The memory may be used to store computer program instructions. The network communication unit may be an interface for performing network connection communication, which is set in accordance with a standard prescribed by a communication protocol.
In this embodiment, the functions and effects specifically realized by the program instructions stored in the computer storage medium can be explained by comparing with other embodiments, and are not described herein again.
It will be apparent to those skilled in the art that the modules or steps of the embodiments of the present specification described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed over a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different from that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, embodiments of the present description are not limited to any specific combination of hardware and software.
Although the embodiments herein provide the method steps as described in the above embodiments or flowcharts, more or fewer steps may be included in the method based on conventional or non-inventive efforts. In the case of steps where no causal relationship is logically necessary, the order of execution of the steps is not limited to that provided by the embodiments of the present description. When the method is executed in an actual device or end product, the method can be executed sequentially or in parallel according to the embodiment or the method shown in the figure (for example, in the environment of a parallel processor or a multi-thread processing).
It is to be understood that the above description is intended to be illustrative, and not restrictive. Many embodiments and many applications other than the examples provided will be apparent to those of skill in the art upon reading the above description. The scope of embodiments of the present specification should, therefore, be determined not with reference to the above description, but should instead be determined with reference to the appended claims, along with the full scope of equivalents to which such claims are entitled.
The above description is only a preferred embodiment of the embodiments of the present disclosure, and is not intended to limit the embodiments of the present disclosure, and it will be apparent to those skilled in the art that various modifications and variations can be made in the embodiments of the present disclosure. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the embodiments of the present disclosure should be included in the protection scope of the embodiments of the present disclosure.

Claims (16)

1. A service invocation method, characterized by comprising:
responding to a target service request initiated by a user, and acquiring a service calling relation information set of the target service; the service calling relation information of the target service collectively comprises the calling relations of a plurality of services related to the target service;
and according to the calling relation of the plurality of services related to the target service, using a plurality of threads to sequentially call the plurality of services related to the target service.
2. The method according to claim 1, wherein sequentially calling the plurality of services related to the target service by using a plurality of threads according to the calling relationship of the plurality of services related to the target service comprises:
creating a thread of the current service according to the calling relation of the plurality of services related to the target service; the current service is a service which needs to be called currently;
based on a reflection mechanism, utilizing the thread of the current service to call the current service;
under the condition that the current service is determined to be synchronously called according to the service calling relation information set of the target service, when the current service is determined to be successfully executed, a thread of a next service of the current service is created according to the calling relations of a plurality of services related to the target service;
and taking the thread of the next service of the current service as the thread of the current service until the plurality of service calls related to the target service are completed.
3. The method of claim 2, further comprising, after invoking the current service with the thread of the current service based on a reflection mechanism:
under the condition that the current service is determined to be asynchronously called according to the service calling relation information set of the target service, establishing a thread of a next service of the current service according to the calling relations of a plurality of services related to the target service;
and taking the thread of the next service of the current service as the thread of the current service until the plurality of service calls related to the target service are completed.
4. The method of claim 2, further comprising, prior to invoking the service with the thread of the current service based on a reflection mechanism:
reading the message configuration information set of the current service; the message configuration information set comprises configuration information configured by the input message and the output message of the current service in a metadata mode;
constructing 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 by a MAP mode.
5. The method of claim 4, wherein invoking the current service with the thread of the current service based on a reflection mechanism comprises:
and based on a reflection mechanism, utilizing the request message and the thread of the current service to call the current service.
6. The method of claim 1, before obtaining the service invocation relationship information set of the target service in response to the target service request initiated by the user, further comprising:
calling a service calling process according to the target service request; the service calling process is used for executing calling processing of a plurality of services related to the target business;
in the case that the target business request involves an asynchronous call, invoking an asynchronous service receiving process; the asynchronous service receiving process is used for receiving a 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.
7. The method according to claim 6, wherein sequentially calling the plurality of services related to the target service by using a plurality of threads according to the calling relationship of the plurality of services related to the target service comprises:
the service calling process creates a thread of the current service according to the calling relation of the plurality of services related to the target service; the current service is a service which needs to be called currently;
the thread of the current service calls the current service based on a reflection mechanism;
under the condition that the current service is determined to be synchronously called according to the service calling relation information set of the target service, when the thread of the current service receives the calling result of the current service, the calling result of the current service is sent to the service calling process;
the service calling process establishes a thread of a next service of the current service according to the calling relation of the plurality of services related to the target service under the condition that the current service is determined to be successfully executed according to the calling result of the current service;
and taking the thread of the next service of the current service as the thread of the current service until the plurality of service calls related to the target service are completed.
8. The method of claim 7, after the thread of the current service calls the current service based on a reflection mechanism, further comprising:
under the condition that the current service is determined not to be executed successfully, determining the calling sequence of a plurality of services related to the target service according to the service calling relation information set of the target service;
and the service calling process uses a plurality of threads to call the compensation service of each service related to the target service in turn according to the reverse order of the calling order of the plurality of services related to the target service.
9. The method of claim 7, after the thread of the current service calls the current service based on a reflection mechanism, further comprising:
when the service calling process determines that the current service is synchronously called according to the service calling relation information set of the target service, and the thread of the current service receives the calling result of the current service, the service calling process generates the service flow of the current service according to the calling result of the current service;
and storing the service flow of the current service into a preset database.
10. The method of claim 9, wherein the service pipeline comprises: service ID, input message, output message, service execution result, and ID of last call service of current service.
11. The method of claim 7, after the thread of the current service calls the current service based on a reflection mechanism, further comprising:
under the condition that the current service is determined to be asynchronously called according to the service calling relation information set of the target service, the thread of the current service sends a calling result of the current process to the service calling process;
the service calling process establishes a thread of a next service of the current service according to the calling relation of the plurality of services related to the target service under the condition that the service calling process determines that the current process is successfully called according to the calling result of the current process;
and taking the thread of the next service of the current service as the thread of the current service until the plurality of service calls related to the target service are completed.
12. The method of claim 10, after the thread of the current service sends the invocation result of the current process to the service invocation process, further comprising:
when the asynchronous service receiving process determines that the calling result returned by the thread of the current service is successfully received, generating a response message of the current service according to the service calling relation information set of the target service and the calling result of the current service;
the asynchronous service receiving process puts the response message of the current service into a 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;
and in the case that the current service is determined to be successfully executed, ending the calling process of the current service.
13. The method according to claim 12, wherein after the service invoking process determines whether the current service is successfully executed according to the response message of the current service in the target message mechanism, the method further comprises:
under the condition that the current service is determined not to be executed successfully, determining the calling sequence of a plurality of services related to the target service according to the service calling relation information set of the target service;
the service calling process calls the compensation service of at least one characteristic service related to the target service in sequence by using a plurality of threads according to the reverse order of the calling sequence of the plurality of services related to the target service; wherein the characteristic service is a service related to the target service and needing to invoke a compensation service.
14. The method according to claim 13, wherein the service invoking process invokes the compensation service of the at least one feature service related to the target service in turn by using a plurality of threads according to a reverse order of the invoking order of the plurality of services related to the target service, comprising:
the service calling process reads a plurality of service pipelines related to the target service from a preset database;
according to the reverse order of the calling order of the plurality of services related to the target service, a plurality of threads are created again according to the service flow of each feature service in sequence, and the plurality of threads created again are used for calling the compensation service of the feature service related to the target service in sequence;
the method for sequentially calling the compensation service of the feature service related to the target service by using the plurality of created threads comprises the following steps: the thread of the target characteristic service determines a compensation service ID of the target characteristic service according to a target characteristic service ID in service flow water of the target characteristic service; based on a reflection mechanism, calling the compensation service of the target feature service according to the compensation service ID of the target feature service until the compensation service calling of at least one feature service related to the target service is completed.
15. A service invocation apparatus, characterized by comprising:
the processing module is used for responding to a target service request initiated by a user and acquiring a service calling relation information set of the target service; the service calling relation information of the target service collectively comprises the calling relations of a plurality of services related to the target service;
and the calling module is used for calling the plurality of services related to the target service in sequence by using a plurality of threads according to the calling relation of the plurality of services related to the target service.
16. A computer-readable storage medium having stored thereon computer instructions which, when executed, implement the steps of the method of any one of claims 1 to 14.
CN202010974484.5A 2020-09-16 2020-09-16 Service calling method and device Pending CN112099973A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010974484.5A CN112099973A (en) 2020-09-16 2020-09-16 Service calling method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010974484.5A CN112099973A (en) 2020-09-16 2020-09-16 Service calling method and device

Publications (1)

Publication Number Publication Date
CN112099973A true CN112099973A (en) 2020-12-18

Family

ID=73759329

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010974484.5A Pending CN112099973A (en) 2020-09-16 2020-09-16 Service calling method and device

Country Status (1)

Country Link
CN (1) CN112099973A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170366623A1 (en) * 2016-06-15 2017-12-21 Futurewei Technologies, Inc. System, computer program, and method for dividing services into subsets based on interdependencies
CN109040152A (en) * 2017-06-08 2018-12-18 阿里巴巴集团控股有限公司 A kind of service request and providing method based on service orchestration, device and electronic equipment
CN110321119A (en) * 2018-03-30 2019-10-11 优酷网络技术(北京)有限公司 The generation method of data processing module, server and client side
CN111277639A (en) * 2020-01-16 2020-06-12 中国建设银行股份有限公司 Method and device for maintaining data consistency
CN111553652A (en) * 2020-04-23 2020-08-18 中国银行股份有限公司 Service processing method and device
CN111580793A (en) * 2020-04-30 2020-08-25 微民保险代理有限公司 Method, apparatus, computer device and storage medium for executing service

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170366623A1 (en) * 2016-06-15 2017-12-21 Futurewei Technologies, Inc. System, computer program, and method for dividing services into subsets based on interdependencies
CN109040152A (en) * 2017-06-08 2018-12-18 阿里巴巴集团控股有限公司 A kind of service request and providing method based on service orchestration, device and electronic equipment
CN110321119A (en) * 2018-03-30 2019-10-11 优酷网络技术(北京)有限公司 The generation method of data processing module, server and client side
CN111277639A (en) * 2020-01-16 2020-06-12 中国建设银行股份有限公司 Method and device for maintaining data consistency
CN111553652A (en) * 2020-04-23 2020-08-18 中国银行股份有限公司 Service processing method and device
CN111580793A (en) * 2020-04-30 2020-08-25 微民保险代理有限公司 Method, apparatus, computer device and storage medium for executing service

Similar Documents

Publication Publication Date Title
WO2020177533A1 (en) Electronic invoice identifier allocation method, and electronic ticket generating method, device and system
US7516176B2 (en) Distributed request and response queues for service processor
CN110633320A (en) Processing method, system, equipment and storage medium of distributed data service
CN111277639B (en) Method and device for maintaining data consistency
US20060167921A1 (en) System and method using a distributed lock manager for notification of status changes in cluster processes
CN111897633A (en) Task processing method and device
CN113067850B (en) Cluster arrangement system under multi-cloud scene
CN110413822B (en) Offline image structured analysis method, device and system and storage medium
CN111212085A (en) Internet of things platform synchronous calling method, Internet of things system and network equipment
CN111858007A (en) Task scheduling method and device based on message middleware
US20190317840A1 (en) Integrating transaction processing system interfaces with event-driven polyglot runtime modules
CN115544044A (en) Data consistency keeping method, device, equipment and storage medium
CN108108119B (en) Configuration method and device for extensible storage cluster things
CN113127564B (en) Parameter synchronization method and device
CN107025257A (en) A kind of transaction methods and device
CN111290842A (en) Task execution method and device
CN109558254B (en) Asynchronous callback method, system, device and computer readable storage medium
CN113760522A (en) Task processing method and device
US9910893B2 (en) Failover and resume when using ordered sequences in a multi-instance database environment
CN113645260A (en) Service retry method, device, storage medium and electronic equipment
CN111259032A (en) Service processing method and device
CN112099973A (en) Service calling method and device
US10728323B2 (en) Method and apparatus for operating infrastructure layer in cloud computing architecture
CN112328598B (en) ID generation method, ID generation device, electronic equipment and storage medium
CN112565340B (en) Service scheduling method, device, computer system and medium for distributed application

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination