CN113806104A - Interface access request processing method, API gateway, server and system - Google Patents

Interface access request processing method, API gateway, server and system Download PDF

Info

Publication number
CN113806104A
CN113806104A CN202110882756.3A CN202110882756A CN113806104A CN 113806104 A CN113806104 A CN 113806104A CN 202110882756 A CN202110882756 A CN 202110882756A CN 113806104 A CN113806104 A CN 113806104A
Authority
CN
China
Prior art keywords
access request
interface access
identifier
parameter
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
CN202110882756.3A
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 Fangjianghu Technology Co Ltd
Original Assignee
Beijing Fangjianghu 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 Fangjianghu Technology Co Ltd filed Critical Beijing Fangjianghu Technology Co Ltd
Priority to CN202110882756.3A priority Critical patent/CN113806104A/en
Publication of CN113806104A publication Critical patent/CN113806104A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention provides an interface access request processing method, an API gateway, a server and a system, wherein the method comprises the following steps: receiving an interface access request which is initiated by a front end and comprises a module identifier, a service identifier, a method identifier and a request parameter of a micro service; the interface access request is routed to the micro-service module corresponding to the server and the module identifier, so that the server searches a corresponding service instance in the micro-service module according to the service identifier, acquires a corresponding method and a parameter definition list in the service instance according to the method identifier, calls the method based on the request parameter and the parameter definition list, and acquires an interface access request processing result; and receiving an interface access request processing result returned by the server and sending the interface access request processing result to the front end. The interface access request processing method, the API gateway, the server and the system provided by the invention realize method calling based on hierarchical refinement of the interface access request and step-by-step processing according to hierarchical information, thereby improving the processing efficiency and accuracy of the interface access request.

Description

