CN111045833A - Interface calling method and device - Google Patents

Interface calling method and device Download PDF

Info

Publication number
CN111045833A
CN111045833A CN201811195680.1A CN201811195680A CN111045833A CN 111045833 A CN111045833 A CN 111045833A CN 201811195680 A CN201811195680 A CN 201811195680A CN 111045833 A CN111045833 A CN 111045833A
Authority
CN
China
Prior art keywords
target
service method
unique identifier
module
target service
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
CN201811195680.1A
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
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 Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201811195680.1A priority Critical patent/CN111045833A/en
Publication of CN111045833A publication Critical patent/CN111045833A/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
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/544Remote

Abstract

The invention discloses a method and a device for calling an interface, and relates to the technical field of computers. One embodiment of the method comprises: acquiring a request task of a local system, and acquiring a unique identifier of a target service method corresponding to the request task in a service registration module; judging whether the local system provides the target service method or not according to the unique identifier of the target service method; if yes, executing local interface calling, and if not, initiating remote interface calling. According to the embodiment, the unique identifier of the target service method of the request is inquired by the service registration module of the API general component, whether the local system provides the target service method is judged according to the inquiry result, and the interface calling of the specific service method is realized by the API general component, so that the problem that the system depends on an external APIJAR package can be solved, the coupling between the local system and the API of the external system is reduced, and the influence of the interface change of the external system on the local system is reduced.

Description

