CN112637289A - Micro-service request processing method, equipment and storage medium - Google Patents

Micro-service request processing method, equipment and storage medium Download PDF

Info

Publication number
CN112637289A
CN112637289A CN202011463785.8A CN202011463785A CN112637289A CN 112637289 A CN112637289 A CN 112637289A CN 202011463785 A CN202011463785 A CN 202011463785A CN 112637289 A CN112637289 A CN 112637289A
Authority
CN
China
Prior art keywords
service
request
target
types
preset
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
CN202011463785.8A
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.)
WeBank Co Ltd
Original Assignee
WeBank 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 WeBank Co Ltd filed Critical WeBank Co Ltd
Priority to CN202011463785.8A priority Critical patent/CN112637289A/en
Publication of CN112637289A publication Critical patent/CN112637289A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services
    • H04L67/565Conversion or adaptation of application format or content
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • G06F16/9535Search customisation based on user profiles and personalisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
    • G06F16/9566URL specific, e.g. using aliases, detecting broken or misspelled links
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/08Protocols for interworking; Protocol conversion

Abstract

The embodiment of the application discloses a micro-service request processing method, which comprises the following steps: receiving a service request sent by client equipment; analyzing the service request, and determining n request services included in the service request; determining n service types of the request service to obtain n service types; if the n service types comprise p first preset types and n-p second preset types, converting the service request based on the p first preset types to obtain p target requests; sending each target request to a first service device having an association relation with the first preset type; sending the service request to a second service device associated with the second preset type; wherein the service request is used for enabling the second service device to provide a corresponding service. The embodiment of the application also discloses gateway equipment and a storage medium.

Description

