CN111045833B - Interface calling method and device - Google Patents

Interface calling method and device Download PDF

Info

Publication number
CN111045833B
CN111045833B CN201811195680.1A CN201811195680A CN111045833B CN 111045833 B CN111045833 B CN 111045833B CN 201811195680 A CN201811195680 A CN 201811195680A CN 111045833 B CN111045833 B CN 111045833B
Authority
CN
China
Prior art keywords
target
service method
module
service
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.)
Active
Application number
CN201811195680.1A
Other languages
Chinese (zh)
Other versions
CN111045833A (en
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/CN111045833B/en
Publication of CN111045833A publication Critical patent/CN111045833A/en
Application granted granted Critical
Publication of CN111045833B publication Critical patent/CN111045833B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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

Landscapes

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

Abstract

The 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 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 the local interface call, and if not, initiating the remote interface call. According to the embodiment, the service registration module of the API universal component is used for inquiring the unique identification of the requested target service method, then whether the local system provides the target service method is judged according to the inquiring result, and the interface call of the specific service method is realized by means of the API universal 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 present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for calling an interface.
Background
When the engineering for developing the application program is bigger and bigger, and more staff participate, the engineering is divided into systems according to functions and services, so that the development of the application program needs to be cooperated by a plurality of systems, and the cooperation among the systems is not called by an interface. Currently, there are two call modes of HTTP call (i.e., application program interface call based on the HTTP protocol) and RPC call (i.e., remote Procedure Call remote procedure call, which requests a service from a remote computer program through a network without knowing the underlying network technology), but RPC call is generally used in an application program based on efficiency considerations.
The calling party of the RPC call in the prior art depends on the API JAR package defined by the interface, and the most common relying mode is to directly introduce an external API JAR package. The API, collectively referred to as Application Programming Interface, is a predefined function of the application programming interface to provide the application and developer with the ability to access a set of routines based on certain software or hardware without having to access source code or understand the details of the internal operating mechanism. JAR packages are archive files of the computer language Java that allow many files to be combined into one compressed file, and are used not only for compression and release, 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 present invention, the inventor finds that at least the following problems exist in the prior art: 1. in the RPC calling method in the prior art, if the interfaces are numerous, more external JAR packets are introduced, the size of an application program packet is increased, and code conflict is easily caused due to the introduction of external JAR containers; 2. if the interface definition of the external API JAR packet changes, the system needs to be re-introduced into the external JAR packet and be on line.
Disclosure of Invention
In view of this, the embodiments of the present invention provide a method and an apparatus for calling an interface, which can solve the problem that a system depends on an external API JAR packet, 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, there is provided a method of interface call.
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 the local interface call, and if not, initiating the remote interface call.
Optionally, before acquiring a request task of the 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; for each service method, determining a module for providing the service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method; a provider of a remote interface for dynamically publishing the service method according to the service implementation class; storing the corresponding relation between the unique identification of the module and the service realization class into the service registration module; and storing the unique identification of the module and the corresponding relation between the request behavior and the service method into the service registration module.
Optionally, obtaining a request task of the local system, and obtaining a unique identifier of a target service method corresponding to the request task in a service registration module, where the method includes: according to the request task, determining a unique identifier of a target module of the request task and a target request behavior, inquiring a 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, 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, 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 the 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 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, 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 the remote interface according to the unique identification of the target module of the request task, initiating remote interface call to the provider, and receiving a returned call result.
To achieve the above object, according to another aspect of an embodiment of the present invention, there is provided an apparatus for interface call.
An interface calling device of the embodiment of the invention comprises: the acquisition unit is used for acquiring a request task of the 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 the local interface call if yes, and initiating the remote interface call if no.
Optionally, the apparatus further comprises a storage unit for: acquiring a service method provided by an application program; for each service method, determining a module for providing the service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method; a provider of a remote interface for dynamically publishing the service method according to the service implementation class; storing the corresponding relation between the unique identification of the module and the service realization class into the service registration module; and storing the unique identification of the module and the corresponding relation between the request behavior and the service method into the service registration module.
Optionally, the acquiring unit is further configured to: according to the request task, determining a unique identifier of a target module of the request task and a target request behavior, inquiring a 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 judging 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, 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 calling 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 the 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 calling 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 the remote interface according to the unique identification of the target module of the request task, initiating remote interface call to the provider, and receiving a returned call result.
To achieve the above object, according to still another aspect of the embodiments of the present invention, there is provided an electronic device.
An electronic device of an embodiment of the present invention includes: one or more processors; and 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 interface calling method of the embodiment of the invention.
To achieve the above object, according to still another aspect of the embodiments of the present invention, there is provided a computer-readable medium.
A computer readable medium of an embodiment of the present invention has stored thereon a computer program which, when executed by a processor, implements a method of interface invocation of an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: the user-defined general API component realizes the interface call between different systems by means of the general API component, and the specific implementation method is as follows: the service registration module of the API general component is used for inquiring the unique identification of the requested target service method, then judging whether the local system provides the target service method or not according to the inquiring result, and the interface call of the specific service method is realized by means of the API general component, so that the problem that the system depends on an external API JAR package can be solved, the coupling between the local system and an external system API is reduced, and the influence of external system interface modification 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 general service registration module can be utilized to inquire the target method information of the request task and the service realization class; in 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 the local call or the remote call can be carried out according to the actual situation, and the efficiency of the interface call is improved; in the embodiment of the invention, when the method is called locally, the target service realization class is found, and then the purpose of calling different service methods according to parameters is achieved by using a reflection technology; in the embodiment of the invention, when the remote call is performed, the provider of the remote interface is queried according to the service implementation class, and the caller of the remote interface is dynamically generated according to the unique identification of the target module, so that the remote interface call can be realized.
Further effects of the above-described non-conventional alternatives are 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 invention;
FIG. 2 is a schematic diagram of the main flow of a method of interface invocation according to one referenceable embodiment of the invention;
FIG. 3 is a schematic diagram of the major modules of an interface-invoked device 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 applied;
fig. 5 is a schematic diagram of a computer system suitable for use in implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered 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 call in the prior art, a local system needs to introduce a plurality of API JAR packages of external systems, and the invention defines a general API component. The system of the same application program is provided with a universal API component, and the invention realizes the interface call between different systems by means of the universal API component instead of a method for directly calling the API of an external system, thereby achieving the aim of decoupling the systems. In addition, because the general API components in the invention are the same, the invention further embodies that the local system can communicate with any system containing the API general components without relying on the API JAR package provided by an external system to make interface calls. Meanwhile, since the method provided by the general API component is universal enough, the local system only needs to change parameters when in call even if the external system interface changes.
The universal API component of the present invention comprises: 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 invention. As a referenceable embodiment of the present invention, as shown in fig. 1, the main steps of the method for calling an interface of the embodiment of the present invention may include:
Step S101: and acquiring a request task of the local system, and acquiring a unique identifier of a target service method corresponding to the request task in a service registration module. The invention first obtains the requested task of the local system, say for a shopping application whose system requests to query the user's most recent browsing records. After the request task is acquired, the unique identification 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 parameter information of the request task is the parameter information of the interface, namely the custom API module SessionInfo object and RequestInfo object. The interface SessionInfo object represents session information, the object contains ID, pin, context, name attributes, the four attributes respectively represent a unique identifier of a session, a user account, a session Context (i.e., some attribute information contained in the session), a system name (name information for recording a caller), and furthermore, the Context attribute data type may be a JAVA (i.e., a computer programming language) native Map type (i.e., a data structure type). The RequestInfo object represents a request object, where the object includes IpAddr, action, mudule, params attributes, where the four attributes respectively represent an IP address, a request behavior, a unique identifier of a Module (in this invention, a Module name is used to indicate a name attribute of a Module annotation on a service implementation class), a request parameter (i.e. parameter information required by a service method corresponding to the request behavior), and in addition, a Params attribute data structure is a JAVA native Map type.
As a reference embodiment of the present invention, in step S101, the method for calling an interface may further include: acquiring a service method provided by an application program; for each service method, determining a module for providing the service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method; a provider of a remote interface for dynamically publishing a service method according to a service implementation class; storing the corresponding relation between the unique identification of the module and the service implementation class into a service registration module; and storing the unique identification 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 universal component. The service release module is used for releasing the service method which can be provided by the system, and the specific implementation process is as follows: the custom annotation @ Module class (Module class is a function block of the custom of the invention for providing some special services) searches the component marked with @ Module from the Spring component (the component refers to the system of the application program in the invention), and dynamically issues the service implementation class (i.e. the custom class capable of realizing the service method) in the API Module into the interface capable of being called remotely according to the name attribute of the Module annotation (i.e. the unique identification of the Module in the invention).
The service registration module is used for storing information of all available service methods of 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 saving the system information of the application program, recording the relation 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 a local virtual machine memory, and the memory data structure is a JAVA original Map structure, so that the information is convenient and quick to access, the memory can be directly read, and a network is not needed. In the relation 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 the relation data structure of the module and the service method, key is the unique identification of the module plus the request behavior, and Value is the method information corresponding to the request behavior.
As an embodiment of the present invention, 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 a unique identifier of a target module of the request task and a target request behavior, inquiring a unique identifier of the target module and a target service method corresponding to the target request behavior in a service registration module, and acquiring the unique identifier of the target service method. The unique identifier of the target module of the request task, namely the unique identifier of the functional module executing the request task, is included in the request task, and the target request behavior refers to specific request behavior. Meanwhile, in the service registration module, all relevant information which can provide a service method of the application program and is automatically recorded in the initialization process of the application program. Thus, the unique identification of the target service method of the requested 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 identification of the target service method.
In the present invention, a 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, 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 or not, if so, the target method can be directly called locally, so that the time for calling the interface can be reduced, and the efficiency of calling the interface is improved.
Step S103: if yes, executing the local interface call, and if not, initiating the remote interface call.
For still another embodiment of the present invention, the executing the local 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; according to the unique identification of the target service method, converting the parameter information of the request task into a parameter format of the target service method; based on the reflection technology, calling a target service method according to the parameter formats of the target service implementation class and the target service method, and receiving a returned calling result. The reflection technology in the invention can be a JAVA reflection mechanism, namely in the running state, for any one class, all the attributes and methods of the class can be known, and for any one object, any one method and attribute thereof can be called, and the functions of the dynamically acquired information and the method for dynamically calling the object are called as the JAVA reflection mechanism.
The service processing module in the invention is used for: when the request behavior of the local system is executed, inquiring whether the requested service method is provided locally or not from the service registration module according to the unique identification of the module and the unique identification of the method, if so, finding the corresponding service implementation class and the specific target method, converting the parameters into the parameter format of the target method, calling the target method according to the JAVA reflection technology, and receiving the returned calling result. If the service provider is not locally provided, the remote call module is relied on to initiate remote call and receive the returned call result.
In the 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 the target service method according to the target service implementation class; and dynamically generating a calling party of the remote interface according to the unique identification of the target module of the request task, initiating remote interface call to the provider, and receiving a returned call 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 dynamically issue the provider of the remote interface according to the target service implementation class.
Wherein, the returned result is RpcResult objects customized by the API module. The RpcResult object is used to represent the return value of the interface call, and contains code, desc, data, success attributes, where the four attributes represent the result code, the result description, the real data of the interface, and the execution state. The real data type of the interface is generic, success is JAVA basic data type and is used for indicating whether the interface call is successful, true is successful and false is failed.
FIG. 2 is a schematic diagram of the main flow of a method of interface invocation according to one referenceable embodiment of the invention. As shown in fig. 2, the main flow of the method for calling an interface 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, dynamically publishing a calling party of a remote interface of the service method by using a 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, wherein the specific implementation is as follows: (1) Acquiring a module for providing the service method and a service implementation class corresponding to the module, and storing the corresponding relation between the unique identification 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 of a target module of the request task and a target request behavior;
Step S205: in the service registration module, inquiring a 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 identification 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 request task;
Step S209: according to the unique identification of the target service method, converting the parameter information of the request task into a parameter format of the target service method;
step S210: based on JAVA reflection technology, calling a target service method according to the parameter formats of the target service implementation class and 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 request task, 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 request task, initiating remote interface call to the provider, and receiving a returned call result.
According to the technical scheme of the interface call, the embodiment of the invention can be seen to customize a general API component, and the interface call among different systems is realized by means of the general API component, and the specific realization method is as follows: the service registration module of the API general component is used for inquiring the unique identification of the requested target service method, then judging whether the local system provides the target service method or not according to the inquiring result, and the interface call of the specific service method is realized by means of the API general component, so that the problem that the system depends on an external API JAR package can be solved, the coupling between the local system and an external system API is reduced, and the influence of external system interface modification 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 general service registration module can be utilized to inquire the target method information of the request task and the service realization class; in 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 the local call or the remote call can be carried out according to the actual situation, and the efficiency of the interface call is improved; in the embodiment of the invention, when the method is called locally, the target service realization class is found, and then the purpose of calling different service methods according to parameters is achieved by using a reflection technology; in the embodiment of the invention, when the remote call is performed, the provider of the remote interface is queried according to the service implementation class, and the caller of the remote interface is dynamically generated according to the unique identification of the target module, so that the remote interface call can be realized.
Fig. 3 is a schematic diagram of the main modules of an interface-invoked device according to an embodiment of the present invention. As shown in fig. 3, the device 300 for calling an interface according to an 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 the local system, and obtain, in the service registration module, a unique identifier of a target service method corresponding to the request task. The judging unit 302 may be configured to judge whether the local system provides the target service method according to the unique identifier of the target service method. The calling unit 303 may be configured to execute the local interface call if yes, and initiate the remote interface call if no.
In the embodiment of the present invention, the device for calling an interface may further include a storage unit (not shown in the figure). The memory unit is operable to: acquiring a service method provided by an application program; for each service method, determining a module for providing the service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method; a provider of a remote interface for dynamically publishing a service method according to a service implementation class; storing the corresponding relation between the unique identification of the module and the service implementation class into a service registration module; and storing the unique identification of the module and the corresponding relation between the request behavior and the service method into a service registration module.
In the embodiment of the present invention, the obtaining unit 301 may further be configured to: according to the request task, determining a unique identifier of a target module of the request task and a target request behavior, inquiring a unique identifier of the target module and a target service method corresponding to the target request behavior in a service registration module, and acquiring the unique identifier of the target service method.
In the 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, 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 the embodiment of the present invention, the calling unit 303 may further be 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; according to the unique identification of the target service method, converting the parameter information of the request task into a parameter format of the target service method; based on the reflection technology, calling a target service method according to the parameter formats of the target service implementation class and the target service method, and receiving a returned calling result.
In the embodiment of the present invention, the calling unit 303 may further be 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 the remote interface according to the unique identification of the target module of the request task, initiating remote interface call to the provider, and receiving a returned call result.
From the above description, it can be seen that the general API component is customized, and the interface call between different systems is realized by means of the general API component, and the specific implementation method is as follows: the service registration module of the API general component is used for inquiring the unique identification of the requested target service method, then judging whether the local system provides the target service method or not according to the inquiring result, and the interface call of the specific service method is realized by means of the API general component, so that the problem that the system depends on an external API JAR package can be solved, the coupling between the local system and an external system API is reduced, and the influence of external system interface modification 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 general service registration module can be utilized to inquire the target method information of the request task and the service realization class; in 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 the local call or the remote call can be carried out according to the actual situation, and the efficiency of the interface call is improved; in the embodiment of the invention, when the method is called locally, the target service realization class is found, and then the purpose of calling different service methods according to parameters is achieved by using a reflection technology; in the embodiment of the invention, when the remote call is performed, the provider of the remote interface is queried according to the service implementation class, and the caller of the remote interface is dynamically generated according to the unique identification of the target module, so that the remote interface call can be realized.
Fig. 4 illustrates an exemplary system architecture 400 of a method of interface invocation or an apparatus of interface invocation to which 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 is used as a medium to provide communication links between the terminal devices 401, 402, 403 and the server 405. The network 404 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may interact with the server 405 via the network 404 using the terminal devices 401, 402, 403 to receive or send messages or the like. Various communication client applications, such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the terminal devices 401, 402, 403.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (by way of example only) providing support for shopping-type websites browsed by users using the terminal devices 401, 402, 403. The background management server may analyze and process the received data such as the product information query request, and feedback the processing result (e.g., the target push information, the product information—only an example) to the terminal device.
It should be noted that, the method for calling the interface provided in the embodiment of the present invention is generally executed by the server 405, and accordingly, the device for calling the interface 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, there is illustrated a schematic diagram of a computer system 500 suitable for use in implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not impose any limitation on the functions and the scope of use of the embodiment of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU) 501, which 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 required for the operation of the system 500 are also stored. The CPU501, ROM 502, and RAM 503 are connected to each other through 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 section 506 including a keyboard, a mouse, and the like; an output portion 507 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker, and the like; 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 drive 510 is also connected to the I/O interface 505 as needed. 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 needed so that a computer program read therefrom is mounted into the storage section 508 as needed.
In particular, according to embodiments of the present disclosure, the processes described above with reference to 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 shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 509, and/or installed from the removable media 511. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 501.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any 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 context of this document, 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, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. 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 flowcharts 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 involved in the embodiments of the present invention may be implemented in software or in hardware. The described units may also be provided in a processor, for example, described as: a processor includes an acquisition unit, a determination unit, and a call unit. The names of these units do not limit the unit itself in some cases, for example, the acquisition unit may also be described as "a unit that acquires a request task of the local system and acquires, in the service registration module, a unique identifier of a target service method corresponding to the request task".
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 present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include: 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 the local interface call, and if not, initiating the remote interface call.
According to the technical scheme of the embodiment of the invention, the universal API component is customized, and the interface call among different systems is realized by means of the universal API component, and the specific realization method is as follows: the service registration module of the API general component is used for inquiring the unique identification of the requested target service method, then judging whether the local system provides the target service method or not according to the inquiring result, and the interface call of the specific service method is realized by means of the API general component, so that the problem that the system depends on an external API JAR package can be solved, the coupling between the local system and an external system API is reduced, and the influence of external system interface modification 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 general service registration module can be utilized to inquire the target method information of the request task and the service realization class; in 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 the local call or the remote call can be carried out according to the actual situation, and the efficiency of the interface call is improved; in the embodiment of the invention, when the method is called locally, the target service realization class is found, and then the purpose of calling different service methods according to parameters is achieved by using a reflection technology; in the embodiment of the invention, when the remote call is performed, the provider of the remote interface is queried according to the service implementation class, and the caller of the remote interface is dynamically generated according to the unique identification of the target module, so that the remote interface call can be realized.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.