Interface access request processing method, API gateway, server and system
Technical Field
The embodiment of the invention relates to an interface access request processing method, an API gateway, a server and a system.
Background
In the Dubbo micro-Service interface-oriented programming mode, a Service in a micro-Service module is represented by a Service interface class (e.g., user Service UserService), and a Service interface is represented by a method in this interface class (e.g., userInfo method represents details of the querying user).
With continuous expansion of services, the existing Dubbo micro-service scale is getting larger and larger, and in the conventional method, a gateway project is specially developed and maintained by people, interfaces of different micro-services are introduced into the project to provide HTTP service externally, request JSON data is deserialized and converted into a required data type, then a rear-end micro-service interface is called, and a method return result is deserialized into JSON and returned to a requester; however, when an interface of a certain micro-service at the back end is newly added or changed, the project needs to be frequently modified, constructed and deployed, all operations need to be artificially coded, and the maintenance is more difficult as the scale increases.
Disclosure of Invention
In order to solve the problems in the prior art, the invention provides an interface access request processing method, an API gateway, a server and a system.
The invention provides an interface access request processing method, which comprises the following steps: receiving an interface access request initiated by a front end; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service; the interface access request is routed to a server and a micro-service module corresponding to the module identifier according to the module identifier, so that the server further searches a corresponding service instance in the micro-service module according to the service identifier, acquires a corresponding method and a parameter definition list in the service instance according to the method identifier, and calls the method based on the request parameter and the parameter definition list, thereby acquiring an interface access request processing result; and receiving the interface access request processing result returned by the server, and sending the interface access request processing result to the front end.
According to the interface access request processing method provided by the invention, the receiving of the interface access request initiated by the front end comprises the following steps: receiving an interface access request initiated by a front end based on an HTTP interface protocol; the protocol format of the HTTP interface protocol includes the module identifier, the service identifier, and the method identifier, and the request parameter exists in a request body corresponding to the protocol format of the HTTP interface protocol or the interface access request.
According to the interface access request processing method provided by the invention, the name of the request parameter is consistent with the parameter name of the method in the service instance corresponding to the interface access request.
The invention also provides an interface access request processing method, which comprises the following steps: acquiring an interface access request from a front end, which is sent by an API gateway; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service; searching a corresponding service instance in a micro service module corresponding to the module identifier according to the service identifier, acquiring a corresponding method and a parameter definition list in the service instance according to the method identifier, and calling the method based on the request parameter and the parameter definition list so as to acquire an interface access request processing result; and sending the interface access request processing result to the front end through an API gateway.
According to the interface access request processing method provided by the invention, the method calling based on the request parameter and the parameter definition list specifically comprises the following steps: acquiring a parameter name and a parameter type of the method according to the parameter definition list; converting the parameter value in the request parameter into a value object corresponding to the parameter type in the parameter definition list; instantiating a corresponding parameter object according to the parameter name, the parameter type and the value object; and executing a method call on the method through a java reflection mechanism based on the parameter object.
The present invention also provides an API gateway, comprising: a request receiving unit configured to: receiving an interface access request initiated by a front end; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service; a routing unit to: the interface access request is routed to a server and a micro-service module corresponding to the module identifier according to the module identifier, so that the server further searches a corresponding service instance in the micro-service module according to the service identifier, acquires a corresponding method and a parameter definition list in the service instance according to the method identifier, and calls the method based on the request parameter and the parameter definition list, thereby acquiring an interface access request processing result; a feedback unit to: and receiving the interface access request processing result returned by the server, and feeding back the interface access request processing result to the front end.
The present invention also provides a server comprising: a request acquisition unit configured to: acquiring an interface access request from a front end, which is sent by an API gateway; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service; a distribution processing unit configured to: searching a corresponding service instance in a micro service module corresponding to the module identifier according to the service identifier, acquiring a corresponding method and a parameter definition list in the service instance according to the method identifier, and calling the method based on the request parameter and the parameter definition list so as to acquire an interface access request processing result; a transmitting unit configured to: and sending the interface access request processing result to the front end through an API gateway.
The invention also provides an interface access request processing system, which comprises a front end, an API gateway and a server; wherein: the front end is used for sending an interface access request to the API gateway; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service; the API gateway is used for receiving the interface access request and routing the interface access request to the server and the micro-service module corresponding to the module identifier according to the module identifier; the server is used for receiving the interface access request, searching a corresponding service instance in a micro-service module corresponding to the module identifier according to the service identifier, acquiring a corresponding method and a parameter definition list in the service instance according to the method identifier, calling the method based on the request parameter and the parameter definition list so as to acquire an interface access request processing result, and sending the interface access request processing result to the API gateway; the API gateway is also used for receiving the interface access request processing result and feeding back the interface access request processing result to the front end; the front end is also used for receiving the interface access request processing result fed back by the API gateway.
The present invention also provides an electronic device, including a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the interface access request processing method according to any one of the above methods when executing the program.
The present invention also provides a non-transitory computer-readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the interface access request processing method according to any one of the above.
The present invention also provides a computer program product comprising computer program/instructions which, when executed by a processor, implement the steps of the interface access request processing method according to any of the above.
According to the interface access request processing method, the API gateway, the server and the system, the interface access request is subjected to layered processing comprising the module identifier, the service identifier and the method identifier, when the interface access request is initiated at the front end, the interface access request is routed to the corresponding micro-service module according to the module identifier, then the corresponding service instance is obtained according to the service identifier, the corresponding method is called according to the method identifier, the target method is called quickly, the processing efficiency and the processing accuracy of the interface access request are improved, the problem that codes in the API gateway are changed frequently due to updating of the method is avoided, the overall maintainability is improved, and the front end friendliness is achieved.
Drawings
In order to more clearly illustrate the technical solutions of the present invention or the prior art, the drawings needed for the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
FIG. 1 is a flow chart of an interface access request processing method provided by the present invention;
FIG. 2 is a second flowchart of the interface access request processing method provided by the present invention;
FIG. 3 is a third schematic flowchart of a method for processing an interface access request according to the present invention;
FIG. 4 is a schematic structural diagram of an API gateway provided by the present invention;
FIG. 5 is a schematic diagram of a server provided by the present invention;
FIG. 6 is a schematic structural diagram of an interface access request processing system provided by the present invention;
fig. 7 is a schematic structural diagram of an electronic device provided by the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is obvious that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a schematic flowchart of an interface access request processing method provided by the present invention, and fig. 3 is a third schematic flowchart of an interface access request processing method provided by the present invention, as shown in fig. 1, the method includes:
step S110, receiving an interface access request initiated by a front end; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service;
step S120, the interface access request is routed to a server and a micro service module corresponding to the module identifier according to the module identifier, so that the server further searches a corresponding service instance in the micro service module according to the service identifier, acquires a corresponding method and a parameter definition list in the service instance according to the method identifier, and calls the method based on the request parameter and the parameter definition list, thereby acquiring an interface access request processing result;
step S130, receiving the interface access request processing result returned by the server, and sending the interface access request processing result to the front end.
The interface access request processing method provided by the invention can be applied to an API (application program interface) gateway. The API gateway receives an interface access request initiated by a front end; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service. And after receiving the interface access request, the API gateway routes the interface access request to the micro-service module corresponding to the server according to the module identifier.
As shown in fig. 3, there is a Dispatch (a function module) in each micro-service module of the server, which may have the following functions: firstly, a method calling process is carried out in the micro service module according to the service identifier, the method identifier and the request parameter in the interface access request; uniformly processing the method calling result and returning the method calling result to the front end; and thirdly, intercepting the exception generated in the calling process of the method and returning friendly prompt information to the front end. For example, when an exception occurs in the method calling process, the prompt message of 'method calling failure' is returned to the front end; the process fully considers the possible situations in the method calling process, gives feedback to the situation of method calling failure in time, and optimizes the human-computer interaction experience; fourthly, the parameters in the request protocol are organized and converted into the format required by the target method, and the method is called.
It should be noted that, in step S120, after the interface access request is routed to the micro service module corresponding to the module identifier, the module finds a corresponding service instance from the bean managed by spring through the servicebeans name (service identifier), and can obtain a method and a parameter definition list corresponding to the methodName (method identifier) through the java reflection mechanism. The Spring is a layered JavaSE/EE full-stack (one-stop) lightweight open-source framework, which is convenient for integrating various excellent frameworks and testing programs; a bean is equivalent to defining a component that is used to implement a certain function. In the process, only specific parameter objects need to be instantiated according to parameter names, parameter types and parameter values transmitted from the front end, and the method call can be executed through a java reflection mechanism. The parameter name and the parameter type can be directly obtained in the parameter definition, then a character string is obtained from the Map through the parameter name, and finally the character string is converted into a value object corresponding to the parameter type, so that the required parameter value transmitted by the front end is obtained. The conversion needs to judge the parameter type, if the type is simple, the conversion can be directly carried out, and if the type is a composite object type, the conversion can be carried out by transmitting the JSON field to a javaBean object. A Map is a data storage structure that can be viewed as a container that stores elements according to keys (keys) that are similar to subscripts, where keys (keys) can be any type of object, where there cannot be duplicate keys (keys) in the Map, and each Key (Key) has a corresponding value (value).
And after obtaining the interface access request processing result, the server sends the interface access request processing result to the API gateway. The API gateway receives an interface access request processing result returned by the server and feeds the interface access request processing result back to the front end, so that the processing of the corresponding interface access request is realized.
According to the interface access request processing method provided by the invention, the interface access request is subjected to layered processing comprising the module identifier, the service identifier and the method identifier, when the interface access request is initiated at the front end, the interface access request is routed to the corresponding micro-service module according to the module identifier, then the corresponding service instance is obtained according to the service identifier, and the corresponding method is called according to the method identifier, so that the target method is quickly called, the processing efficiency and the processing accuracy of the interface access request are improved, the problem of frequent change of internal codes of an API gateway caused by method updating is avoided, the integral maintainability is improved, and the front end friendliness is realized.
According to the interface access request processing method provided by the present invention, in the present invention, the receiving of the interface access request initiated by the front end includes: receiving an interface access request initiated by a front end based on an HTTP interface protocol; the protocol format of the HTTP interface protocol includes the module identifier, the service identifier, and the method identifier, and the request parameter exists in a request body corresponding to the protocol format of the HTTP interface protocol or the interface access request.
For example, the protocol format of the HTTP interface agreed between the front end and the server may be:http://${domain}/ ${module}/${servcieBeanName}/${custom}/${method name }, in the above interface protocol, { domain } is the domain name, { module } is the module ID, { servcieeBeanName } is the service ID, and { custom } is the special ID Requirement parameter, { MethodName } is the method identification.Request parameters may also be set in the protocol format of the HTTP interface.
The HTTP request message consists of three parts, respectively: the system comprises a request line, a request header and a request body, wherein the request line consists of a method, a URL and an HTTP version, the method refers to what operation is specifically executed by a command browser, the URL represents an address of a server, and the HTTP version represents a protocol which is specifically a few versions; the request header is composed of a limited field name and a limited field value, and the field name and the field value are additional information of the request message, such as 7/9/2021, date, data type, language or compression format, and the like; the specific components of the request body depend on specific request content, that is, the request body is used for carrying HTTP request data, is used for carrying information of specific request parameters, and is the core for embodying the specific HTTP request content. The request parameters may also be present in the request body to which the interface access request corresponds.
According to the interface access request processing method provided by the invention, the interface access request is designed into a standard request format based on an HTTP (hyper text transport protocol) interface protocol, the HTTP interface protocol comprises a module identifier, a service identifier and a method identifier, the readability of the interface access request at the front end is improved, the interface access request can be quickly processed on a back-end server based on the interface protocol, meanwhile, request parameters exist in the protocol format of the HTTP interface protocol or a request body corresponding to the interface access request, and the flexibility is improved.
According to the interface access request processing method provided by the invention, the name of the request parameter is consistent with the parameter name of the method in the service instance corresponding to the interface access request.
For example, an interface access request is initiated at the front end:http://${domain}/ com.ke.sinan.UserService/userInfoparam=username. Ke. The name of the request parameter is set to be the username, so that the request parameter is consistent with the parameter name of the method in the service instance corresponding to the interface access request, the method can be quickly called, and the method is more friendly to the front end.
The interface access request processing method provided by the invention is beneficial to ensuring the one-to-one correspondence between the interface access request and the method calling process in the micro service module by keeping the name of the request parameter in the interface access request consistent with the name of the parameter in the calling method in the micro service module, thereby improving the processing efficiency and the processing accuracy of the interface access request and being more friendly to the front end.
Fig. 2 is a second schematic flowchart of the interface access request processing method provided by the present invention, as shown in fig. 2, the method includes:
step S210, obtaining an interface access request from a front end sent by an API gateway; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service;
step S220, searching a corresponding service instance in a micro-service module corresponding to the module identifier according to the service identifier, acquiring a corresponding method and a parameter definition list in the service instance according to the method identifier, and calling the method based on the request parameter and the parameter definition list so as to acquire an interface access request processing result;
step S230, sending the interface access request processing result to the front end via the API gateway.
According to the interface access request processing method provided by the invention, after an interface access request sent by an API gateway is received, a corresponding service instance is searched in a micro-service module according to a service identifier in the interface access request, a corresponding method and parameter definition list are obtained in the service instance according to the method identifier, the method is called based on the request parameter and parameter definition list, a processing result of the interface access request is finally obtained, and meanwhile, the processing result of the interface access request is sent to a front end through the API gateway.
According to the interface access request processing method provided by the present invention, in the present invention, the method calling based on the request parameter and the parameter definition list specifically includes: acquiring a parameter name and a parameter type of the method according to the parameter definition list; converting the parameter value in the request parameter into a value object corresponding to the parameter type in the parameter definition list; instantiating a corresponding parameter object according to the parameter name, the parameter type and the value object; and executing a method call on the method through a java reflection mechanism based on the parameter object.
It should be noted that, in the running state, the java reflection mechanism can know all the attributes and methods of any entity class; for any object, any method and attribute of the object can be called; this function of dynamically acquiring information and dynamically invoking object methods is referred to as the reflection mechanism of the java language. The java reflection mechanism mainly provides the following functions of judging the class to which any object belongs during running; constructing an object of any one class at runtime; judging member variables and methods of any one class during running; calling a method of any one object at runtime; a dynamic proxy is generated.
The interface access request processing method provided by the invention converts the parameter values in the request parameters in the interface access request into the value objects corresponding to the parameter types in the parameter definition list, instantiates the corresponding parameter objects based on the parameter names and the parameter types acquired from the parameter definition list and the value objects, and finally realizes the method call aiming at the parameter objects by using the java reflection mechanism. The process realizes the method calling process based on the request parameters by reasonably utilizing the parameter definition list, and ensures the accuracy of the method calling process.
Fig. 4 is a schematic structural diagram of the API gateway provided in the present invention, and as shown in fig. 4, the API gateway 400 includes: a request receiving unit 410, a routing unit 420 and a feedback unit 430, wherein:
a request receiving unit 410, configured to: receiving an interface access request initiated by a front end; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service;
a routing unit 420, configured to: the interface access request is routed to a server and a micro-service module corresponding to the module identifier according to the module identifier, so that the server further searches a corresponding service instance in the micro-service module according to the service identifier, acquires a corresponding method and a parameter definition list in the service instance according to the method identifier, and calls the method based on the request parameter and the parameter definition list, thereby acquiring an interface access request processing result;
a feedback unit 430 configured to: and receiving the interface access request processing result returned by the server, and feeding back the interface access request processing result to the front end.
According to the API gateway provided by the invention, the module identification in the interface access request is identified, and then the interface access request is routed to the corresponding micro-service module on the server based on the module identification to process the interface access request, so that the process of correspondingly matching the interface access request with the micro-service module for processing the interface access request is realized, and the processing efficiency and the processing accuracy of the interface access request are improved.
According to an API gateway provided by the present invention, when the request receiving unit 410 is configured to receive an interface access request initiated by a front end, specifically: receiving an interface access request initiated by a front end based on an HTTP interface protocol; the protocol format of the HTTP interface protocol includes the module identifier, the service identifier, and the method identifier, and the request parameter exists in a request body corresponding to the protocol format of the HTTP interface protocol or the interface access request.
According to the API gateway provided by the invention, the interface access request is designed into a standard request format based on an HTTP interface protocol, the HTTP interface protocol comprises a module identifier, a service identifier and a method identifier, the readability of the interface access request at the front end is improved, the interface access request can be quickly processed on a back-end server based on the interface protocol, meanwhile, request parameters exist in the protocol format of the HTTP interface protocol or a request body corresponding to the interface access request, and the flexibility is improved.
According to the API gateway provided by the invention, the name of the request parameter is consistent with the parameter name of the method in the service instance corresponding to the interface access request.
The API gateway provided by the invention is beneficial to ensuring the one-to-one correspondence between the interface access request and the method calling process in the micro service module by keeping the name of the request parameter in the interface access request consistent with the name of the parameter in the calling method in the micro service module, thereby improving the processing efficiency and the processing accuracy of the interface access request and being more friendly to the front end.
Fig. 5 is a schematic structural diagram of a server provided in the present invention, and as shown in fig. 5, the server 500 includes: a request acquisition unit 510, a distribution processing unit 520, and a transmission unit 530, wherein:
a request obtaining unit 510, configured to: acquiring an interface access request from a front end, which is sent by an API gateway; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service;
a distribution processing unit 520 configured to: searching a corresponding service instance in a micro service module corresponding to the module identifier according to the service identifier, acquiring a corresponding method and a parameter definition list in the service instance according to the method identifier, and calling the method based on the request parameter and the parameter definition list so as to acquire an interface access request processing result;
a sending unit 530, configured to: and sending the interface access request processing result to the front end through an API gateway.
According to the server provided by the invention, after the interface access request sent by the API gateway is received, the corresponding service instance is searched in the micro-service module according to the service identifier in the interface access request, the corresponding method and the parameter definition list are obtained in the service instance according to the method identifier, the method is called based on the request parameter and the parameter definition list, the processing result of the interface access request is finally obtained, and meanwhile, the processing result of the interface access request is sent to the front end through the API gateway.
According to a server provided by the present invention, the distribution processing unit 520 is configured to perform a method call to the method based on the request parameter and the parameter definition list, and specifically configured to: acquiring a parameter name and a parameter type of the method according to the parameter definition list; converting the parameter value in the request parameter into a value object corresponding to the parameter type in the parameter definition list; instantiating a corresponding parameter object according to the parameter name, the parameter type and the value object; and executing a method call on the method through a java reflection mechanism based on the parameter object.
The server provided by the invention converts the parameter value in the request parameter in the interface access request into the value object corresponding to the parameter type in the parameter definition list, instantiates the corresponding parameter object based on the parameter name and the parameter type acquired from the parameter definition list and the value object, and finally realizes the method call aiming at the parameter object by using the java reflection mechanism. The process realizes the method calling process based on the request parameters by reasonably utilizing the parameter definition list, and ensures the accuracy of the method calling process.
Fig. 6 is a schematic structural diagram of an interface access request processing system provided by the present invention, and as shown in fig. 6, the interface access request processing system 10 specifically includes: front end 300, API gateway 400, and server 500, wherein:
the front end 300 is configured to send an interface access request to the API gateway 400; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service;
the API gateway 400 is configured to receive the interface access request, and route the interface access request to the micro service module corresponding to the module identifier in the server 500 according to the module identifier;
the server 500 is configured to receive the interface access request, search a corresponding service instance in a micro service module corresponding to the module identifier according to the service identifier, obtain a corresponding method and parameter definition list in the service instance according to the method identifier, perform method call on the method based on the request parameter and the parameter definition list, thereby obtaining an interface access request processing result, and send the interface access request processing result to the API gateway 400;
the API gateway 400 is further configured to receive the processing result of the interface access request, and feed back the processing result of the interface access request to the front end 300;
the front end 300 is further configured to receive the interface access request processing result fed back by the API gateway 400.
It should be noted that the API gateway 400 is configured to receive the interface access request, specifically: receiving an interface access request initiated by a front end based on an HTTP interface protocol; the protocol format of the HTTP interface agreed between the front end and the server may be: http:// $ { domain }/$ { module }/$ { servciebenname }/$ { custom }/$ { method Name }, in the above interface protocol, { module } is module identification, { servciebenname } is service identification, and { methodName } is method identification.
After receiving the interface access request, the API gateway routes the specific interface access request to a corresponding micro-service module on the server according to the module identifier in the interface access request; issuing a Dubbo service of a DispatchService in each micro service module, wherein the DispatchService represents a functional module in the micro service module for processing an interface access request, the DispatchServices of different micro services are distinguished by group attributes of Dubbo, the group value of a specific micro service corresponds to $ { module } of the protocol, the API gateway provides a method for uniformly processing a Controller by a request, the request is processed by @ RequestMapping (value: "/{ module }/{ serviceBeanName }/{ custom }"), all request parameters are received by Map, the core logic of the processing is to call the DispatchServiceService of the specified module by Dubbo, route the request to the specified micro service module, and transmit { serviceName }, { custom }, { other previous }, and other { quantity } past parameters.
Specifically, after the interface access request is routed to the micro-service module corresponding to the module identifier, the module finds a corresponding service instance from a bean managed by spring through the servicebean name, and can obtain a method and a parameter definition list corresponding to the methodName through a java reflection mechanism. In the process, only specific parameter objects need to be instantiated according to parameter names, parameter types and parameter values transmitted from the front end, and the method call can be executed through a java reflection mechanism. The parameter name and the parameter type can be directly obtained in the parameter definition, then a character string is obtained from the Map through the parameter name, and finally the character string is converted into a value object corresponding to the parameter type, so that the required parameter value transmitted by the front end is obtained. The conversion needs to judge the parameter type, if the type is simple, the conversion can be directly carried out, and if the type is a composite object type, the conversion can be carried out by transmitting the JSON field to a javaBean object.
According to the interface access request processing system provided by the invention, the interface access request is subjected to layered processing comprising the module identifier, the service identifier and the method identifier, when the interface access request is initiated at the front end, the interface access request is routed to the corresponding micro-service module according to the module identifier, then the corresponding service instance is obtained according to the service identifier, and the corresponding method is called according to the method identifier, so that the target method is quickly called, the processing efficiency and the processing accuracy of the interface access request are improved, the problem of frequent change of internal codes of an API gateway caused by method updating is avoided, the integral maintainability is improved, and the front end friendliness is realized.
Fig. 7 illustrates a physical structure diagram of an electronic device, and as shown in fig. 7, the electronic device may include: a processor (processor)710, a communication Interface (Communications Interface)720, a memory (memory)730, and a communication bus 740, wherein the processor 710, the communication Interface 720, and the memory 730 communicate with each other via the communication bus 740. Processor 710 may call logic instructions in memory 730 to perform an interface access request processing method comprising: receiving an interface access request initiated by a front end; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service; the interface access request is routed to a server and a micro-service module corresponding to the module identifier according to the module identifier, so that the server further searches a corresponding service instance in the micro-service module according to the service identifier, acquires a corresponding method and a parameter definition list in the service instance according to the method identifier, and calls the method based on the request parameter and the parameter definition list, thereby acquiring an interface access request processing result; and receiving the interface access request processing result returned by the server, and sending the interface access request processing result to the front end.
In addition, the logic instructions in the memory 730 can be implemented in the form of software functional units and stored in a computer readable storage medium when the software functional units are sold or used as independent products. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In another aspect, the present invention also provides a computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions which, when executed by a computer, enable the computer to perform the interface access request processing method provided by the above methods, the method comprising: receiving an interface access request initiated by a front end; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service; the interface access request is routed to a server and a micro-service module corresponding to the module identifier according to the module identifier, so that the server further searches a corresponding service instance in the micro-service module according to the service identifier, acquires a corresponding method and a parameter definition list in the service instance according to the method identifier, and calls the method based on the request parameter and the parameter definition list, thereby acquiring an interface access request processing result; and receiving the interface access request processing result returned by the server, and sending the interface access request processing result to the front end.
In yet another aspect, the present invention also provides a non-transitory computer-readable storage medium having stored thereon a computer program which, when executed by a processor, is implemented to perform the interface access request processing method provided above, the method including: receiving an interface access request initiated by a front end; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service; the interface access request is routed to a server and a micro-service module corresponding to the module identifier according to the module identifier, so that the server further searches a corresponding service instance in the micro-service module according to the service identifier, acquires a corresponding method and a parameter definition list in the service instance according to the method identifier, and calls the method based on the request parameter and the parameter definition list, thereby acquiring an interface access request processing result; and receiving the interface access request processing result returned by the server, and sending the interface access request processing result to the front end.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. An interface access request processing method, comprising:
receiving an interface access request initiated by a front end; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service;
the interface access request is routed to a server and a micro-service module corresponding to the module identifier according to the module identifier, so that the server further searches a corresponding service instance in the micro-service module according to the service identifier, acquires a corresponding method and a parameter definition list in the service instance according to the method identifier, and calls the method based on the request parameter and the parameter definition list, thereby acquiring an interface access request processing result;
and receiving the interface access request processing result returned by the server, and sending the interface access request processing result to the front end.
2. The interface access request processing method according to claim 1, wherein the receiving of the interface access request initiated by the front end includes:
receiving an interface access request initiated by a front end based on an HTTP interface protocol; wherein the protocol format of the HTTP interface protocol comprises the module identifier, the service identifier and the method identifier, and
the request parameter exists in the protocol format of the HTTP interface protocol or a request body corresponding to the interface access request.
3. The interface access request processing method according to claim 1, wherein a name of the request parameter coincides with a parameter name of a method in the service instance corresponding to the interface access request.
4. An interface access request processing method, comprising:
acquiring an interface access request from a front end, which is sent by an API gateway; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service;
searching a corresponding service instance in a micro service module corresponding to the module identifier according to the service identifier, acquiring a corresponding method and a parameter definition list in the service instance according to the method identifier, and calling the method based on the request parameter and the parameter definition list so as to acquire an interface access request processing result;
and sending the interface access request processing result to the front end through an API gateway.
5. The interface access request processing method according to claim 4, wherein the method invoking based on the request parameter and the parameter definition list specifically includes:
acquiring a parameter name and a parameter type of the method according to the parameter definition list;
converting the parameter value in the request parameter into a value object corresponding to the parameter type in the parameter definition list;
instantiating a corresponding parameter object according to the parameter name, the parameter type and the value object;
and executing a method call on the method through a java reflection mechanism based on the parameter object.
6. An API gateway, comprising:
a request receiving unit configured to: receiving an interface access request initiated by a front end; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service;
a routing unit to: the interface access request is routed to a server and a micro-service module corresponding to the module identifier according to the module identifier, so that the server further searches a corresponding service instance in the micro-service module according to the service identifier, acquires a corresponding method and a parameter definition list in the service instance according to the method identifier, and calls the method based on the request parameter and the parameter definition list, thereby acquiring an interface access request processing result;
a feedback unit to: and receiving the interface access request processing result returned by the server, and feeding back the interface access request processing result to the front end.
7. A server, comprising:
a request acquisition unit configured to: acquiring an interface access request from a front end, which is sent by an API gateway; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service;
a distribution processing unit configured to: searching a corresponding service instance in a micro service module corresponding to the module identifier according to the service identifier, acquiring a corresponding method and a parameter definition list in the service instance according to the method identifier, and calling the method based on the request parameter and the parameter definition list so as to acquire an interface access request processing result;
a transmitting unit configured to: and sending the interface access request processing result to the front end through an API gateway.
8. An interface access request processing system is characterized by comprising a front end, an API gateway and a server; wherein:
the front end is used for sending an interface access request to the API gateway; the interface access request comprises a module identifier, a service identifier, a method identifier and a request parameter of the micro service;
the API gateway is used for receiving the interface access request and routing the interface access request to the server and the micro-service module corresponding to the module identifier according to the module identifier;
the server is used for receiving the interface access request, searching a corresponding service instance in a micro-service module corresponding to the module identifier according to the service identifier, acquiring a corresponding method and a parameter definition list in the service instance according to the method identifier, calling the method based on the request parameter and the parameter definition list so as to acquire an interface access request processing result, and sending the interface access request processing result to the API gateway;
the API gateway is also used for receiving the interface access request processing result and feeding back the interface access request processing result to the front end;
the front end is also used for receiving the interface access request processing result fed back by the API gateway.
9. A non-transitory computer-readable storage medium having stored thereon a computer program, wherein the computer program, when executed by a processor, implements the steps of the interface access request processing method according to any one of claims 1 to 5.
10. A computer program product comprising computer programs/instructions, characterized in that the computer programs/instructions, when executed by a processor, implement the steps of the interface access request processing method according to any of claims 1 to 5.
CN202110882756.3A 2021-08-02 2021-08-02 Interface access request processing method, API gateway, server and system Pending CN113806104A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110882756.3A CN113806104A (en) 2021-08-02 2021-08-02 Interface access request processing method, API gateway, server and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110882756.3A CN113806104A (en) 2021-08-02 2021-08-02 Interface access request processing method, API gateway, server and system