Micro-service request processing method, equipment and storage medium
Technical Field
The present application relates to the field of computer application technologies, and in particular, to a method, a device, and a storage medium for processing a microservice request.
Background
With the rapid development of computer technology, more and more technologies are applied in the financial field, and the traditional financial industry is gradually changing to financial technology (Fintech), but higher requirements are also put forward on the technologies due to the requirements of the financial industry on safety and real-time performance. Microservice as a cloud-native architecture approach, where a single application consists of many loosely coupled and independently deployable smaller components or services, enables easy code updates, teams can use different stacks and components for different components, can scale independently of each other, reduces the waste and cost of having to scale the entire application, and is widely used. At present, in order to avoid letting the client device know the existence of multiple micro services of the server, an Application Programming Interface (API) gateway is provided between the client device and the server device, so that after the client device sends a service request to the API gateway, the API gateway searches for a micro service address corresponding to the service request according to user configuration, and if routing information matching the service request is found, the API gateway performs authentication, authentication and the like on the request information, and then forwards the service request to the micro service corresponding to the server device according to the matching routing information, so as to implement that the server device provides the service corresponding to the service request for the client device.
However, at present, a service request sent by a client device is based on a HyperText Transfer Protocol (HTTP) or a HyperText Transfer security Protocol (HTTPs), so that when the API gateway forwards the service request, the service request can only be forwarded to a microservice providing an HTTP/HTTPs access interface, and correspondingly, when the microservice provides a service interface based on a non-HTTP/HTTPs Protocol, the microservice is required to convert the provided service interface into a service interface in an HTTP/HTTPs Protocol format, which results in low forwarding efficiency of the API gateway at present.
Content of application
In order to solve the above technical problems, embodiments of the present application desirably provide a method, a device, and a storage medium for processing a micro service request, so as to solve a problem that an API gateway cannot send a request including a non-HTTP/HTTPs protocol to a corresponding micro service, implement a technical scheme that the API gateway can directly forward the request including the non-HTTP/HTTPs protocol to the corresponding micro service, and effectively improve forwarding efficiency of the API gateway.
The technical scheme of the application is realized as follows:
in a first aspect, a method for processing microservice requests includes:
receiving a service request sent by client equipment;
analyzing the service request, and determining n request services included in the service request; wherein n is an integer greater than or equal to 1;
determining n service types of the request service to obtain n service types;
if the n service types comprise p first preset types and n-p second preset types, converting the service request based on the p first preset types to obtain p target requests; the first preset type is a service type except the second preset type, p is an integer which is greater than or equal to 1 and smaller than n, and the value of n-p is greater than or equal to 1;
sending each target request to a first service device having an association relation with the first preset type;
sending the service request to a second service device associated with the second preset type; wherein the service request is used for enabling the second service device to provide a corresponding service.
In a second aspect, a gateway device, the device comprising a memory, a processor, and a communication bus; wherein:
the memory to store executable instructions;
the communication bus is used for realizing communication connection between the processor and the memory;
the processor is configured to execute the micro-service request processing program stored in the memory, and implement the steps of the micro-service request processing method according to any one of the above descriptions.
In a third aspect, a storage medium has stored thereon a microservice request handling program which, when executed by a processor, implements the steps of a microservice request handling method as defined in any of the above.
In the embodiment of the application, after receiving a service request sent by a client device, a gateway device parses the service request, determines n request services included in the service request, determines service types of the n request services, obtains n service types, converts the service request based on the p first preset types if the n service types include p first preset types and n-p second preset types, obtains p target requests, sends each target request to a first service device having an association relationship with the first preset type, and sends the service request to a second service device having an association relationship with the second preset type. Therefore, the gateway device judges whether to convert the service request according to the service type of the request service included in the service request, converts the service request into a corresponding target request and forwards the target request to the corresponding service device when the service request is determined to be converted, and directly forwards the service request to the corresponding service device when the service request is not required to be converted, so that the problem that the forwarding efficiency is low because the existing API gateway cannot provide a service interface of a non-HTTP/HTTPS protocol to realize direct service exchange of the micro-service of the non-HTTP/HTTPS protocol is solved, the technical scheme that the API gateway can directly forward the request of the non-HTTP/HTTPS protocol to the corresponding micro-service part is realized, the forwarding efficiency of the API gateway is effectively improved, and the functions of the API gateway are enriched.
Drawings
Fig. 1 is a schematic flowchart of a method for processing a microservice request according to an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of another method for processing a microservice request according to an embodiment of the present disclosure;
fig. 3 is a schematic structural diagram of a micro service architecture according to an embodiment of the present application;
fig. 4 is a schematic flowchart of another method for processing a microservice request according to an embodiment of the present application;
fig. 5 is a flowchart illustrating a method for processing a microservice request according to another embodiment of the present application;
FIG. 6 is a flowchart illustrating another method for processing a microservice request according to another embodiment of the present application;
fig. 7 is a schematic flowchart of another method for processing a microservice request according to another embodiment of the present application;
fig. 8 is a flowchart illustrating a method for processing a microservice request according to another embodiment of the present application;
fig. 9 is a schematic structural diagram of a gateway device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application.
An embodiment of the present application provides a method for processing a microservice request, which is shown in fig. 1 and is applied to a gateway device, and the method includes the following steps:
step 101, receiving a service request sent by a client device.
In the embodiment of the present application, the gateway device is in a micro service architecture, and is configured to manage and control a client device and a micro service provided by a server device, that is, the client device interacts with the gateway device, and the gateway device realizes invocation of the micro service based on a service request sent by the client device. The gateway device may have some other functions, such as authentication, monitoring, caching, load balancing, traffic control, and routing forwarding, in addition to the micro service invocation service. The gateway device may be a virtual gateway device or an entity gateway device. The client device may be a device used by a user, and may be, for example, a smart mobile device or a computer device or the like having a function of accessing the internet.
Step 102, analyzing the service request, and determining n request services included in the service request.
Wherein n is an integer greater than or equal to 1.
In the embodiment of the application, after the gateway device receives the service request sent by the client device, the gateway device analyzes the service request to obtain n request services included in a request header of the service request. n is at least 1. The request service is a service that the client device wishes the server device to provide.
And 103, determining the service types of the n request services to obtain n service types.
In the embodiment of the application, the service type of each request service in the n request services is determined, so that n service types are obtained. For example, assuming that there are 2 request services a and B included in the service request, it may be determined that 2 service types are obtained, which are the service type of the request service a and the service type of the request service B. It should be noted that there may be the same service type in the included n service types, that is, when n is greater than or equal to 2, there may be 2 or more than 2 of the n service types.
And step 104, if the n service types comprise p first preset types and n-p second preset types, converting the service request based on the p first preset types to obtain p target requests.
The first preset type is a service type except the second preset type, p is an integer which is greater than or equal to 1 and smaller than n, and the value of n-p is greater than or equal to 1.
In this embodiment of the application, when n is an integer greater than 1 and the n service types include both a first preset type and a second preset type, the service request is converted based on the first preset type of the n service types to obtain a target request corresponding to each first preset type. For example, taking n as 3 and p as 2 as an example for explanation, when 3 service types are specifically 2 first preset types and 1 second preset type, based on 2 first preset types a1 and B1, a service request is converted to obtain 2 target requests, which are a target request a corresponding to the first preset type a1 and a target request B corresponding to the first preset type B1, respectively.
And 105, sending each target request to the first service equipment with the association relation with the first preset type.
In this embodiment of the present application, the first service device with the first preset type having an association relationship refers to a service device that provides a micro service of the first preset type, that is, after the gateway device obtains p target requests, each target request is respectively forwarded to the first service device that provides a corresponding request service of the first preset type. The first service device is a service device providing at least one microservice. Illustratively, the gateway device forwards the target request a to a first service device providing a micro service of a first preset type a1, and forwards the target request B to a second service device providing a micro service of a first preset type B1.
And step 106, sending the service request to a second service device having an association relation with a second preset type.
The service request is used for enabling the second service equipment to provide corresponding services.
In this embodiment of the present application, the second service device of the second preset type having an association relationship refers to a service device that provides a microservice of the second preset type. That is, when the gateway device determines that the n service types include n-p second preset types, the gateway device directly forwards the service request to a second service device providing a microservice of the second preset type without performing conversion processing on the service request. The second preset type may have an association relationship with the type of the service request. In some application scenarios, when n-p is greater than 1, the gateway device may determine, according to an actual requirement, the number of second service devices to which the service request is forwarded according to the service request, and therefore, the number of times that the gateway device forwards the service request is not specifically limited, and may specifically be determined according to the micro service provided by the second service device.
In the embodiment of the application, after receiving a service request sent by a client device, a gateway device parses the service request, determines n request services included in the service request, determines service types of the n request services, obtains n service types, converts the service request based on the p first preset types if the n service types include p first preset types and n-p second preset types, obtains p target requests, sends each target request to a first service device having an association relationship with the first preset type, and sends the service request to a second service device having an association relationship with the second preset type. Therefore, the gateway equipment judges whether to convert the service request according to the service type of the request service included in the service request, converts the service request into a corresponding target request and forwards the target request to the corresponding service equipment when the service request is determined to be converted, and solves the problem that the forwarding efficiency is low because the existing API gateway cannot provide a service interface of a non-HTTP/HTTPS protocol so as to realize direct service transaction of the micro-service of the non-HTTP/HTTPS protocol, thereby realizing the technical scheme that the API gateway can directly forward the request of the non-HTTP/HTTPS protocol to the corresponding micro-service, effectively improving the forwarding efficiency of the API gateway and enriching the functions of the API gateway.
Based on the foregoing embodiments, an embodiment of the present application provides a method for processing a microservice request, which is shown in fig. 2 and is applied to a gateway device, and the method includes the following steps:
step 201, receiving a service request sent by a client device.
In an embodiment of the present application, a microservice architecture is provided, which is shown in fig. 3, and includes a client device 31, a gateway device 32, and a server device 33, where: the gateway device 32 is used for information transfer between the client device 31 and the server device 33, and the server device 33 includes a plurality of server devices for providing a plurality of micro services. The micro service system corresponding to the micro service architecture shown in fig. 3 can be roughly divided into three layers, including: a presentation layer, an API gateway layer and a business logic layer. The presentation layer runs in the client device and realizes interaction with a user, and comprises a World Wide Web (Web) page, an Application program (APP) page, an interface for a third party to call and the like; the API gateway layer runs in the gateway equipment and is a uniform inlet of the micro-service system, the outside accesses the micro-service through the uniform API gateway, and simultaneously processes some non-service functions, such as monitoring, load balancing, flow control, identity authentication and the like; the service logic layer runs on the server-side equipment and is responsible for realizing the service rules.
Illustratively, the client device sends a service request in HTTP format to the gateway device.
Step 202, parsing the service request and determining n request services included in the service request.
Wherein n is an integer greater than or equal to 1.
In the embodiment of the present application, the gateway device analyzes the service request, and determines to obtain n request services from a request header of the service request.
Illustratively, when the API gateway layer receives an HTTP service request from a user, the API gateway layer parses a request header of the HTTP service request to obtain a cache (Cookie) value with a target key. Wherein, the Cookie value indicates the request service included in the HTTP service request. If the Cookie value is RMB, indicating that the requested service is a Reliable Message Bus (RMB) Reliable Message Bus service; if the Cookie value is RMB and HTTP, it indicates that there are two request services, RMB service and HTTP service.
Step 203, determining the service types of the n request services to obtain n service types.
In the embodiment of the present application, when the Cookie value is RMB, n is 1, and the corresponding service type is RMB. When the Cookie value is RMB and HTTP, n is 2, and the corresponding 2 service types are RMB service type and HTTP service type.
Step 204, if the n service types include p first preset types and n-p second preset types, obtaining a target request conversion processor corresponding to each first preset type.
The first preset type is a service type except the second preset type, p is an integer which is greater than or equal to 1 and smaller than n, and the value of n-p is greater than or equal to 1.
In the embodiment of the present application, the target request conversion processor is a converter that is generated in advance, stored in a storage unit corresponding to the gateway device, and is configured to convert the service request to a corresponding target request of a first preset type. The second preset type is an HTTP service type, and the first preset type is a service type other than the HTTP service type, and may be, for example, an RMB service type, a WebSocket service type, or the like.
Illustratively, when the Cookie value is RMB and HTTP, n is 2, and the corresponding 2 service types are an RMB service type and an HTTP service type, the target request conversion processor corresponding to the RMB service type is acquired.
Step 205, analyzing the service request by the target request conversion processor to obtain a target parameter corresponding to each first preset type, and encapsulating the target parameter by adopting a parameter format corresponding to each first preset type to obtain p target requests.
In the embodiment of the application, the gateway device converts the service request into the corresponding target request through the target request conversion processor. Illustratively, the HTTP service request is used as an input parameter of a target request conversion processor corresponding to the RMB service type, and is input into the target request conversion processor corresponding to the RMB service type, and the target request conversion processor corresponding to the RMB service type outputs a target request in the RMB format. When the target request conversion processor corresponding to the RMB service type parses the HTTP service request, because the RMB has no request header, the target request conversion processor corresponding to the RMB service type filters out the request header content of the HTTP service request, and RMB does not obtain (get), issue (post), and other request manners, and the target request conversion processor corresponding to the RMB service type masks these request manners, i.e., deletes the items that are invalid for the RMB, so as to parse out the parameters of different request manners of the HTTP, i.e., keep the parameters required by the RMB as target parameters, and encapsulate the parsed parameters required by the RMB in a uniform RMB parameter format, thereby obtaining the target request corresponding to the RMB service type.
Step 206, sending each target request to the first service device having an association relation with the first preset type.
In this embodiment of the present application, the gateway device forwards the target request corresponding to the RMB service type to the first service device providing the RMB service.
And step 207, sending the service request to a second service device associated with the second preset type.
The service request is used for enabling the second service equipment to provide corresponding services.
In an embodiment of the present application, the gateway device forwards the HTTP service request to a second service device that provides the HTTP service.
Therefore, the preset target conversion processor is used for converting the service request, the conversion efficiency is effectively improved, and the process of obtaining the target request by packaging during converting the service request can perform operations such as compression and/or filtration according to the service type of the request service, so that the size of a target request body is effectively reduced, and the consumption of network bandwidth is further reduced. And the gateway device and the server device are communicated through interfaces with different protocols, so that the gateway device performs one-time conversion processing on a received service request sent by the client device to obtain a target request corresponding to the corresponding server device and sends the target request to the corresponding server device, correspondingly, the API gateway can receive a response in any protocol format sent by the micro-service, and then packages the received response into a response in an HTTP format to return to the client device, thereby effectively improving the service processing efficiency in the micro-service architecture.
Based on the foregoing embodiments, in other embodiments of the present application, step 204 may be implemented by steps 204a to 204 c:
step 204a, if the n service types include p first preset types and n-p second preset types, obtaining the mapping relation of the request conversion processor.
In this embodiment of the application, the mapping relationship of the request conversion processor is a search relationship preset for different preset types of the gateway device and identification information of the request conversion processor corresponding to the different preset types. In some application scenarios, the request conversion process mapping relationship may be represented in the form of a list.
And step 204b, determining the identification information of the target request conversion processor corresponding to each first preset type from the mapping relation of the request conversion processors.
Step 204c, obtaining the target request conversion processor corresponding to the identification information of the target request conversion processor from the target storage area corresponding to the gateway device.
In this way, the target request conversion processor corresponding to each first preset type is searched through the mapping relation of the request conversion processor arranged at the gateway device, and the searching efficiency of the target request conversion processor is effectively improved.
Based on the foregoing embodiments, in other embodiments of the present application, referring to fig. 4, before the gateway device performs step 202, steps 208 to 210 may be performed:
and step 208, acquiring the stored storage file from the target storage area.
In this embodiment, the target storage area may be a storage area corresponding to the gateway device and used for storing the request conversion processor. And the gateway equipment acquires all storage files stored in the target storage area.
Step 209, selecting a target file in a target form from the storage files.
In the embodiment of the present application, the target form may refer to a named form of a file, and in some application scenarios, may also be a storage format of the file. Illustratively, the gateway device selects a file named as a target form from the acquired storage files to obtain a target file.
Step 210, based on the target file, generating a mapping relation of the request conversion processor.
In the embodiment of the application, the gateway device counts the identification information of the target file to obtain the mapping relation of the request conversion processor.
It should be noted that the embodiments corresponding to steps 208-210 can be performed before any step before step 202. The steps 208 to 210 may also be implemented as an independent embodiment, and may be implemented at a certain time, for example, when the gateway device is started or a gateway system operated by the gateway device is started, or after the request conversion processor is updated, the steps 208 to 209 may be implemented to correspondingly update the mapping relationship of the request conversion processor. Therefore, the conversion efficiency of the gateway equipment when converting the service request is effectively improved by presetting the mapping relation of the request conversion processor.
Based on the foregoing embodiments, in other embodiments of the present application, step 210 may be implemented by steps 210a to 210 d:
step 210a, obtaining the target identification information of each target file.
In the embodiment of the present application, the target identification information of each target file may be information for uniquely identifying the target file, and may be, for example, a name of the target file.
And step 210b, determining a storage path of each target file stored in the target storage area.
And step 210c, performing reflective loading based on each target identification information and the corresponding storage path to obtain each reference request conversion processor.
Step 210d, generating a request conversion processor mapping relation based on each target identification information and the corresponding reference request conversion processor.
Exemplarily, 1) when the API gateway system is started, the API gateway obtains all files, i.e., storage files, in the target storage area, i.e., in the converter assembly path, through the file operation class, and forms a file assembly. When the converter set path includes a folder, the subfolders included in the folder can be determined and obtained in a recursive request mode, that is, the subfolders meeting the requirement are determined from the folder continuously through the same query request, and each query request queries the folder to obtain one subfolder until no subfolder meeting the requirement exists in the folder. The file set may further include a subfolder path, for example, a file named http rmbhandler. The target storage area, i.e., the converter set path, may be default to the system or may be specified in a configuration file.
2) Naming in the form of e.g. http:/Handler can be set in the API gateway, so that the target form is determined as http:/Handler, i.e. selecting the target files named as http:/Handler from the file collection, and determining the target identification information of each target form of the target files. The target file is used for specifying a request conversion method, the entry parameter of the method is an HTTP service request, and the return parameter is an HTTP response, namely an output target request. Illustratively, a name HTTP rmbhandler denotes a request conversion processor that converts an HTTP service request into a target request corresponding to an RMB.
3) And acquiring target identification information of each target file in the target form determined in the step 2) as http header, and determining a storage path of each target file in the target form, wherein the storage path of each target file in the target form comprises a converter set path. The API gateway performs the following operations according to the storage path of the target file of each target form in a reflection mode:
a. and (4) lexical analysis. And reading the complete converter class definition content in the file into a memory, and identifying keywords in the definition content. These keys are either reserved keys of the Java language (e.g., if, else, while, etc.) or meet the Java's variable naming specification (beginning with a letter or underline). An exception is thrown that does not meet the requirements and the operation is terminated.
b. And (5) analyzing the syntax. Checking whether the key words in the a are combined together to be in accordance with the Java language specification. If the if key is followed by a boolean judgment expression, the function definition includes a return type, a function name, a function body, and the like.
c. And (5) semantic analysis. The structurally correct source program is examined for context-related properties, whether there are semantic errors. If the array subscript is an integer, the automatic type conversion is correct.
d. And generating byte codes. And translating the content of the source file into byte codes conforming to the specification of the Java virtual machine to obtain each reference request conversion processor, and storing the reference request conversion processor in a memory. In this way, the API gateway may call a method or attribute in the translated file, i.e., request the conversion processor to complete the corresponding conversion processing operation.
4) A request translation processor mapping table is constructed. And (3) constructing a request conversion processor mapping table in the memory by taking the target identification information of the target file in each target form determined in the step 2) as a key and each reference request conversion processor obtained by reflection loading in the step 3) as a value.
Therefore, the request conversion processors stored in the gateway equipment are counted in advance to generate the request conversion processor mapping table, the condition that the request conversion processors do not exist is effectively reduced, and the request conversion processing efficiency of the gateway equipment is improved.
Based on the foregoing embodiment, in another embodiment of the present application, referring to fig. 5, before the gateway device performs step 206, it is further configured to perform the following steps:
and step 211, acquiring the mapping relation of the Uniform Resource Identifier (URI).
In the embodiment of the present application, the URI mapping relationship is a URI mapping relationship corresponding to a second preset type. The URI mapping relation is equipment identification information of preset service equipment for providing the micro-service except for a second preset type.
Step 212, based on the p first preset types, determining device identification information for providing services for each first preset type from the URI mapping relationship.
In this embodiment of the application, the device identification information included in the URI mapping relationship and serving each first preset type may be interface identification information provided externally for each micro service pair. The devices providing services for different first preset types are different, and the corresponding device identification information is also different.
Step 213, determining the first service device based on the device identification information.
In the embodiment of the present application, it should be noted that in some application scenarios, one service device may provide different preset types of micro services.
Therefore, the service equipment providing the micro service of the first preset type is determined through the preset URI mapping relation, the efficiency of determining the service equipment providing the micro service is effectively improved, and the forwarding efficiency of forwarding the target request by the gateway equipment is improved.
Based on the foregoing embodiments, in other embodiments of the present application, step 211 may be implemented by steps 211a to 211 c:
step 211a, determining reference device identification information of at least one server device managed and controlled by the gateway device.
The at least one server device comprises a first service device and a second service device.
In this embodiment of the application, the reference device identification information of the at least one server device may be interface identification information provided externally by the at least one server device.
Step 211b determines at least one target device identification information providing a service other than the service of the second service type from the at least one reference device identification information.
In this embodiment of the application, since the gateway device manages that at least one service device, which is in communication connection with the gateway device, includes both HTTP format and non-HTTP format, at least one target device identification information belonging to the non-HTTP format is determined from the at least one reference device identification information.
Step 211c, generating a URI mapping relationship based on the at least one piece of target device identification information.
In the embodiment of the application, at least one piece of target equipment identification information belonging to a non-HTTP format is counted, and a URI mapping relation of the target equipment identification information providing a service in the non-HTTP format is generated.
It should be noted that, steps 211a to 211c may be executed before any step before step 210, or may be executed as an independent embodiment, and are executed at a certain time, for example, when the gateway device is started or the gateway system in which the gateway device operates is started, or after the micro service provided by the service end is updated, steps 211a to 211c may be executed to correspondingly update the URI mapping relationship.
Therefore, the efficiency of determining the service equipment providing the micro service is effectively improved and the forwarding efficiency of the gateway equipment for forwarding the target request is improved by presetting the URI mapping relation including at least one target equipment identification information in a non-HTTP format.
Based on the foregoing embodiments, in other embodiments of the present application, the step 211c may be implemented by the steps a 11-a 13:
step a11, determining the target annotation corresponding to each target device identification information.
Step a12, obtaining target attributes from the target annotation.
Step a13, generating URI mapping relation based on each target attribute and corresponding target device identification information.
In the embodiment of the present application, for example, (1) when the API gateway is started, a user-defined annotation, that is, a target annotation, included in the API gateway is loaded by using a Spring framework. Wherein the custom annotation contains a property path (path), i.e. a target property.
(2) And determining a service interface provided by at least one server-side device, namely reference device identification information of the server-side device. And determining a business service interface in a non-HTTP format from the business service interfaces provided by the determined at least one service device to obtain at least one piece of target device identification information. The service interface in non-HTTP format has corresponding self-defined annotation, and the attribute path included in the self-defined annotation is used for specifying the corresponding HTTP URI, so that the service interface can be indicated to process the HTTP service request with the URI being the specified value. Therefore, whether the business service interface is in the non-HTTP format can be determined directly through the business service interface in the non-HTTP format.
Illustratively, the domain name corresponding to the service is www.wbnk.com, the service has an interface for providing an RMB service to the outside to query user information, and then an attribute path value/userinfo included in the custom annotation is added to the definition of the service interface, so that target device identification information corresponding to the RMB interface of the service is www.wbnk.com/userinfo.
(3) A request URI mapping table is constructed. And (3) constructing a URI mapping table of the non-HTTP request in the memory by taking the attribute path analyzed in the step (2) as a key and the corresponding target equipment identification information as a value.
Based on the foregoing embodiments, in other embodiments of the present application, referring to fig. 6, after the gateway device performs step 207, the gateway device is further configured to perform steps 214 to 216:
step 214, receiving the first service response sent by each first service device and the second service response sent by each second service device, and obtaining p first service responses and q second service responses.
Each first service response is a service response provided by the corresponding first service device for the received target request, and each second service response is a service response provided by the corresponding second service device for the received service request.
Step 215, the p first service responses and the q second service responses are processed to obtain the target response.
Wherein the target response is used for responding to the service request sent by the client device.
In this embodiment of the application, the gateway device performs splicing processing on the p first service responses and the q second service responses, assembles the p first service responses and the q second service responses into one HTTP response, that is, a target response, and returns the HTTP response to the client device. For the response of submitting the class request, only the total record number of successful or failed submission needs to be returned after the assembly; for the response of the data acquisition request, the assembly process can perform de-duplication and filtering on the returned data, so that the size of a response body is reduced to a certain extent, and the network bandwidth consumption is reduced.
Step 216, sending the target response to the client device.
In the embodiment of the application, the target response is sent to the client device, so that the response to the service request sent by the client device is realized.
Therefore, the gateway equipment is used for splicing the service responses fed back by the micro-services, generating target responses and returning the target responses to the client equipment, and the gateway equipment is used for splicing the service responses fed back by the micro-services, so that the filtering, white list control and the like of the service response data fed back by the micro-services are effectively controlled, the condition that the service response fed back by each micro-service is independently sent to the client equipment is avoided, and the efficiency of the gateway equipment for responding to the client equipment is effectively improved.
Based on the foregoing embodiment, in other embodiments of the present application, referring to fig. 7, if n service types are all the first preset types, after the gateway device performs step 203, it may further select to perform steps 217 to 221:
step 217, if the n service types are all the first preset type, performing conversion processing on the service request based on each service type to obtain n target requests.
In this embodiment of the application, when the n service types are all the first preset types, the service request is converted based on each service type, and a specific implementation process of obtaining the n target requests may refer to step 204 and step 205, and implementation processes corresponding to steps 204a to 204c, which are not described in detail herein.
Step 218, each target request is sent to the first service device having an association relationship with the first preset type.
Step 219, receiving a third service response sent by each first service device.
And step 220, processing the third service response to obtain a target response.
In the embodiment of the application, when n is 1, generating a target response in an HTTP format from a third service response sent by the first service device; and when n is greater than or equal to 2, splicing the plurality of third service responses to obtain target responses in the HTTP format.
Step 221, sending the target response to the client device.
In this embodiment of the application, if the n service types are all the second preset types, the service request is directly sent to the corresponding second service device, and when a fourth service response sent by each second service device is received, the fourth service response is packaged to obtain a target response, and the target response is sent to the client device.
Therefore, when the n service types are the first preset type, the gateway device converts the service request to obtain a corresponding target request and forwards the target request to the server device, so that the functions of the gateway device are effectively enriched, and the forwarding efficiency of the gateway device is improved.
Based on the foregoing embodiments, an embodiment of the present application provides a method for processing a microservice request, which is shown in fig. 8 and includes:
and step 31, the presentation layer sends the user request in the HTTP format sent by the client device to the gateway layer.
And step 32, the gateway layer analyzes the request header of the user request to obtain the request service type included in the user request.
Step 33, the gateway layer determines whether the request service type included in the user request is the HTTP type, if so, step 34 is executed, and if not, step 36 is executed.
Step 34, the gateway layer forwards the user request to the HTTP-type service interface.
Step 35, the gateway layer receives the service response 1 about the user request sent by the service interface of the HTTP type.
And step 36, the gateway layer acquires a request conversion processor corresponding to the request service type of the non-HTTP type, and performs conversion processing on the user request through the corresponding request conversion processor to obtain a target request 1 and a target request 2.
And step 37, the gateway layer acquires the URI mapping table.
And step 38, the gateway layer determines a service interface 1 corresponding to the request service type corresponding to the target request 1 based on the URI mapping table, sends the target request 1 to the service interface 1, determines a service interface 2 corresponding to the request service type corresponding to the target request 2, and sends the target request 2 to the service interface 2.
And step 39, the gateway layer receives the service response 2 aiming at the target request 1 sent by the service interface 1 and the service response 3 aiming at the target request 2 sent by the service interface 2.
And 310, the gateway layer performs splicing processing on the service response 1, the service response 2 and the service response 3 to obtain a target response.
Step 311, the gateway layer sends the target response to the presentation layer.
Step 312, the presentation layer displays the content corresponding to the target response.
It should be noted that, for the descriptions of the same steps and the same contents in this embodiment as those in other embodiments, reference may be made to the descriptions in other embodiments, which are not described herein again.
In the embodiment of the application, after receiving a service request sent by a client device, a gateway device parses the service request, determines n request services included in the service request, determines service types of the n request services, obtains n service types, converts the service request based on the p first preset types if the n service types include p first preset types and n-p second preset types, obtains p target requests, sends each target request to a first service device having an association relationship with the first preset type, and sends the service request to a second service device having an association relationship with the second preset type. Therefore, the gateway equipment judges whether to convert the service request according to the service type of the request service included in the service request, converts the service request into a corresponding target request and forwards the target request to the corresponding service equipment when the service request is determined to be converted, and solves the problem that the forwarding efficiency is low because the existing API gateway cannot provide a service interface of a non-HTTP/HTTPS protocol so as to realize direct service transaction of the micro-service of the non-HTTP/HTTPS protocol, thereby realizing the technical scheme that the API gateway can directly forward the request of the non-HTTP/HTTPS protocol to the corresponding micro-service, effectively improving the forwarding efficiency of the API gateway and enriching the functions of the API gateway.
Based on the foregoing embodiments, an embodiment of the present application provides a gateway device, and as shown in fig. 9, the gateway device 4 may include: a processor 41, a memory 42, and a communication bus 43, wherein:
a memory 42 for storing executable instructions;
a communication bus 43 for implementing a communication connection between the processor 41 and the memory 42;
a processor 41 for executing the microservice request handler stored in the memory 42 to implement the steps of:
receiving a service request sent by client equipment;
analyzing the service request, and determining n request services included in the service request; wherein n is an integer greater than or equal to 1;
determining the service types of n request services to obtain n service types;
if the n service types comprise p first preset types and n-p second preset types, converting the service request based on the p first preset types to obtain p target requests; the first preset type is a service type except the second preset type, p is an integer which is greater than or equal to 1 and smaller than n, and the value of n-p is greater than or equal to 1;
sending each target request to a first service device having an association relation with a first preset type;
sending a service request to a second service device associated with a second preset type; the service request is used for enabling the second service equipment to provide corresponding services.
In other embodiments of the present application, if the n service types include p first preset types and n-p second preset types, the processor performs the step of converting the service request based on the p first preset types to obtain p target requests, and the step may be implemented by:
if the n service types comprise p first preset types and n-p second preset types, acquiring a target request conversion processor corresponding to each first preset type;
and analyzing the service request to obtain a target parameter corresponding to each first preset type through a target request conversion processor, and packaging the target parameter by adopting a parameter format corresponding to each first preset type to obtain p target requests.
In other embodiments of the present application, if the n service types include p first preset types and n-p second preset types, the processor may perform the following steps when obtaining the target request conversion processor corresponding to each first preset type:
if the n service types comprise p first preset types and n-p second preset types, acquiring a mapping relation of a request conversion processor;
determining identification information of a target request conversion processor corresponding to each first preset type from the mapping relation of the request conversion processors;
and acquiring the target request conversion processor corresponding to the identification information of the target request conversion processor from the target storage area corresponding to the gateway equipment.
In other embodiments of the present application, the processor is further configured to, before performing the step of parsing the service request and determining n request services included in the service request, perform the following steps:
acquiring a stored storage file from a target storage area;
selecting a target file in a target form from the storage files;
based on the target file, a request to convert a processor mapping is generated.
In other embodiments of the present application, when the processor executes the step of generating the mapping relation for requesting to convert the processor based on the target file, the step of:
acquiring target identification information of each target file;
determining a storage path of each target file stored in a target storage area;
performing reflective loading based on each target identification information and the corresponding storage path to obtain each reference request conversion processor;
a request translation processor mapping relationship is generated based on each target identification information and the corresponding reference request translation processor.
In other embodiments of the present application, before the processor executes the step of sending each target request to the first service device having an association relationship with the first preset type, the processor is further configured to execute the following steps:
acquiring a Uniform Resource Identifier (URI) mapping relation;
determining equipment identification information for providing service for each first preset type from the URI mapping relation based on the p first preset types;
based on the device identification information, a first serving device is determined.
In other embodiments of the present application, when the processor executes the step of obtaining the uniform resource identifier URI mapping relationship, the step of obtaining the uniform resource identifier URI mapping relationship may be implemented by:
determining reference equipment identification information of at least one server side equipment controlled by gateway equipment; the at least one server device comprises a first service device and a second service device;
determining at least one target device identification information providing a service other than the service of the second service type from the at least one reference device identification information;
a URI mapping relation is generated based on at least one piece of target device identification information.
In other embodiments of the present application, when the processor executes the step of generating the URI mapping relationship based on at least one piece of target device identification information, the step of:
determining a target annotation corresponding to each target device identification information;
obtaining target attributes from the target annotations;
and generating a URI mapping relation based on each target attribute and the corresponding target equipment identification information.
In other embodiments of the present application, the processor is further configured to perform the steps of:
receiving a first service response sent by each first service device and a second service response sent by each second service device to obtain p first service responses and q second service responses; each first service response is a service response provided by the corresponding first service device for the received target request, and each second service response is a service response provided by the corresponding second service device for the received service request;
processing the p first service responses and the q second service responses to obtain target responses; the target response is used for responding to a service request sent by the client equipment;
and sending the target response to the client device.
In other embodiments of the present application, the processor is further configured to perform the steps of:
if the n service types are all the first preset types, converting the service request based on each service type to obtain n target requests;
sending each target request to a first service device having an association relation with a first preset type;
receiving a third service response sent by each first service device;
processing the third service response to obtain a target response;
and sending the target response to the client device.
It should be noted that, in the embodiment of the present application, the steps of the one or more programs may be explained by using one or more processors, and reference may be made to the implementation processes of the methods provided in the embodiments corresponding to fig. 1 to 2 and fig. 4 to 7, which are not described herein again.
In the embodiment of the application, after receiving a service request sent by a client device, a gateway device parses the service request, determines n request services included in the service request, determines service types of the n request services, obtains n service types, converts the service request based on the p first preset types if the n service types include p first preset types and n-p second preset types, obtains p target requests, sends each target request to a first service device having an association relationship with the first preset type, and sends the service request to a second service device having an association relationship with the second preset type. Therefore, the gateway equipment judges whether to convert the service request according to the service type of the request service included in the service request, converts the service request into a corresponding target request and forwards the target request to the corresponding service equipment when the service request is determined to be converted, and solves the problem that the forwarding efficiency is low because the existing API gateway cannot provide a service interface of a non-HTTP/HTTPS protocol so as to realize direct service transaction of the micro-service of the non-HTTP/HTTPS protocol, thereby realizing the technical scheme that the API gateway can directly forward the request of the non-HTTP/HTTPS protocol to the corresponding micro-service, effectively improving the forwarding efficiency of the API gateway and enriching the functions of the API gateway.
Based on the foregoing embodiments, embodiments of the present application provide a computer-readable storage medium, referred to as a storage medium for short, where one or more programs are stored in the computer-readable storage medium, and the one or more programs can be executed by one or more processors to implement the implementation process of the micro service request processing method provided in the embodiments corresponding to fig. 1 to 2 and fig. 4 to 7, which is not described herein again.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of a hardware embodiment, a software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The above description is only a preferred embodiment of the present application, and is not intended to limit the scope of the present application.

