Detailed Description
A logic structure of an application scenario of the embodiment of the present application is shown in fig. 1, when a plurality of service users need to invoke service interfaces of a plurality of service providers, compared with the implementation of changing each service user and each service provider, one to a plurality of service users and one to a plurality of service providers can be respectively accessed to a gateway, and the embodiment of the present application is run on the gateway, and a request and a response for invoking the interfaces between the service users and the service providers are transferred, and by carrying an association field uniquely representing a service identifier in a user invocation request in a call request initiated to the service provider, an association field can be obtained from a call response returned by the service provider, so as to further obtain a service identifier of the user corresponding to the response, thereby avoiding full-table scanning of a service user database and not causing a decrease in database operation speed, to solve the problems existing in the prior art.
In embodiments of the present application, the gateway is mutually accessible with each service consumer and each service provider that is accessed. It should be noted that the gateway, the service user and the service provider may run on separate physical or logical devices respectively; the gateway can also be used as a functional module to run on equipment of a service user and used for calling one service interface to a plurality of service providers; the gateway can also be used as a functional module to run on a device where a service provider is located, and used as a preposed functional module of a service interface of the gateway for being called by one to a plurality of service users.
The embodiments of the present application may be executed on any device with computing and storage capabilities, for example, a physical device or a logical device such as a mobile phone, a tablet Computer, a PC (Personal Computer), a notebook, a server, a virtual machine, etc.; the functions of the embodiments of the present application may be implemented by two or more physical or logical devices sharing different responsibilities and cooperating with each other.
In the embodiment of the present application, a flow of a method for implementing asynchronous invocation of a service interface is shown in fig. 2, and the method is applied to a gateway accessing one to a plurality of service users and one to a plurality of service providers.
Step 210, after receiving a user call request including a call interface and a user service identifier from a service user, generating an association value according to at least one association field in the user call request, storing a corresponding relationship between the association value and the user service identifier, and acquiring a provider service identifier according to the call interface.
When a certain service process performed at a service user needs to call a service interface of a certain service provider, a user calling request is generated and sent to the gateway.
The use calling request comprises a user service identifier and a calling interface. The service identifier of the user is an identifier given by the service user to a service process for calling the service interface, and the service user can uniquely represent the service process; if multiple service interface calls are required in the service process, the user service identifier is used in each user call request. The calling interface is a service interface called by a service user and can only represent one service interface in all service interfaces accessed by the gateway; the content included in the calling interface may be determined according to the specific implementation of the actual application scenario, for example, the application scenario of a service provider is accessed to the gateway, and the calling interface may be a service interface identifier; for an application scenario where a gateway accesses multiple service providers, the call interface may be a service provider identifier and a service interface identifier.
In the embodiment of the application, the user invocation request carries one or more associated fields, and the combination of all the associated fields can uniquely represent the service process of the service user on the gateway, or all the associated fields can uniquely represent the service identifier of the user. It should be noted that, the association field may include a user service identifier and/or a call interface. Similarly, which contents are used as the associated fields can be selected according to the specific implementation of the actual application scenario, for example, an application scenario where a service user accesses a gateway may use a user service identifier, or a user service identifier and a call interface as the associated fields; for an application scenario that the gateway accesses a plurality of service users, the service user identifier and the user service identifier may be used as associated fields, or the service user identifier, the user service identifier and the calling interface may be used as associated fields.
After receiving a user calling request sent by a service user, the gateway extracts all the associated fields from the user calling request, generates associated values according to all the associated fields, and stores the corresponding relation between the associated values and the user service identifier.
In some application scenarios, different invocation interfaces may employ different associated fields or combinations of associated fields. The gateway can preset the corresponding relation between the calling interface and the associated rule of the user, obtain the associated rule of the user from the calling interface in the calling request of the user, extract all the associated fields from the calling request of the user according to the associated fields specified in the associated rule of the user, and combine all the associated fields according to the combination mode specified in the associated rule of the user.
The method for generating the association value according to all the association fields may be selected by referring to the length of all the association fields, the speed requirement for calling the gateway processing interface, and the like, and the embodiment of the present application is not limited. For example, if the combined length of all the associated fields is short, the associated field combination (only one associated field is the associated field itself) can be directly used as the associated value; for another example, if the length of the associated field combination is long or the gateway is required to be able to process the interface call quickly, the combination of all associated fields may be input to a predetermined digest algorithm, and the digest value output by the digest algorithm is used as the associated value. The digest Algorithm may be CRC (Cyclic Redundancy Check), MD (Message-digest Algorithm), SHA (Secure Hash Algorithm), or the like. It should be noted that, in the above two examples, if there is only one associated field, the associated field combination is the associated field itself.
When only one service user or the service identifiers of the service users are not the same in the application scenario in which the embodiment of the application is located, the gateway can directly store the corresponding relationship between the association value and the service identifier of the user. If the service identifiers of the service users are probably the same, two database tables can be adopted on the gateway: and the user service identifier record table and the association relation table are used for storing the corresponding relation between the association value and the user service identifier. Specifically, the gateway generates a unique index code for the user call request (the index code is unique in the user service identification record table), and stores the corresponding relation between the index code and the user service identification in the user service identification record table by taking the index code as a main key; after generating the association value, the gateway saves the corresponding relation between the association value and the index code in the association relation table by taking the association value as a main key. Therefore, the associated value of the same user calling request can be corresponding to the user service identifier through the index code.
And according to the calling interface in the calling request of the user, the gateway acquires the provider service identifier of the calling interface and is used for carrying out the service process at the service provider when the service interface is called. According to the specific implementation of the service provider and the service interface thereof, the gateway may obtain the provider service identifier in different manners, which is not limited in the embodiments of the present application. For example, when there are multiple service interfaces using different interface identification rules (rules for generating provider service identifiers), the corresponding relationship between the calling interface and the interface identification rule may be stored in the gateway, and after receiving a user calling request, the provider service identifier may be generated using the interface identification rule corresponding to the calling interface. For another example, the gateway may request the provider service identifier from the calling interface in the user calling request, and the service provider where the calling interface is located generates a new provider service identifier according to the generation rule of the service identifier of the service provider, and returns the new provider service identifier to the gateway for use.
Step 220, based on the user calling request, sending a gateway calling request to the service provider with the calling interface.
The gateway generates a gateway calling request corresponding to the user calling request by adopting a provider service identifier on the basis of the user calling request, and sends the gateway calling request to a service provider where a calling interface in the user calling request is located. The gateway call request carries all the associated fields in the user call request and the provider service identifier.
The gateway calling request is used for calling the service interface by adopting the provider service identifier according to the specification of the service interface.
Step 230, after receiving the gateway call response including the association field from the service provider from the call interface, generating an association value according to the association field in the gateway call response, and acquiring the service identifier of the user corresponding to the association value.
And the service provider receives the gateway calling request from the calling interface, executes the service process with the provider service identifier in the gateway calling request, encapsulates the execution result and all associated fields in the gateway calling request in a gateway calling response, and sends the gateway calling response to the service provider.
In an application scenario that different calling interfaces adopt different associated fields or associated field combinations, a corresponding relation between the calling interface and a provider associated rule is preset on a gateway, the gateway can obtain the provider associated rule according to the corresponding relation by using the calling interface which sends a gateway calling response, then extracts all associated fields from the gateway calling response according to the associated fields specified in the provider associated rule, and combines all associated fields according to a combination mode specified in the provider associated rule. The user association rule and the provider association rule of the same calling interface can generate the same association field combination based on the same association field content.
In the same manner as in step 210, the gateway generates an association value according to the combination of the association fields in the gateway call response, and obtains the user identifier of the reply object (i.e., the service process of the service user) of the gateway call response by using the correspondence between the association value stored in step 210 and the user service identifier. In an application scenario that a gateway stores a corresponding relation between an association value and a user service identifier by using a user service identifier record table and an association relation table, after the gateway generates the association value according to the combination of association fields in a gateway call response, an index code corresponding to the association value is searched in the association relation table, then the user service identifier corresponding to the index code is searched in the user service identifier record table, and the user service identifier corresponding to the association value can be obtained.
Step 240, based on the gateway call response, sending the consumer call response including the consumer service identifier to the service consumer.
The gateway generates a user calling response corresponding to the gateway calling response by using the user service identifier on the basis of the gateway calling response, and sends the user calling response to the service user initiating the corresponding user calling request. The user calling response carries the execution result of the service interface calling and the user service identifier, so that the service user can identify which user calling request the user calling response is to.
The gateway can identify the corresponding gateway call request and gateway call response by carrying the same associated field, and identify the corresponding service user call request and service user call response by carrying the same user service identifier.
In the embodiment of the application, the gateway generates the associated value according to the associated field which uniquely represents the service identifier of the user in the user calling request, and carries the associated field in the gateway calling request initiated to the service provider, so that the service provider returns the gateway calling response with the associated field, and returns the user calling response with the service identifier of the user to the service user according to the corresponding relation between the associated value and the service identifier of the user, thereby respectively adopting the service identifier of the user and the service identifier of the provider to carry out the service processes of the service user and the service provider, avoiding the full-table scanning of the database of the service user and avoiding the reduction of the operation speed of the database.
In an application example of the present application, multiple service users and multiple service providers access the same gateway, each service user and each service provider have their own traffic serial number (traffic identifier) generation rule, and the service provider opens a service interface available for invocation to an external system. When a service user calls a service interface of a service provider in a business process, the interaction flow of the service user, the gateway and the service provider is shown in fig. 3.
The service user generates the service serial number of the user according to the database-dividing and table-dividing rules of the system, encapsulates the service serial number of the user, the service user identifier, the service provider identifier and the service interface identifier in the user calling request and sends the user calling request to the gateway. The calling interface is a service provider identifier and a service interface identifier.
The gateway maintains a user association table and a provider association table, which are respectively used for storing the corresponding relation between the calling interface and the user association rule and the corresponding relation between the calling interface and the provider association rule. After receiving the user calling request, the gateway extracts the service provider identifier and the service interface identifier from the user calling request, and finds out the user association rule for the calling interface in the user association table, namely: and using the user identifier, the service serial number of the user and the provider identifier as associated fields, and combining the associated fields in the sequence. The gateway extracts the user identifier, the user service serial number and the provider identifier from the user call request according to the user association rule, generates an associated field combination, and takes an MD5(Message Digest Algorithm version 5) value of the associated field combination as an associated value.
The gateway generates an index code for the user calling request, takes the index code as a main key, and stores the corresponding relation between the index code and the user service flow number in the user calling request in the user service flow water meter; and storing the corresponding relation between the associated value and the index code in an associated relation table by taking the associated value as a main key.
And the gateway generates a provider service serial number according to a provider serial number generation rule (interface identification rule) of the calling interface.
And the gateway packages the user identifier, the user service serial number, the provider identifier, the provider service serial number and other service information in the user calling request into the gateway calling request on the basis of the user calling request, and sends the gateway calling request to the service provider where the calling interface is positioned.
And the service provider executes the service process of the calling interface by adopting the provider service serial number according to the gateway calling request to obtain an execution result. The service provider encapsulates the execution result, the user identifier, the user service serial number and the provider identifier in a gateway calling response, and replies to the gateway through the calling interface.
And the gateway searches the association table of the provider by using a calling interface for receiving the gateway calling response to obtain the association rule of the provider. The provider association rule matches with the user association rule of the same invocation interface, namely: and using the user identifier, the service serial number of the user and the provider identifier as associated fields, and combining the associated fields in the sequence. And the gateway extracts the user identifier, the user service serial number and the provider identifier from the gateway calling response according to the provider association rule and generates an association field combination. The gateway calculates the MD5 value for the associated field combination as the associated value.
The gateway searches the association relation table according to the association value to obtain an index code; and searching the service flow water meter of the user by the obtained index code to obtain the service flow number of the user.
The gateway packages the service serial number and the execution result of the user in the user calling response based on the gateway calling response, and sends the service user who initiates the user calling request with the service serial number of the user.
And the service user determines the service process applying the execution result according to the service serial number of the user and performs subsequent service processing according to the service logic of the service user.
Corresponding to the above flow implementation, an embodiment of the present application further provides an implementation apparatus for asynchronous call of a service interface applied to a gateway. The apparatus may be implemented by software, or by hardware, or by a combination of hardware and software. Taking a software implementation as an example, the logical device is formed by reading a corresponding computer program instruction into a memory for running through a Central Processing Unit (CPU) of the device. In terms of hardware, in addition to the CPU, the memory, and the nonvolatile memory shown in fig. 4, the device in which the service interface asynchronous call implementation apparatus is located generally includes other hardware such as a chip for performing wireless signal transmission and reception and/or other hardware such as a board for implementing a network communication function.
Fig. 5 is a device for implementing asynchronous invocation of service interfaces, which is applied to a gateway accessing one service provider to multiple service users and one service provider to multiple service providers, and includes a user request processing unit, a user request forwarding unit, a gateway response processing unit, and a gateway response forwarding unit, where:
the user request processing unit is used for generating an association value according to at least one association field in the user calling request after receiving the user calling request which comes from a service user and comprises a calling interface and a user service identifier, storing the corresponding relation between the association value and the user service identifier and acquiring the provider service identifier according to the calling interface; all the associated fields can uniquely represent the service identifier of the user;
the user request forwarding unit is used for sending a gateway calling request to a service provider with the calling interface based on the user calling request, wherein the gateway calling request comprises a provider service identifier and all associated fields;
the gateway response processing unit is used for generating a correlation value according to the correlation field in the gateway calling response after receiving the gateway calling response including the correlation field from the service provider from the calling interface, and acquiring a user service identifier corresponding to the correlation value;
the gateway response forwarding unit is used for sending a user calling response comprising the user service identification to the service user based on the gateway calling response.
Optionally, the storing, by the user request processing unit, a corresponding relationship between the association value and the user service identifier includes: generating a unique index code for the user calling request, storing the corresponding relation between the index code and the user service identifier by taking the index code as a main key in a user service identifier record table, and storing the corresponding relation between an association value and the index code by taking the association value as the main key in an association relation table; the gateway response processing unit acquires the user service identifier corresponding to the associated value, and the method comprises the following steps: and searching an index code corresponding to the association value in the association relation table, and searching a user service identifier corresponding to the index code in a user service identifier record table.
Optionally, the association value is generated by using a predetermined digest algorithm with a combination of all the association fields as input.
Optionally, the obtaining, by the user request processing unit, the provider service identifier according to the call interface includes: and generating a provider service identifier according to an interface identifier rule corresponding to the calling interface.
In one example, the generating, by the consumer request processing unit, an association value according to at least one association field in the consumer invocation request includes: extracting the associated fields from the user calling request according to the associated fields and the specified combination mode specified by the user associated rule corresponding to the calling interface in the user calling request, combining the associated fields, and generating an associated value by adopting the associated field combination; the gateway response processing unit generates a correlation value according to the correlation field in the gateway call response, and the method comprises the following steps: and extracting the associated fields from the gateway call response according to the associated fields specified by the provider associated rule corresponding to the call interface for receiving the gateway call response and the specified combination mode, combining the associated fields, and generating an associated value by adopting the associated field combination.
In the above example, the user service identifier includes: the user service serial number, the provider service identification includes: a provider service flow number; the association field includes: a user identifier, a user service serial number, and a provider identifier.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.