Interface calling method and device
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for calling an interface.
Background
When the engineering for developing the application program is larger and more, and the participators are more and more, the engineering is split into systems according to functions and services, so that the multiple systems are required to work cooperatively when developing one application program, and the cooperation among the systems can not be called by an interface. Currently, interface calls include two calling modes, namely an HTTP Call (namely, an application program interface Call based on an HTTP protocol) and an RPC Call (namely, a Remote Procedure Call which requests a service from a Remote computer program through a network without knowing underlying network technology), but the RPC Call is generally adopted in the application program based on efficiency.
In the prior art, a calling party of an RPC call depends on an API JAR packet defined by an interface, and the most common dependence mode is to directly introduce an external API JAR packet. Among them, the API is called Application Programming Interface, which is a predefined function for providing the Application and developer with the ability to access a set of routines based on certain software or hardware without accessing the source code or understanding the details of the internal working mechanism. The JAR package is an archive file of Java, a computer language that allows many files to be combined into one compressed file, is used not only for compression and distribution, but also for deploying and packaging libraries, components, and plug-ins, and can be used directly by tools like compilers and virtual machines.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art: in the method for RPC calling in the prior art, if the number of dependent interfaces is large, more external JAR packets are introduced, the size of an application program packet is increased, and code conflict is easily caused by introducing external JAR containers; and secondly, if the interface definition of the external API JAR package changes and needs to be upgraded, the system needs to reintroduce the external API JAR package and get on line.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for interface invocation, which can solve the problem that a system depends on an external API JAR package, reduce the coupling between a local system and an external system API, and reduce the influence of external system interface modification on the local system.
To achieve the above object, according to an aspect of an embodiment of the present invention, a method for interface invocation is provided.
The method for calling the interface comprises the following steps: acquiring a request task of a local system, and acquiring a unique identifier of a target service method corresponding to the request task in a service registration module; judging whether the local system provides the target service method or not according to the unique identifier of the target service method; if yes, executing local interface calling, and if not, initiating remote interface calling.
Optionally, before acquiring a request task of a local system and acquiring a unique identifier of a target service method corresponding to the request task in a service registration module, the method further includes: acquiring a service method provided by an application program; acquiring all service methods provided by an application program; determining a module providing the service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method for each service method; a provider of a remote interface for dynamically issuing the service method according to the service implementation class; storing the corresponding relation between the unique identifier of the module and the service implementation class in the service registration module; and storing the unique identifier of the module and the corresponding relation between the request behavior and the service method into the service registration module.
Optionally, the obtaining a request task of a local system, and obtaining a unique identifier of a target service method corresponding to the request task in a service registration module includes: according to the request task, determining the unique identifier and the target request behavior of a target module of the request task, inquiring the unique identifier of the target module and a target service method corresponding to the target request behavior in the service registration module, and acquiring the unique identifier of the target service method.
Optionally, determining whether the local system provides the target service method according to the unique identifier of the target service method includes: and determining a system for providing the target service method according to the unique identifier of the target service method, and judging whether the system is the local system, if so, considering that the local system provides the target service method, otherwise, considering that the local system does not provide the target service method.
Optionally, the executing the local interface call includes: in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the request task; converting the parameter information of the request task into a parameter format of the target service method according to the unique identifier of the target service method; based on reflection technology, calling the target service method according to the target service implementation class and the parameter format of the target service method, and receiving a returned calling result.
Optionally, initiating the remote interface call comprises: in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the request task, and searching a provider of a remote interface of the target service method according to the target service implementation class; and dynamically generating a calling party of a remote interface according to the unique identifier of the target module of the request task, initiating remote interface calling to the provider and receiving a returned calling result.
To achieve the above object, according to another aspect of the embodiments of the present invention, an apparatus for interface invocation is provided.
The device for calling the interface of the embodiment of the invention comprises: the system comprises an acquisition unit, a service registration module and a service processing unit, wherein the acquisition unit is used for acquiring a request task of a local system and acquiring a unique identifier of a target service method corresponding to the request task in the service registration module; the judging unit is used for judging whether the local system provides the target service method or not according to the unique identifier of the target service method; and the calling unit is used for executing local interface calling if the local interface is called, and initiating remote interface calling if the local interface is not called.
Optionally, the apparatus further comprises a storage unit configured to: acquiring a service method provided by an application program; determining a module providing the service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method for each service method; a provider of a remote interface for dynamically issuing the service method according to the service implementation class; storing the corresponding relation between the unique identifier of the module and the service implementation class in the service registration module; and storing the unique identifier of the module and the corresponding relation between the request behavior and the service method into the service registration module.
Optionally, the obtaining unit is further configured to: according to the request task, determining the unique identifier and the target request behavior of a target module of the request task, inquiring the unique identifier of the target module and a target service method corresponding to the target request behavior in the service registration module, and acquiring the unique identifier of the target service method.
Optionally, the determining unit is further configured to: and determining a system for providing the target service method according to the unique identifier of the target service method, and judging whether the system is the local system, if so, considering that the local system provides the target service method, otherwise, considering that the local system does not provide the target service method.
Optionally, the invoking unit is further configured to: in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the request task; converting the parameter information of the request task into a parameter format of the target service method according to the unique identifier of the target service method; based on reflection technology, calling the target service method according to the target service implementation class and the parameter format of the target service method, and receiving a returned calling result.
Optionally, the invoking unit is further configured to: in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the request task, and searching a provider of a remote interface of the target service method according to the target service implementation class; and dynamically generating a calling party of a remote interface according to the unique identifier of the target module of the request task, initiating remote interface calling to the provider and receiving a returned calling result.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided an electronic apparatus.
An electronic device of an embodiment of the present invention includes: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by one or more processors, the one or more processors realize the method called by the interface of the embodiment of the invention.
To achieve the above object, according to still another aspect of an embodiment of the present invention, there is provided a computer-readable medium.
A computer-readable medium of an embodiment of the present invention has a computer program stored thereon, and when the program is executed by a processor, the program implements a method of interface calling of an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: customizing a general API component, and realizing interface calling between different systems by means of the general API component, wherein the specific realization method comprises the following steps: the unique identification of the target service method of the request is inquired by a service registration module of the API general component, then whether the local system provides the target service method is judged according to the inquiry result, and interface calling of a specific service method is realized by the API general component, so that the problem that the system depends on an external API JAR package can be solved, the coupling of the local system and the API of the external system is reduced, and the influence of the interface change of the external system on the local system is reduced; in the embodiment of the invention, the information of the service methods which can be provided by the application program is stored in the service registration module in advance, so that the universal service registration module can be used for inquiring the target method information and the service implementation class of the request task, in addition, the invention also dynamically releases the provider of the remote interface of the service method by using the service implementation class in advance, so that the interface calling of the service method can be directly realized by using an API component, and the problem of depending on an external API JAR package is solved; according to the embodiment of the invention, whether the local system provides the target service method is judged according to the unique identifier of the target service method, so that local calling or remote calling can be carried out according to the actual situation, and the efficiency of interface calling is improved; in the embodiment of the invention, when the local calling is carried out, the target service realization class is searched, and then the reflection technology is used for achieving the purpose of dynamically calling different service methods according to the parameters; in the embodiment of the invention, when the remote interface is called remotely, the provider of the remote interface is inquired according to the service implementation class, and the caller of the remote interface is dynamically generated according to the unique identifier of the target module, so that the remote interface can be called.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main steps of a method of interface invocation according to an embodiment of the present invention;
FIG. 2 is a diagram showing a main flow of a method of interface calling according to a referential embodiment of the present invention;
FIG. 3 is a schematic diagram of the main modules of an apparatus for interface invocation according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 5 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
In the method for realizing RPC calling in the prior art, a local system needs to introduce a plurality of API JAR packages of an external system, and a universal API component is defined in the invention. The invention realizes the interface calling between different systems by the universal API component, but not the method of directly calling the external system API, thereby achieving the purpose of decoupling the system. In addition, because the universal API components in the invention are the same, the method further embodies that the local system can communicate with any system containing the API universal components without relying on an API JAR packet provided by an external system to make interface calls. Meanwhile, the method provided by the general API component is general enough, so even if the external system interface changes, the local system only needs to change the parameters when calling.
The generic API components of the invention include: the system comprises an API module, a service processing module, a service registration module, a service remote calling module and a service publishing module. Fig. 1 is a schematic diagram of the main steps of a method of interface invocation according to an embodiment of the present invention. As a reference embodiment of the present invention, as shown in fig. 1, the main steps of the method for interface invocation of the embodiment of the present invention may include:
step S101: and acquiring a request task of a local system, and acquiring a unique identifier of a target service method corresponding to the request task in a service registration module. The method comprises the steps of firstly acquiring a request task of a local system, for example, for a certain shopping application program, a certain system of the shopping application program requests to inquire the latest browsing record of a user. After the request task is obtained, the unique identifier of the service method corresponding to the request task needs to be queried in the service registration module according to the request task.
The API module is used for defining a general API interface of the interface calling method, and the entry parameter of the interface is parameter information of a request task, namely a self-defined API module SessionInfo object and a RequestInfo object. The SessionInfo object represents session information, and the object contains ID, Pin, Context, and Name attributes, which respectively represent a unique identifier of the session, a user account, a session Context (i.e., some attribute information contained in the session), and a system Name (for recording Name information of a caller), and furthermore, the data type of the Context attribute may be JAVA (i.e., a computer programming language) native Map type (i.e., a data structure type). The RequestInfo object represents a request object, which contains properties of IpAddr, Action, mulule and Params, where the four properties respectively represent an IP address, a request behavior, a unique identifier of a Module (in the present invention, the unique identifier is represented by a Module name, that is, a name property of a Module annotation on a service implementation class), and a request parameter (that is, parameter information required by a service method corresponding to the request behavior), and a data structure of the Params property is a JAVA native Map type.
As a referential embodiment of the present invention, before acquiring a request task of a local system in step S101 and acquiring a unique identifier of a target service method corresponding to the request task in a service registration module, a method invoked by an interface may further include: acquiring a service method provided by an application program; determining a module for providing a service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method aiming at each service method; a provider of a remote interface for dynamically issuing a service method according to the service implementation class; storing the corresponding relation between the unique identifier of the module and the service implementation class into a service registration module; and storing the unique identifier of the module and the corresponding relation between the request behavior and the service method into a service registration module.
The module for providing the service method in the invention means that the specific module for realizing the service method is different from the module in the API general component. The service publishing module is used for publishing the service method which can be provided by the system, and the specific implementation process is as follows: according to the self-defined annotation @ Module class (the Module class is a function block which is self-defined by the invention and provides some special services), a component marked with the @ Module is searched for from a Spring component (the component refers to a system of an application program in the invention) factory, and a service implementation class (namely, the self-defined class which can implement a service method) in an API Module is dynamically published into an interface which can be called remotely according to the name attribute (namely, the unique identification of the Module in the invention) of the Module annotation.
The service registration module is used for storing information of all service methods which can be provided by the application program, so that each system can comprise the same service registration module, or the whole application program only comprises one service registration module. An application context module: the service registration module is responsible for storing system information of the application program, and recording the relationship between the module of the remote service method provided in the application system and the service implementation class and the module release method information in the form of Key Value pair Key-Value. The information can be stored in the memory of the virtual machine of the local machine, and the memory data structure is a JAVA native Map structure, so that the quick access is convenient, the memory can be directly read, and a network is not needed. In a relational data structure of the unique identifier of the module and the service implementation class, Key is the unique identifier of the module, and Value is the service implementation class of the module; in a relational data structure of a module and a service method, Key is a unique identifier of the module and a request behavior, and Value is method information corresponding to the request behavior.
As a reference embodiment of the present invention, the step S101 of obtaining a request task of a local system, and obtaining a unique identifier of a target service method corresponding to the request task in a service registration module may include: according to the request task, determining the unique identifier and the target request behavior of the target module of the request task, inquiring the unique identifier of the target module and the target service method corresponding to the target request behavior in the service registration module, and acquiring the unique identifier of the target service method. The request task of the invention comprises the unique identification of the target module of the request task, namely the unique identification of the functional module executing the request task, and the target request behavior refers to the specific request behavior. Meanwhile, in the service registration module, all the relevant information of the application program which can provide the service method is automatically recorded in the initialization process of the application program. Therefore, the unique identifier of the target service method of the request task can be found in the service registration module.
Step S102: and judging whether the local system provides the target service method or not according to the unique identifier of the target service method.
In the present invention, the specific implementation manner may be: and determining a system for providing the target service method according to the unique identifier of the target service method, and judging whether the system is a local system, if so, considering that the local system provides the target service method, otherwise, considering that the local system does not provide the target service method. The step is to judge whether the target service method is provided locally, if so, the target method can be directly called locally, so that the time for calling the interface can be reduced, and the efficiency for calling the interface can be improved.
Step S103: if yes, executing local interface calling, and if not, initiating remote interface calling.
As another reference embodiment of the present invention, the executing the local interface call in step S103 may include: in a service registration module, inquiring a target service implementation class corresponding to the unique identifier of a target module of a request task; converting the parameter information of the request task into a parameter format of the target service method according to the unique identifier of the target service method; based on reflection technology, calling the target service method according to the target service implementation class and the parameter format of the target service method, and receiving a returned calling result. The reflection technology in the invention can be a JAVA reflection mechanism, that is, in the running state, for any class, all attributes and methods of the class can be known, for any object, any method and attribute of the class can be called, and the function of the dynamically acquired information and the method for dynamically calling the object is called as the reflection mechanism of the JAVA language.
The service processing module in the invention is used for: when the request behavior of the local system is executed, whether a provider exists locally for the requested service method is inquired from the service registration module according to the unique identifier of the module and the unique identifier of the method, if the provider exists locally, the corresponding service implementation class and the specific target method are found, the parameters are converted into the parameter format of the target method, the target method is called according to the JAVA reflection technology, and the returned calling result is received. If no service provider exists locally, the remote calling module of the dependent service initiates the remote calling to receive the returned calling result.
In this embodiment of the present invention, the initiating the remote interface call in step S103 may include: in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the request task, and searching a provider of a remote interface of a target service method according to the target service implementation class; and dynamically generating a calling party of the remote interface according to the unique identifier of the target module of the request task, initiating remote interface calling to a provider, and receiving a returned calling result. The service remote calling module is used for dynamically generating a calling party of a remote interface according to the unique identification of the target module in the request task and then initiating interface calling. Meanwhile, the invention can also realize the provider of the class dynamic release remote interface according to the target service.
And the returned result is the RpcResult object customized by the API module. The RpcResult object is used for representing a return value called by the interface, the RpcResult object comprises code, desc, data and success attributes, and the four attributes represent a result code, a result description, interface real data and an execution state. The real data type of the interface is a generic type, success is a JAVA basic data type and is used for indicating whether the interface calling is successful or not, true indicates success, and false indicates failure.
Fig. 2 is a schematic diagram of a main flow of a method of interface calling according to a referential embodiment of the present invention. As shown in fig. 2, the main flow of the method for interface invocation according to the embodiment of the present invention may include:
step S201: acquiring a service method provided by each system in an application program;
step S202: for each service method, a calling party of a remote interface for dynamically releasing the service method by using the service implementation class of the service method;
step S203: for each service method, storing relevant information of the service method in a service registration module, specifically realizing that: (1) acquiring a module providing the service method and a service implementation class corresponding to the module, and storing the corresponding relation between the unique identifier of the module and the service implementation class corresponding to the module into a service registration module; (2) determining a request behavior corresponding to the service method, and storing the unique identifier of the module and the corresponding relation between the request behavior and the service method into a registration unit service registration module;
step S204: receiving a request task of a local system, and determining a unique identifier and a target request behavior of a target module of the request task;
step S205: in a service registration module, inquiring the unique identifier of a target module and a target service method corresponding to a target request behavior, and acquiring the unique identifier of the target service method;
step S206: determining a system for providing the target service method according to the unique identifier of the target service method;
step S207: judging whether the determined system is a local system, if so, executing step S208, otherwise, executing step S211;
step S208: in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the task requested at this time;
step S209: converting the parameter information of the request task into a parameter format of the target service method according to the unique identifier of the target service method;
step S210: based on JAVA reflection technology, calling a target service method according to a target service implementation class and a parameter format of the target service method, and receiving a returned calling result;
step S211: in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the task requested at this time, and searching a provider of a remote interface of the target service method according to the target service implementation class;
step S212: and dynamically generating a calling party of the remote interface according to the unique identification of the target module of the task requested at this time, initiating remote interface calling to a provider and receiving a returned calling result.
According to the technical scheme of the interface calling of the embodiment of the invention, the general API component is customized, and the interface calling between different systems is realized by means of the general API component, and the specific realization method comprises the following steps: the unique identification of the target service method of the request is inquired by a service registration module of the API general component, then whether the local system provides the target service method is judged according to the inquiry result, and interface calling of a specific service method is realized by the API general component, so that the problem that the system depends on an external API JAR package can be solved, the coupling of the local system and the API of the external system is reduced, and the influence of the interface change of the external system on the local system is reduced; in the embodiment of the invention, the information of the service methods which can be provided by the application program is stored in the service registration module in advance, so that the universal service registration module can be used for inquiring the target method information and the service implementation class of the request task, in addition, the invention also dynamically releases the provider of the remote interface of the service method by using the service implementation class in advance, so that the interface calling of the service method can be directly realized by using an API component, and the problem of depending on an external API JAR package is solved; according to the embodiment of the invention, whether the local system provides the target service method is judged according to the unique identifier of the target service method, so that local calling or remote calling can be carried out according to the actual situation, and the efficiency of interface calling is improved; in the embodiment of the invention, when the local calling is carried out, the target service realization class is searched, and then the reflection technology is used for achieving the purpose of dynamically calling different service methods according to the parameters; in the embodiment of the invention, when the remote interface is called remotely, the provider of the remote interface is inquired according to the service implementation class, and the caller of the remote interface is dynamically generated according to the unique identifier of the target module, so that the remote interface can be called.
Fig. 3 is a schematic diagram of main modules of an interface-invoked apparatus according to an embodiment of the present invention. As shown in fig. 3, the apparatus 300 for interface invocation according to the embodiment of the present invention mainly includes the following modules: an acquisition unit 301, a judgment unit 302 and a calling unit 303.
The obtaining unit 301 may be configured to obtain a request task of a local system, and obtain, in the service registration module, a unique identifier of a target service method corresponding to the request task. The determining unit 302 may be configured to determine whether the local system provides the target service method according to the unique identifier of the target service method. The invoking unit 303 may be configured to execute a local interface invocation if the local interface invocation is performed, and initiate a remote interface invocation if the remote interface invocation is not performed.
In the embodiment of the present invention, the interface calling device may further include a storage unit (not shown in the figure). The memory cell is operable to: acquiring a service method provided by an application program; determining a module for providing a service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method aiming at each service method; a provider of a remote interface for dynamically issuing a service method according to the service implementation class; storing the corresponding relation between the unique identifier of the module and the service implementation class into a service registration module; and storing the unique identifier of the module and the corresponding relation between the request behavior and the service method into a service registration module.
In this embodiment of the present invention, the obtaining unit 301 may further be configured to: according to the request task, determining the unique identifier and the target request behavior of the target module of the request task, inquiring the unique identifier of the target module and the target service method corresponding to the target request behavior in the service registration module, and acquiring the unique identifier of the target service method.
In this embodiment of the present invention, the determining unit 302 may further be configured to: and determining a system for providing the target service method according to the unique identifier of the target service method, and judging whether the system is a local system, if so, considering that the local system provides the target service method, otherwise, considering that the local system does not provide the target service method.
In this embodiment of the present invention, the invoking unit 303 may be further configured to: in a service registration module, inquiring a target service implementation class corresponding to the unique identifier of a target module of a request task; converting the parameter information of the request task into a parameter format of the target service method according to the unique identifier of the target service method; based on reflection technology, calling the target service method according to the target service implementation class and the parameter format of the target service method, and receiving a returned calling result.
In this embodiment of the present invention, the invoking unit 303 may be further configured to: in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the request task, and searching a provider of a remote interface of a target service method according to the target service implementation class; and dynamically generating a calling party of the remote interface according to the unique identifier of the target module of the request task, initiating remote interface calling to a provider, and receiving a returned calling result.
It can be seen from the above description that the general API component is customized, and the general API component is used to implement interface call between different systems, and the specific implementation method is: the unique identification of the target service method of the request is inquired by a service registration module of the API general component, then whether the local system provides the target service method is judged according to the inquiry result, and interface calling of a specific service method is realized by the API general component, so that the problem that the system depends on an external API JAR package can be solved, the coupling of the local system and the API of the external system is reduced, and the influence of the interface change of the external system on the local system is reduced; in the embodiment of the invention, the information of the service methods which can be provided by the application program is stored in the service registration module in advance, so that the universal service registration module can be used for inquiring the target method information and the service implementation class of the request task, in addition, the invention also dynamically releases the provider of the remote interface of the service method by using the service implementation class in advance, so that the interface calling of the service method can be directly realized by using an API component, and the problem of depending on an external API JAR package is solved; according to the embodiment of the invention, whether the local system provides the target service method is judged according to the unique identifier of the target service method, so that local calling or remote calling can be carried out according to the actual situation, and the efficiency of interface calling is improved; in the embodiment of the invention, when the local calling is carried out, the target service realization class is searched, and then the reflection technology is used for achieving the purpose of dynamically calling different service methods according to the parameters; in the embodiment of the invention, when the remote interface is called remotely, the provider of the remote interface is inquired according to the service implementation class, and the caller of the remote interface is dynamically generated according to the unique identifier of the target module, so that the remote interface can be called.
Fig. 4 illustrates an exemplary system architecture 400 of an apparatus to which the method of interface invocation or interface invocation of embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 401, 402, 403. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the method for interface calling provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, the device for interface calling is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present invention may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes an acquisition unit, a judgment unit, and a call unit. The names of the units do not form a limitation on the units themselves in some cases, for example, the obtaining unit may also be described as a unit that obtains a request task of a local system and obtains a unique identifier of a target service method corresponding to the request task in the service registration module.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: acquiring a request task of a local system, and acquiring a unique identifier of a target service method corresponding to the request task in a service registration module; judging whether the local system provides the target service method or not according to the unique identifier of the target service method; if yes, executing local interface calling, and if not, initiating remote interface calling.
According to the technical scheme of the embodiment of the invention, a universal API component is customized, and interface calling among different systems is realized by means of the universal API component, and the specific realization method comprises the following steps: the unique identification of the target service method of the request is inquired by a service registration module of the API general component, then whether the local system provides the target service method is judged according to the inquiry result, and interface calling of a specific service method is realized by the API general component, so that the problem that the system depends on an external API JAR package can be solved, the coupling of the local system and the API of the external system is reduced, and the influence of the interface change of the external system on the local system is reduced; in the embodiment of the invention, the information of the service methods which can be provided by the application program is stored in the service registration module in advance, so that the universal service registration module can be used for inquiring the target method information and the service implementation class of the request task, in addition, the invention also dynamically releases the provider of the remote interface of the service method by using the service implementation class in advance, so that the interface calling of the service method can be directly realized by using an API component, and the problem of depending on an external API JAR package is solved; according to the embodiment of the invention, whether the local system provides the target service method is judged according to the unique identifier of the target service method, so that local calling or remote calling can be carried out according to the actual situation, and the efficiency of interface calling is improved; in the embodiment of the invention, when the local calling is carried out, the target service realization class is searched, and then the reflection technology is used for achieving the purpose of dynamically calling different service methods according to the parameters; in the embodiment of the invention, when the remote interface is called remotely, the provider of the remote interface is inquired according to the service implementation class, and the caller of the remote interface is dynamically generated according to the unique identifier of the target module, so that the remote interface can be called.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (14)