Claims (12)

1. A method for processing microservice requests, the method comprising:
receiving a service request sent by client equipment;
analyzing the service request, and determining n request services included in the service request; wherein n is an integer greater than or equal to 1;
determining n service types of the request service to obtain n service types;
if the n service types comprise p first preset types and n-p second preset types, converting the service request based on the p first preset types to obtain p target requests; the first preset type is a service type except the second preset type, p is an integer which is greater than or equal to 1 and smaller than n, and the value of n-p is greater than or equal to 1;
sending each target request to a first service device having an association relation with the first preset type;
sending the service request to a second service device associated with the second preset type; wherein the service request is used for enabling the second service device to provide a corresponding service.
2. The method of claim 1, wherein if the n service types include p first preset types and n-p second preset types, performing conversion processing on the service request based on the p first preset types to obtain p target requests, comprising:
if the n service types comprise p first preset types and n-p second preset types, acquiring a target request conversion processor corresponding to each first preset type;
and analyzing the service request to obtain target parameters corresponding to each first preset type through the target request conversion processor, and packaging the target parameters by adopting a parameter format corresponding to each first preset type to obtain p target requests.
3. The method of claim 2, wherein if the n service types include p first preset types and n-p second preset types, obtaining the target request conversion processor corresponding to each of the first preset types comprises:
if the n service types comprise p first preset types and n-p second preset types, acquiring a mapping relation of a request conversion processor;
determining identification information of a target request conversion processor corresponding to each first preset type from the mapping relation of the request conversion processors;
and acquiring the target request conversion processor corresponding to the identification information of the target request conversion processor from a target storage area corresponding to the gateway equipment.
4. The method of claim 3, wherein before parsing the service request and determining n request services included in the service request, the method further comprises:
acquiring a stored storage file from the target storage area;
selecting a target file in a target form from the storage files;
and generating the request conversion processor mapping relation based on the target file.
5. The method of claim 4, wherein generating the request translation processor mapping based on the target file comprises:
acquiring target identification information of each target file;
determining a storage path of each target file stored in the target storage area;
performing reflective loading based on each target identification information and the corresponding storage path to obtain each reference request conversion processor;
and generating the mapping relation of the request conversion processor based on each target identification information and the corresponding reference request conversion processor.
6. The method of claim 1, wherein before the sending each target request to the first service device associated with the first preset type, the method further comprises:
acquiring a Uniform Resource Identifier (URI) mapping relation;
determining equipment identification information for providing service for each first preset type from the URI mapping relation based on the p first preset types;
determining the first service device based on the device identification information.
7. The method of claim 6, wherein obtaining a Uniform Resource Identifier (URI) mapping comprises:
determining reference equipment identification information of at least one server side equipment controlled by gateway equipment; wherein, at least one of the service end devices comprises the first service device and the second service device;
determining at least one target device identification information providing a service other than the service of the second service type from among the at least one reference device identification information;
and generating the URI mapping relation based on at least one piece of target equipment identification information.
8. The method of claim 7, wherein generating the URI mapping based on the at least one piece of target device identification information comprises:
determining a target annotation corresponding to each piece of target equipment identification information;
obtaining target attributes from the target annotations;
and generating the URI mapping relation based on each target attribute and the corresponding target equipment identification information.
9. The method according to any one of claims 1 to 8, further comprising:
receiving a first service response sent by each first service device and a second service response sent by each second service device to obtain p first service responses and q second service responses; each first service response is a service response provided by the corresponding first service device for the received target request, and each second service response is a service response provided by the corresponding second service device for the received service request;
processing the p first service responses and the q second service responses to obtain target responses; wherein the target response is used for responding to the service request sent by the client device;
and sending the target response to the client device.
10. The method according to any one of claims 1 to 8, further comprising:
if the n service types are all first preset types, based on each service type, converting the service request to obtain n target requests;
sending each target request to a first service device having an association relation with the first preset type;
receiving a third service response sent by each first service device;
processing the third service response to obtain a target response;
and sending the target response to the client device.
11. A gateway device, characterized in that the device comprises a memory, a processor and a communication bus; wherein:
the memory to store executable instructions;
the communication bus is used for realizing communication connection between the processor and the memory;
the processor, configured to execute the micro-service request processing program stored in the memory, and implement the steps of the micro-service request processing method according to any one of claims 1 to 10.
12. A storage medium having stored thereon a micro-service request handling program which, when executed by a processor, implements the steps of the micro-service request handling method according to any one of claims 1 to 10.
CN202011463785.8A 2020-12-11 2020-12-11 Micro-service request processing method, equipment and storage medium Pending CN112637289A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011463785.8A CN112637289A (en) 2020-12-11 2020-12-11 Micro-service request processing method, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011463785.8A CN112637289A (en) 2020-12-11 2020-12-11 Micro-service request processing method, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN112637289A true CN112637289A (en) 2021-04-09