Claims (12)

1. A method of interface invocation, comprising:
acquiring a service method provided by an application program;
For each service method, determining a module for providing the service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method;
a provider of a remote interface for dynamically publishing the service method according to the service implementation class;
storing the corresponding relation between the unique identification of the module and the service implementation class into a service registration module;
Storing the unique identification of the module and the corresponding relation between the request behavior and the service method into the service registration module;
acquiring a request task of a local system, and acquiring a unique identifier of a target service method corresponding to the request task from a service registration module of an API universal component; wherein, the system for the same application program has a general API component; each system corresponding to the application program comprises a same service registration module, or the whole application program comprises a service registration module; the service registration module records all information of the application program which can provide a service method, and stores the corresponding relation between the unique identification of the module providing the service method and the service implementation class and the corresponding relation between the unique identification and the request behavior and the service method;
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 the local interface call, and if not, initiating the remote interface call.
2. The method of claim 1, wherein obtaining a requested task of a local system and obtaining, in a service registration module, a unique identifier of a target service method corresponding to the requested task, comprises:
According to the request task, determining a unique identifier of a target module of the request task and a target request behavior, inquiring a 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.
3. The method of claim 1, wherein determining whether the local system provides the target service method based on the unique identification 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, 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.
4. The method of claim 1, 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 the 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.
5. The method of claim 1, 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 the remote interface according to the unique identification of the target module of the request task, initiating remote interface call to the provider, and receiving a returned call result.
6. An apparatus for interface invocation, comprising:
a storage unit configured to: acquiring a service method provided by an application program; for each service method, determining a module for providing the service method, a service implementation class corresponding to the module and a request behavior corresponding to the service method;
A provider of a remote interface for dynamically publishing the service method according to the service implementation class; storing the corresponding relation between the unique identification of the module and the service implementation class into a service registration module; storing the unique identification of the module and the corresponding relation between the request behavior and the service method into the service registration module;
The acquisition unit is used for acquiring a request task of the local system and acquiring a unique identifier of a target service method corresponding to the request task from a service registration module of the API universal component; wherein, the system for the same application program has a general API component; each system corresponding to the application program comprises a same service registration module, or the whole application program comprises a service registration module; the service registration module is used for storing the corresponding relation between the unique identifier and the service implementation class and the corresponding relation between the unique identifier and the request behavior and the service method, and storing the corresponding relation between the unique identifier of the module providing the service method and the service implementation class and the corresponding relation between the unique identifier and the request behavior and the service method;
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 the local interface call if yes, and initiating the remote interface call if no.
7. The apparatus of claim 6, wherein the acquisition unit is further configured to:
According to the request task, determining a unique identifier of a target module of the request task and a target request behavior, inquiring a 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.
8. The apparatus of claim 6, wherein the determination 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, 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.
9. The apparatus of claim 6, wherein the calling 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 the 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.
10. The apparatus of claim 6, wherein the calling 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 the remote interface according to the unique identification of the target module of the request task, initiating remote interface call to the provider, and receiving a returned call result.
11. An electronic device, comprising:
One or more processors;
Storage means for storing one or more programs,
When executed by the one or more processors, causes the one or more processors to implement the method of any of claims 1-5.
12. A computer readable medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-5.
CN201811195680.1A 2018-10-15 2018-10-15 Interface calling method and device Active CN111045833B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811195680.1A CN111045833B (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 CN111045833B (en) 2018-10-15 2018-10-15 Interface calling method and device

Publications (2)

Publication Number Publication Date
CN111045833A CN111045833A (en) 2020-04-21
CN111045833B true CN111045833B (en) 2024-06-18

Family

ID=70230239

Family Applications (1)

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

Country Status (1)

Country Link
CN (1) CN111045833B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111538492B (en) * 2020-04-24 2023-12-19 浙江大搜车软件技术有限公司 Method and device for calling policy implementation, electronic equipment and storage medium
CN111970349B (en) * 2020-08-07 2022-06-24 中国建设银行股份有限公司 Communication system, method, device, equipment and medium based on remote procedure call
CN112416612B (en) * 2020-08-13 2023-03-28 上海哔哩哔哩科技有限公司 Service calling method and device, computer equipment and readable storage medium
CN112084046B (en) * 2020-09-12 2021-12-21 深圳市艾可思信息技术有限公司 Method and device for calling generalization interface in distributed computing
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

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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
CN108134766A (en) * 2016-12-01 2018-06-08 阿里巴巴集团控股有限公司 A kind of method, apparatus, system, server and client for servicing publication

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7716357B2 (en) * 2003-10-24 2010-05-11 Microsoft Corporation Service discovery and publication
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
CN107360261B (en) * 2017-09-07 2020-07-10 北京奇艺世纪科技有限公司 HTTP request processing method and device and electronic equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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
CN102810069A (en) * 2012-07-16 2012-12-05 深圳市融创天下科技股份有限公司 JAVA object requesting and responding methods, devices and systems and terminal
CN108134766A (en) * 2016-12-01 2018-06-08 阿里巴巴集团控股有限公司 A kind of method, apparatus, system, server and client for servicing publication

Also Published As

Publication number Publication date
CN111045833A (en) 2020-04-21

Similar Documents

Publication Publication Date Title
CN111045833B (en) Interface calling method and device
US10623476B2 (en) Endpoint management system providing an application programming interface proxy service
CN112114979B (en) Remote procedure call method and device
CN112507005B (en) Method and device for processing message
CN111427701A (en) Workflow engine system and business processing method
CN113076153B (en) Interface calling method and device
CN114979295B (en) Gateway management method and device
CN109981546B (en) Method and device for acquiring remote call relation between application modules
CN109471713B (en) Method and device for inquiring information
CN113778499B (en) Method, apparatus, device and computer readable medium for publishing services
CN112948138A (en) Method and device for processing message
CN110764769A (en) Method and device for processing user request
CN113779122B (en) Method and device for exporting data
CN113760487B (en) Service processing method and device
CN112860447B (en) Interaction method and system between different applications
CN115080274A (en) Service processing method, device and system and interface mapping system
CN112905273A (en) Service calling method and device
CN113765983A (en) Site service deployment method and device
CN109120692B (en) Method and apparatus for processing requests
CN113779018A (en) Data processing method and device
CN113742617A (en) Cache updating method and device
CN113556370A (en) Service calling method and device
CN113760693A (en) Method and apparatus for local debugging of microservice systems
CN113326060A (en) Service request processing method, device and system and service configuration method and device
CN113495747B (en) Gray scale release method and device

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
GR01 Patent grant