1. A method for interface invocation, comprising:
acquiring a request task of a local system, and acquiring a unique identifier of a target service method corresponding to the request task in a service registration module;
judging whether the local system provides the target service method or not according to the unique identifier of the target service method;
if yes, executing local interface calling, and if not, initiating remote interface calling.
2. The method according to claim 1, wherein before obtaining the request task of the local system and obtaining the unique identifier of the target service method corresponding to the request task in the service registration module, the method further comprises:
acquiring a service method provided by an application program;
determining a module providing the service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method for each service method;
a provider of a remote interface for dynamically issuing the service method according to the service implementation class;
storing the corresponding relation between the unique identifier of the module and the service implementation class in the service registration module;
and storing the unique identifier of the module and the corresponding relation between the request behavior and the service method into the service registration module.
3. The method according to claim 2, wherein obtaining a request task of a local system and obtaining a unique identifier of a target service method corresponding to the request task in a service registration module comprises:
according to the request task, determining the unique identifier and the target request behavior of a target module of the request task, inquiring the unique identifier of the target module and a target service method corresponding to the target request behavior in the service registration module, and acquiring the unique identifier of the target service method.
4. The method of claim 1, wherein determining whether the local system provides the target service method according to the unique identifier of the target service method comprises:
and determining a system for providing the target service method according to the unique identifier of the target service method, and judging whether the system is the local system, if so, considering that the local system provides the target service method, otherwise, considering that the local system does not provide the target service method.
5. The method of claim 2, wherein performing a local interface call comprises:
in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the request task;
converting the parameter information of the request task into a parameter format of the target service method according to the unique identifier of the target service method;
based on reflection technology, calling the target service method according to the target service implementation class and the parameter format of the target service method, and receiving a returned calling result.
6. The method of claim 2, wherein initiating a remote interface call comprises:
in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the request task, and searching a provider of a remote interface of the target service method according to the target service implementation class;
and dynamically generating a calling party of a remote interface according to the unique identifier of the target module of the request task, initiating remote interface calling to the provider and receiving a returned calling result.
7. An apparatus for interface invocation, comprising:
the system comprises an acquisition unit, a service registration module and a service processing unit, wherein the acquisition unit is used for acquiring a request task of a local system and acquiring a unique identifier of a target service method corresponding to the request task in the service registration module;
the judging unit is used for judging whether the local system provides the target service method or not according to the unique identifier of the target service method;
and the calling unit is used for executing local interface calling if the local interface is called, and initiating remote interface calling if the local interface is not called.
8. The apparatus of claim 7, further comprising a storage unit to:
acquiring a service method provided by an application program;
determining a module providing the service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method for each service method;
a provider of a remote interface for dynamically issuing the service method according to the service implementation class;
storing the corresponding relation between the unique identifier of the module and the service implementation class in the service registration module;
and storing the unique identifier of the module and the corresponding relation between the request behavior and the service method into the service registration module.
9. The apparatus of claim 8, wherein the obtaining unit is further configured to:
according to the request task, determining the unique identifier and the target request behavior of a target module of the request task, inquiring the unique identifier of the target module and a target service method corresponding to the target request behavior in the service registration module, and acquiring the unique identifier of the target service method.
10. The apparatus of claim 7, wherein the determining unit is further configured to:
and determining a system for providing the target service method according to the unique identifier of the target service method, and judging whether the system is the local system, if so, considering that the local system provides the target service method, otherwise, considering that the local system does not provide the target service method.
11. The apparatus of claim 8, wherein the invoking unit is further configured to:
in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the request task;
converting the parameter information of the request task into a parameter format of the target service method according to the unique identifier of the target service method;
based on reflection technology, calling the target service method according to the target service implementation class and the parameter format of the target service method, and receiving a returned calling result.
12. The apparatus of claim 8, wherein the invoking unit is further configured to:
in the service registration module, inquiring a target service implementation class corresponding to the unique identifier of the target module of the request task, and searching a provider of a remote interface of the target service method according to the target service implementation class;
and dynamically generating a calling party of a remote interface according to the unique identifier of the target module of the request task, initiating remote interface calling to the provider and receiving a returned calling result.
13. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
14. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-6.
CN201811195680.1A 2018-10-15 2018-10-15 Interface calling method and device Pending CN111045833A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811195680.1A CN111045833A (en) 2018-10-15 2018-10-15 Interface calling method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811195680.1A CN111045833A (en) 2018-10-15 2018-10-15 Interface calling method and device