Publications (1)

Publication Number Publication Date
CN113806104A true CN113806104A (en) 2021-12-17

Family

ID=78942679

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110882756.3A Pending CN113806104A (en) 2021-08-02 2021-08-02 Interface access request processing method, API gateway, server and system

Country Status (1)

Country Link
CN (1) CN113806104A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110648241A (en) * 2019-08-14 2020-01-03 中国平安财产保险股份有限公司 Claim settlement processing method and device based on micro-service architecture
CN115185712A (en) * 2022-09-08 2022-10-14 中化现代农业有限公司 Data interaction method and device, electronic equipment and storage medium
CN110648241B (en) * 2019-08-14 2024-05-28 中国平安财产保险股份有限公司 Method and device for processing claims based on micro-service architecture

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107483538A (en) * 2017-07-06 2017-12-15 聚好看科技股份有限公司 A kind of method and apparatus that access request bag is handled on the node of micro services cluster
CN108901022A (en) * 2018-06-28 2018-11-27 深圳云之家网络有限公司 A kind of micro services universal retrieval method and gateway
CN109150978A (en) * 2018-07-24 2019-01-04 北京百度网讯科技有限公司 The method and apparatus for debugging micro services
CN110830280A (en) * 2018-08-10 2020-02-21 深圳市鸿合创新信息技术有限责任公司 Micro-service gateway device and method and electronic equipment
CN110971449A (en) * 2019-10-25 2020-04-07 武汉烽火众智数字技术有限责任公司 Service management and control system based on micro-service architecture
CN111314459A (en) * 2020-02-13 2020-06-19 北京奇艺世纪科技有限公司 Service request method, device, electronic equipment and storage medium
CN111752965A (en) * 2020-05-29 2020-10-09 南京南瑞继保电气有限公司 Real-time database data interaction method and system based on micro-service
US20200351243A1 (en) * 2018-03-13 2020-11-05 Huawei Technologies Co., Ltd. Method and apparatus for transmitting application programming interface api request
CN112134721A (en) * 2020-08-17 2020-12-25 福建天泉教育科技有限公司 API gateway degradation method and terminal
CN112346871A (en) * 2020-11-24 2021-02-09 深圳前海微众银行股份有限公司 Request processing method and micro-service system
CN112866177A (en) * 2019-11-26 2021-05-28 浙江大搜车软件技术有限公司 Method, device, storage medium and computer equipment for processing service call request
CN113076502A (en) * 2021-04-23 2021-07-06 南京始云网络科技有限公司 Parameter control method and system based on request identification

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107483538A (en) * 2017-07-06 2017-12-15 聚好看科技股份有限公司 A kind of method and apparatus that access request bag is handled on the node of micro services cluster
US20200351243A1 (en) * 2018-03-13 2020-11-05 Huawei Technologies Co., Ltd. Method and apparatus for transmitting application programming interface api request
CN108901022A (en) * 2018-06-28 2018-11-27 深圳云之家网络有限公司 A kind of micro services universal retrieval method and gateway
CN109150978A (en) * 2018-07-24 2019-01-04 北京百度网讯科技有限公司 The method and apparatus for debugging micro services
CN110830280A (en) * 2018-08-10 2020-02-21 深圳市鸿合创新信息技术有限责任公司 Micro-service gateway device and method and electronic equipment
CN110971449A (en) * 2019-10-25 2020-04-07 武汉烽火众智数字技术有限责任公司 Service management and control system based on micro-service architecture
CN112866177A (en) * 2019-11-26 2021-05-28 浙江大搜车软件技术有限公司 Method, device, storage medium and computer equipment for processing service call request
CN111314459A (en) * 2020-02-13 2020-06-19 北京奇艺世纪科技有限公司 Service request method, device, electronic equipment and storage medium
CN111752965A (en) * 2020-05-29 2020-10-09 南京南瑞继保电气有限公司 Real-time database data interaction method and system based on micro-service
CN112134721A (en) * 2020-08-17 2020-12-25 福建天泉教育科技有限公司 API gateway degradation method and terminal
CN112346871A (en) * 2020-11-24 2021-02-09 深圳前海微众银行股份有限公司 Request processing method and micro-service system
CN113076502A (en) * 2021-04-23 2021-07-06 南京始云网络科技有限公司 Parameter control method and system based on request identification

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
ANTONIO CELESTI: ""A Watchdog Service Making Container-Based Micro-services Reliable in IoT Clouds "", 《 2017 IEEE 5TH INTERNATIONAL CONFERENCE ON FUTURE INTERNET OF THINGS AND CLOUD》 *
朱汉卿: ""基于改进多目标进化算法的微服务用户请求分配策略"", 《计算机科学》 *
王子勇;王焘;张文博;陈宁江;左春;: "一种基于执行轨迹监测的微服务故障诊断方法", 软件学报, no. 06 *
田兵;王玮;苏琦;刘荫;殷齐林;郭爽爽;: "基于微服务架构的应用性能监控平台研究", 信息技术与信息化, no. 01 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110648241A (en) * 2019-08-14 2020-01-03 中国平安财产保险股份有限公司 Claim settlement processing method and device based on micro-service architecture
CN110648241B (en) * 2019-08-14 2024-05-28 中国平安财产保险股份有限公司 Method and device for processing claims based on micro-service architecture
CN115185712A (en) * 2022-09-08 2022-10-14 中化现代农业有限公司 Data interaction method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
US8656417B2 (en) Interface for telecommunication services using uniform resource identifiers
CN109815025B (en) Service model calling method, device and storage medium
CN110119292B (en) System operation parameter query method, matching method, device and node equipment
CN110413418B (en) Cache synchronization device and method, cache synchronization system and electronic equipment
JP2022523914A (en) Methods, systems and computer readable media for data conversion using the Representational State Transfer (REST) application programming interface (API).
CN112671950B (en) Domain name processing method and device based on block chain, electronic equipment and storage medium
CN110753129A (en) Message transmission method, system, device, equipment and computer readable storage medium
CN113691635B (en) Method and device for calling microservice, electronic equipment and readable storage medium
CN114416075A (en) Service processing method and device
CN109343983B (en) Information interaction method, device, equipment and storage medium between function modules
CN109885347B (en) Method, device, terminal, system and storage medium for acquiring configuration data
CN111858083A (en) Remote service calling method and device, electronic equipment and storage medium
CN111008254B (en) Object creation method, device, computer equipment and storage medium
CN109388388B (en) Information interaction method, device, equipment and storage medium between function modules
CN113806104A (en) Interface access request processing method, API gateway, server and system
CN112860308A (en) Configuration method of interface definition, service processing method, server and storage medium
WO2023208132A1 (en) Api conversion system and access request processing method therefor, and electronic device and medium
CN114840574A (en) Data query method, server, node and storage medium
CN114125067A (en) Front-end and back-end separated gray scale publishing method, front-end server and configuration server
US10545983B2 (en) Key versioning for business objects
KR20090042542A (en) Method for collecting quality data of web service using dummy message
CN112650601B (en) Method, apparatus, device, storage medium, and program for opening applet across hosts
US20090100336A1 (en) Methods and systems for communicating data
CN115242631B (en) Message processing method and device, electronic equipment and storage medium
CN114448703B (en) Request processing method, request processing device, electronic equipment and storage medium

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