Family

ID=75312431

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011463785.8A Pending CN112637289A (en) 2020-12-11 2020-12-11 Micro-service request processing method, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112637289A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114338682A (en) * 2021-12-24 2022-04-12 北京字节跳动网络技术有限公司 Flow identity mark transmission method and device, electronic equipment and storage medium
CN115118569A (en) * 2022-06-29 2022-09-27 迈普通信技术股份有限公司 Request processing method and device, network management equipment and readable storage medium
CN115348209A (en) * 2022-10-18 2022-11-15 江西锦路科技开发有限公司 Flow control method and device of API (application program interface), electronic equipment and storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114338682A (en) * 2021-12-24 2022-04-12 北京字节跳动网络技术有限公司 Flow identity mark transmission method and device, electronic equipment and storage medium
CN115118569A (en) * 2022-06-29 2022-09-27 迈普通信技术股份有限公司 Request processing method and device, network management equipment and readable storage medium
CN115118569B (en) * 2022-06-29 2024-03-15 迈普通信技术股份有限公司 Request processing method, request processing device, network management equipment and readable storage medium
CN115348209A (en) * 2022-10-18 2022-11-15 江西锦路科技开发有限公司 Flow control method and device of API (application program interface), electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
US11394805B1 (en) Automatic discovery of API information
CN112637289A (en) Micro-service request processing method, equipment and storage medium
US8161468B2 (en) Processing of expressions
US8375043B2 (en) Techniques for providing XQuery access using web services
US20070016897A1 (en) Methods, apparatus and computer programs for optimized parsing and service invocation
US8719332B2 (en) Method and system for content categorization
CN104699718A (en) Method and device for rapidly introducing business data
JPH09218860A (en) Method for handling remote procedure calling in accordance with various kinds of protocols in client/ server system
KR20090040473A (en) Concatenation discovery web service
CN109327511B (en) Data request method and server based on HTTP (hyper text transport protocol)
CN108038213A (en) A kind of method of data processing, client, server and system
CN111654542B (en) Proxy server, execution server, reception device, and task execution method
CN110569036A (en) data verification system and method under front-end and back-end separation architecture
US10552411B2 (en) Email service adapter
US8819135B2 (en) Method of performing data mediation, and an associated computer program product, data mediation device and information system
JP4852906B2 (en) Cooperation processing system and apparatus
CN113986811A (en) High-performance kernel-mode network data packet acceleration method
CN115543479A (en) Interface calling analysis method and device suitable for dynamic parameters
US11258883B2 (en) Generic communication layer
US10623523B2 (en) Distributed communication and task handling to facilitate operations of application system
CN109688204B (en) File downloading method, node and terminal based on NDN (named data networking)
CN108809900B (en) Framework and method for unified resource access
EP1122644A1 (en) A method and system for dynamically dispatching function calls from a first execution environment to a second execution environment
JP5732926B2 (en) Remote procedure call processing method
US8799351B1 (en) Communicating multiple files in markup language documents

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