Publications (1)

Publication Number Publication Date
CN111045833A true CN111045833A (en) 2020-04-21

Family

ID=70230239

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811195680.1A Pending CN111045833A (en) 2018-10-15 2018-10-15 Interface calling method and device

Country Status (1)

Country Link
CN (1) CN111045833A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111538492A (en) * 2020-04-24 2020-08-14 浙江大搜车软件技术有限公司 Policy implementation calling method and device, electronic equipment and storage medium
CN111970349A (en) * 2020-08-07 2020-11-20 中国建设银行股份有限公司 Communication system, method, device, equipment and medium based on remote procedure call
CN112084046A (en) * 2020-09-12 2020-12-15 朱领军 Dubbo generalization interface calling method and device
CN112416612A (en) * 2020-08-13 2021-02-26 上海哔哩哔哩科技有限公司 Service calling method and device, computer equipment and readable storage medium
CN112783978A (en) * 2021-01-28 2021-05-11 北京东方优播网络科技有限公司 Data transmission method, device, computer system and storage medium
CN113760318A (en) * 2020-11-24 2021-12-07 北京沃东天骏信息技术有限公司 Information processing method, information processing apparatus, server, and storage medium
CN113779467A (en) * 2021-01-05 2021-12-10 北京沃东天骏信息技术有限公司 Method and device for visualizing functional component management

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050234873A1 (en) * 2003-10-24 2005-10-20 Microsoft Corporation, Redmond, Wa Service discovery and publication
CN101017447A (en) * 2007-02-13 2007-08-15 华为技术有限公司 IDE calling device and calling method therefor
CN101047512A (en) * 2006-03-31 2007-10-03 国际商业机器公司 Service logger and correlation system and method
CN102810069A (en) * 2012-07-16 2012-12-05 深圳市融创天下科技股份有限公司 JAVA object requesting and responding methods, devices and systems and terminal
US8555297B1 (en) * 2008-09-29 2013-10-08 Emc Corporation Techniques for performing a remote procedure call using remote procedure call configuration information
CN105450757A (en) * 2015-12-02 2016-03-30 联动优势电子商务有限公司 Service management method and system
CN106412009A (en) * 2016-08-29 2017-02-15 郑州悉知信息科技股份有限公司 Interface calling method and device
CN107360261A (en) * 2017-09-07 2017-11-17 北京奇艺世纪科技有限公司 A kind of HTTP request processing method, device and electronic equipment
CN108134766A (en) * 2016-12-01 2018-06-08 阿里巴巴集团控股有限公司 A kind of method, apparatus, system, server and client for servicing publication

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050234873A1 (en) * 2003-10-24 2005-10-20 Microsoft Corporation, Redmond, Wa Service discovery and publication
CN101047512A (en) * 2006-03-31 2007-10-03 国际商业机器公司 Service logger and correlation system and method
CN101017447A (en) * 2007-02-13 2007-08-15 华为技术有限公司 IDE calling device and calling method therefor
US8555297B1 (en) * 2008-09-29 2013-10-08 Emc Corporation Techniques for performing a remote procedure call using remote procedure call configuration information
CN102810069A (en) * 2012-07-16 2012-12-05 深圳市融创天下科技股份有限公司 JAVA object requesting and responding methods, devices and systems and terminal
CN105450757A (en) * 2015-12-02 2016-03-30 联动优势电子商务有限公司 Service management method and system
CN106412009A (en) * 2016-08-29 2017-02-15 郑州悉知信息科技股份有限公司 Interface calling method and device
CN108134766A (en) * 2016-12-01 2018-06-08 阿里巴巴集团控股有限公司 A kind of method, apparatus, system, server and client for servicing publication
CN107360261A (en) * 2017-09-07 2017-11-17 北京奇艺世纪科技有限公司 A kind of HTTP request processing method, device and electronic equipment

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111538492A (en) * 2020-04-24 2020-08-14 浙江大搜车软件技术有限公司 Policy implementation calling method and device, electronic equipment and storage medium
CN111538492B (en) * 2020-04-24 2023-12-19 浙江大搜车软件技术有限公司 Method and device for calling policy implementation, electronic equipment and storage medium
CN111970349A (en) * 2020-08-07 2020-11-20 中国建设银行股份有限公司 Communication system, method, device, equipment and medium based on remote procedure call
CN112416612A (en) * 2020-08-13 2021-02-26 上海哔哩哔哩科技有限公司 Service calling method and device, computer equipment and readable storage medium
CN112416612B (en) * 2020-08-13 2023-03-28 上海哔哩哔哩科技有限公司 Service calling method and device, computer equipment and readable storage medium
CN112084046A (en) * 2020-09-12 2020-12-15 朱领军 Dubbo generalization interface calling method and device
CN113760318A (en) * 2020-11-24 2021-12-07 北京沃东天骏信息技术有限公司 Information processing method, information processing apparatus, server, and storage medium
CN113779467A (en) * 2021-01-05 2021-12-10 北京沃东天骏信息技术有限公司 Method and device for visualizing functional component management
CN112783978A (en) * 2021-01-28 2021-05-11 北京东方优播网络科技有限公司 Data transmission method, device, computer system and storage medium

Similar Documents

Publication Publication Date Title
CN111045833A (en) Interface calling method and device
CN108255615B (en) Cross-language calling method, server and storage medium
CN112114979B (en) Remote procedure call method and device
CN111460129B (en) Method, device, electronic equipment and storage medium for generating identification
CN111427701A (en) Workflow engine system and business processing method
CN112507005B (en) Method and device for processing message
CN110704200A (en) Method and device for converting call interface
CN113900907B (en) Mapping construction method and system
CN109981546B (en) Method and device for acquiring remote call relation between application modules
CN109471713B (en) Method and device for inquiring information
CN113282589A (en) Data acquisition method and device
CN110764769B (en) Method and device for processing user request
CN112948138A (en) Method and device for processing message
CN115080274A (en) Service processing method, device and system and interface mapping system
CN113779122B (en) Method and device for exporting data
CN113760487B (en) Service processing method and device
CN112905273A (en) Service calling method and device
CN113765983A (en) Site service deployment method and device
CN109120692B (en) Method and apparatus for processing requests
CN109660573B (en) Data transmission method and device
CN113326060A (en) Service request processing method, device and system and service configuration method and device
CN113779018A (en) Data processing method and device
CN113760693A (en) Method and apparatus for local debugging of microservice systems
CN114979295B (en) Gateway management method and device
CN112650601B (en) Method, apparatus, device, storage medium, and program for opening applet across hosts

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