CN111049854B - Service request transmission method and device - Google Patents

Service request transmission method and device Download PDF

Info

Publication number
CN111049854B
CN111049854B CN201911357446.9A CN201911357446A CN111049854B CN 111049854 B CN111049854 B CN 111049854B CN 201911357446 A CN201911357446 A CN 201911357446A CN 111049854 B CN111049854 B CN 111049854B
Authority
CN
China
Prior art keywords
service
description information
interface description
instance address
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201911357446.9A
Other languages
Chinese (zh)
Other versions
CN111049854A (en
Inventor
龙武
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Weimin Insurance Agency Co Ltd
Original Assignee
Weimin Insurance Agency 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 Weimin Insurance Agency Co Ltd filed Critical Weimin Insurance Agency Co Ltd
Priority to CN201911357446.9A priority Critical patent/CN111049854B/en
Publication of CN111049854A publication Critical patent/CN111049854A/en
Application granted granted Critical
Publication of CN111049854B publication Critical patent/CN111049854B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/60Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
    • 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 application relates to a service request transmission method and a service request transmission device, wherein the method comprises the following steps: receiving a first service request transmitted by a front end through a first communication protocol, wherein the first service request is used for requesting to transmit data in a first format to a target service interface of a first service; inquiring service and interface description information with a corresponding relation to obtain target interface description information corresponding to the first service; converting the data in the first format into data in a second format using the target interface description information; and transmitting the data in the second format to a target service interface of the first service through a second communication protocol. The method and the device solve the technical problem that the transmission process of the service request in the related technology is high in complexity.

Description

Service request transmission method and device
Technical Field
The present application relates to the field of computers, and in particular, to a method and an apparatus for transmitting a service request.
Background
In the prior art, mapping relationships between request URLs (Uniform Resource locators) and service API (Application Programming Interface) gateway instances are configured through Nginx, and independent API gateways are configured for services of each product, so that service Interface protocol conversion is supported, and is implemented based on static code files generated by service Interface description files. And the API gateway corresponding to each product service realizes protocol conversion based on the interface description file of the service, and the API gateway and the service are not decoupled on the protocol conversion level. If the interface of the service is changed, the API gateway needs to be synchronously modified. Each time the service interface is changed, the update service and the API gateway are required to be issued, the issuing processes of the update service and the API gateway are difficult to synchronize, the service interface change is required to be compatible with an old protocol, and the maintenance difficulty of product service is increased.
In view of the above problems, no effective solution has been proposed.
Disclosure of Invention
The application provides a service request transmission method and device, which are used for at least solving the technical problem of high complexity of a service request transmission process in the related technology.
According to an aspect of an embodiment of the present application, there is provided a method for transmitting a service request, including:
receiving a first service request transmitted by a front end through a first communication protocol, wherein the first service request is used for requesting to transmit data in a first format to a target service interface of a first service;
inquiring service and interface description information with a corresponding relation to obtain target interface description information corresponding to the first service;
converting the data in the first format into data in a second format using the target interface description information;
and transmitting the data in the second format to the target service interface of the first service through a second communication protocol.
According to another aspect of the embodiments of the present application, there is also provided a transmission apparatus for a service request, including:
the system comprises a receiving module, a sending module and a receiving module, wherein the receiving module is used for receiving a first service request which is sent by a front end and is transmitted through a first communication protocol, and the first service request is used for requesting to transmit data in a first format to a target service interface of a first service;
the query module is used for querying the service and the interface description information with the corresponding relation to obtain the target interface description information corresponding to the first service;
a conversion module, configured to convert the data in the first format into data in a second format using the target interface description information;
and the transmission module is used for transmitting the data in the second format to the target service interface of the first service through a second communication protocol.
Optionally, the query module includes:
the searching unit is used for searching the first service from the cached service and interface description information with the corresponding relation;
the query unit is configured to query, when the first service is not found, the interface description information corresponding to the first service, and receive the target interface description information corresponding to the first service returned by the first service;
a first obtaining unit, configured to obtain, when the first service is found, the target interface description information corresponding to the first service from the service and interface description information having a correspondence relationship.
Optionally, the querying unit is configured to:
acquiring a first service instance address from a service instance address list corresponding to the first service;
sending a query request to the first service instance address, wherein the query request is used for requesting to query interface description information corresponding to the first service;
and receiving a query response returned by the first service instance address, wherein the query response is used for indicating that the first service corresponds to the target interface description information.
Optionally, the apparatus further comprises:
the cache module is configured to cache the first service and the target interface description information having a corresponding relationship in service and interface description information having a corresponding relationship after receiving the target interface description information corresponding to the first service returned by the first service.
Optionally, the transmission module includes:
the second acquisition unit is used for acquiring a first service instance address list corresponding to the first service from the service and service instance address list with the corresponding relation;
a third obtaining unit, configured to obtain a second service instance address from the first service instance address list;
a constructing unit, configured to construct a second service request based on the second communication protocol, where the second service request is used to request transmission of the data in the second format to the target service interface;
a transmission unit, configured to transmit the second service request to the second service instance address.
Optionally, the apparatus further comprises:
a first obtaining module, configured to obtain service instance address update information of a second service before obtaining a first service instance address list corresponding to a first service from a service and service instance address list having a corresponding relationship, where the service instance address update information is used to indicate that a second service instance address list corresponding to the second service is updated to a third service instance address list;
a first updating module, configured to update the second service and the second service instance address list having a correspondence relationship in the service and service instance address lists having a correspondence relationship into the second service and the third service instance address list having a correspondence relationship.
Optionally, the apparatus further comprises:
a second obtaining module, configured to obtain, at target time intervals, a service instance address list corresponding to one or more services included in service and interface description information having a correspondence relationship before querying the service and interface description information having the correspondence relationship;
the access module is used for sequentially accessing each service instance address in a service instance address list corresponding to each service in the one or more services;
and the second updating module is used for updating the service and interface description information with the corresponding relation by using the service interface description updating information under the condition of acquiring the service interface description updating information of the target service instance address.
According to another aspect of the embodiments of the present application, there is also provided a storage medium including a stored program which, when executed, performs the above-described method.
According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the above method through the computer program.
In the embodiment of the application, a first service request which is sent by a receiving front end and is transmitted through a first communication protocol is adopted, wherein the first service request is used for requesting to transmit data in a first format to a target service interface of a first service; inquiring service and interface description information with a corresponding relation to obtain target interface description information corresponding to the first service; converting the data in the first format into data in a second format using the target interface description information; the method comprises the steps of transmitting data in a second format to a target service interface of a first service through a second communication protocol, dynamically updating target interface description information corresponding to the first service through query of the interface description information, performing data conversion and transmission by using the dynamically acquired target interface description information, and unifying API gateways of various product services without updating the API gateways if the interface of the service is changed, thereby greatly reducing development and maintenance costs of the product services, facilitating development and function optimization of new characteristics, and facilitating unified management of gateway flow, thereby realizing the technical effect of reducing the complexity of the transmission process of service requests, and further solving the technical problem of higher complexity of the transmission process of the service requests in the related technology.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention.
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without inventive exercise.
Fig. 1 is a schematic diagram of a hardware environment of a transmission method of a service request according to an embodiment of the present application;
fig. 2 is a flow chart of an alternative service request transmission method according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a bidirectional flow RPC according to an embodiment of the present application;
FIG. 4 is a schematic diagram of a flow of an API gateway processing a service request of a front end in accordance with an alternative embodiment of the present application;
FIG. 5 is a schematic diagram of a service discovery process according to this alternative embodiment;
FIG. 6 is a schematic diagram of a timing synchronization service interface description information procedure in accordance with the alternative embodiment;
fig. 7 is a schematic diagram of a gRPC based micro service architecture API gateway protocol conversion system in accordance with an alternative embodiment of the present application;
fig. 8 is a schematic diagram of an alternative transmission device for a service request according to an embodiment of the present application;
and
fig. 9 is a block diagram of a terminal according to an embodiment of the present application.
Detailed Description
In order to make the technical solutions better understood by those skilled in the art, 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, and it is obvious that the described embodiments are only partial embodiments of the present application, but not all embodiments. 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 application.
It should be noted that the terms "first," "second," and the like in the description and claims of this application and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the application described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
According to an aspect of embodiments of the present application, an embodiment of a method for transmission of a service request is provided.
Alternatively, in this embodiment, the transmission method of the service request may be applied to a hardware environment formed by the front end 101, the access stratum 103 and the micro service 105 as shown in fig. 1. As shown in FIG. 1, the front end 101 may include, but is not limited to, an applet client, an APP client, a web client, and so on, the access layer 103 may include, but is not limited to, an API gateway cluster server, and the microservice 105 may include, but is not limited to, a server for a product 1 business service, a server for a product 2 business service, and a server for a product 3 business service. The transmission method of the service request according to the embodiment of the present application may be executed by an API gateway cluster server of the access layer 103. The front end is based on an HTTP protocol and transmits JSON format data; the micro-services at the back end are transmitted based on a gPRC protocol and Protobuf format data; the API gateway cluster is used as a uniform entrance for front-end access and back-end access, supports dynamic update of service interface description information, and realizes conversion between different protocols. Meanwhile, the API gateway cluster can also integrate the main functions of a reverse proxy server (such as an Nginx cluster), reduce the length of a request calling chain at the front end and reduce the response delay of the request.
Fig. 2 is a flowchart of an alternative service request transmission method according to an embodiment of the present application, and as shown in fig. 2, the method may include the following steps:
step S202, receiving a first service request transmitted by a front end through a first communication protocol, wherein the first service request is used for requesting to transmit data in a first format to a target service interface of a first service;
step S204, inquiring service and interface description information with corresponding relation to obtain target interface description information corresponding to the first service;
step S206, converting the data in the first format into data in a second format by using the target interface description information;
step S208, the data in the second format is transmitted to the target service interface of the first service through a second communication protocol.
Optionally, in this embodiment, the service may refer to, but is not limited to, a function provided to a caller for calling, such as: the system comprises a game function, a shopping function, a live broadcast function, an audio and video playing function, a picture storing and browsing function, a financing function, a web page browsing function and the like.
Optionally, in this embodiment, the target interface description information includes: the interface name of the target interface, the list of request parameter fields of the target interface (including the field name and type of the request parameters, etc.), and the list of response parameter fields of the target interface (including the field name and type of the response parameters, etc.).
Through the steps S202 to S208, the target interface description information corresponding to the first service is dynamically updated through the query of the interface description information, data conversion and transmission are performed using the dynamically obtained target interface description information, if the interface of the service is changed, the API gateway does not need to be updated, and the API gateways of the product services are also unified, so that the development and maintenance costs of the product services are greatly reduced, development of new characteristics and function optimization can be facilitated, and unified management of gateway traffic is facilitated, thereby achieving the technical effect of reducing the complexity of the transmission process of the service request, and further solving the technical problem of higher complexity of the transmission process of the service request in the related art.
Optionally, in this embodiment, the transmission method of the service request may be, but is not limited to, applied to a scenario where the front-end access and the back-end access use different protocols to transmit data in different formats. The first service request sent during front-end access transmits data in a first format through a first communication protocol. And when the data are transmitted to the back-end for access, the data in the second format are transmitted through a second communication protocol.
Optionally, in this embodiment, the transmission method of the service request may be, but is not limited to, applied to an API gateway cluster server in the intervening layer.
In the technical solution provided in step S202, the first communication Protocol may include, but is not limited to, an HTTP Protocol (HyperText Transfer Protocol). The first format may include, but is not limited to, a JSON format (JavaScript Object Notation).
In the technical solution provided in step S204, the manner of querying the description information of the target interface may include, but is not limited to, querying the first service, or querying a local cache, or first searching in the local cache, and if not, requesting the first service.
In the technical solution provided in step S206, the second format may include, but is not limited to, a Protocol buffer (Protocol Buffers).
In the technical solution provided in step S208, the second communication protocol may include, but is not limited to, a gRPC protocol. RPC is an abbreviated form of Remote Procedure Call (Remote Procedure Call). The gPC protocol is a data transmission protocol designed based on the HTTP/2 protocol standard and developed based on the Protobuf serialization protocol.
Optionally, in this embodiment, the gRPC protocol may be, but is not limited to, a bidirectional streaming RPC (bidirectional streaming RPC), fig. 3 is a schematic diagram of the bidirectional streaming RPC according to an embodiment of the present application, and as shown in fig. 3, the client and the server may send or receive streams to each other independently. The order of sending or receiving by the client and the server is arbitrary.
As an optional embodiment, querying service and interface description information having a corresponding relationship, and obtaining target interface description information corresponding to the first service includes:
s11, searching the first service from the cached service and interface description information with the corresponding relation;
s12, when the first service is not found, querying the first service for interface description information corresponding to the first service, and receiving the target interface description information corresponding to the first service returned by the first service;
s13, when the first service is found, obtaining the target interface description information corresponding to the first service from the service and interface description information having the corresponding relationship.
Optionally, in this embodiment, the API gateway cluster may cache the service and the interface description information having the corresponding relationship to improve the query efficiency, and after receiving the first service request, the API gateway cluster may first search in a local cache, and if not, query the first service.
Optionally, in this embodiment, each service may, but is not limited to, perform serverrefelectionfo interface registration to provide a query function of service interface description information, all micro services open a listening port and start a process of the service, and the serverrefelectionfo interface may be registered as a bidirectional stream interface based on a gRPC protocol and provided to the API gateway to query the service interface description information. The ServerReflectionInfo interface may be defined by, but is not limited to:
service Server selection rpc Server selection Info (stream Server selection request)% service interface metadata request interface information (service interface metadata request interface request data stream)
return (stream serverreflectionresponse); % return service interface metadata request interface response data stream
}
As an optional embodiment, querying the first service for interface description information corresponding to the first service, and receiving the target interface description information corresponding to the first service returned by the first service includes:
s21, obtaining a first service instance address from the service instance address list corresponding to the first service;
s22, sending an inquiry request to the first service instance address, wherein the inquiry request is used for requesting to inquire the interface description information corresponding to the first service;
s23, receiving a query response returned by the first service instance address, wherein the query response is used for indicating that the first service corresponds to the target interface description information.
Optionally, in this embodiment, the API gateway cluster may obtain, but is not limited to, interface description information corresponding to the service by sending a query request to a certain service instance address of the service. In the above step S21, the available first service instance address may be obtained, but is not limited to, by using a load balancing polling algorithm.
As an optional embodiment, after receiving the target interface description information corresponding to the first service returned by the first service, the method further includes:
s31, caching the first service and the target interface description information with the corresponding relation into the service and the interface description information with the corresponding relation.
Optionally, in this embodiment, the API gateway cluster may but is not limited to cache the acquired first service and the target interface description information having the corresponding relationship locally, and then may directly acquire the target interface description information corresponding to the first service from the local cache when a request for accessing the first service is received next time, so as to save time and improve efficiency.
Through the process, the API gateway cluster caches the interface description information of the service, so that the response speed of the API gateway cluster for processing the service request can be improved.
As an alternative embodiment, the step of transmitting the data in the second format to the target service interface of the first service via a second communication protocol includes:
s41, acquiring a first service instance address list corresponding to the first service from the service and service instance address list with the corresponding relation;
s42, acquiring a second service instance address from the first service instance address list;
s43, constructing a second service request based on the second communication protocol, wherein the second service request is used for requesting to transmit the data in the second format to the target service interface;
s44, transmitting the second service request to the second service instance address.
Optionally, in this embodiment, after the protocol conversion is completed, the API gateway cluster may select, but is not limited to, to serve an available second service instance address based on a load balancing algorithm, construct a second service request based on the gRPC protocol and carrying request data in the Protobuf format, and forward the second service request to the second service instance address.
Optionally, in this embodiment, a series of service instance addresses provided by the first service are recorded in the first service instance address list, and the second service instance address is a service instance address used for forwarding the second service request, where the service instance address is selected from the series of service instance addresses provided by the first service.
Through the process, the unified gateway access layer is adopted to carry out scheduling of the service request, conversion of the request data and forwarding of the service request, and the main functions of the reverse proxy server are integrated in the gateway access layer, so that the length of a request call chain can be reduced, and the request response time is shortened.
In an alternative embodiment, a flow of processing a service request of a front end by an API gateway is provided, and fig. 4 is a schematic diagram of a flow of processing a service request of a front end by an API gateway according to an alternative embodiment of the present application, as shown in fig. 4, the flow includes the following steps:
step S402, request data in http + json format is received.
Step S404, the service name and the service interface name are obtained through analysis.
Step S406, querying the local cache to obtain the service interface description information.
Step S408, determining whether the cache exists, if not, executing step S410, and if so, executing step S416.
Step S410, query the local cache to obtain the service instance address list.
Step S412, the service instance address is accessed to inquire the interface description information.
Step S414, update the local cache.
In step S416, interface description information is acquired.
Step S418, perform data format conversion through data serialization processing, and convert the JSON format into the Protobuf format.
In step S420, an available instance address of the service is obtained.
Step S422, calling a service interface based on Protobuf format data.
Step S424 deserializes the response data to obtain response data in the JSON format.
Step S426, sending the response data in the JSON format to the front end.
As an optional embodiment, before obtaining the first service instance address list corresponding to the first service from the service and service instance address lists having the corresponding relationship, the method further includes:
s51, obtaining service instance address updating information of a second service, wherein the service instance address updating information is used for indicating that a second service instance address list corresponding to the second service is updated to a third service instance address list;
s52, updating the second service and the second service instance address list having a corresponding relationship in the service and service instance address list having a corresponding relationship into the second service and the third service instance address list having a corresponding relationship.
Optionally, in this embodiment, the service instance address list corresponding to the service cached in the API gateway cluster may be updated in real time.
Optionally, in this embodiment, a service registry may be constructed, which is a bridge for contacting service providers and service consumers, maintaining the latest network locations of service provider instances, and maintaining service registration information, such as etcd, consul, zookeeper, etc., using a distributed, consistent key-value store system.
Through the process, the service interface description information can be dynamically updated, and if the service interface is changed, the API gateway cluster does not need to be updated. The development and maintenance cost of product service is greatly reduced, and the service updating time is also saved, so that the service development and maintenance efficiency is improved.
In an alternative embodiment, a service discovery process is provided, and fig. 5 is a schematic diagram of a service discovery process according to the alternative embodiment, and as shown in fig. 5, the process may include the following steps:
step S502, obtain the list of dependent services.
Step S504, the change events of the service subscription service of the service registry are accessed in sequence.
Step S506, acquiring the update information of the service to determine whether the service is online or offline.
Step S508, the service instance address list in the local cache is updated.
As an optional embodiment, before querying service and interface description information having a corresponding relationship, the method further includes:
s61, obtaining service instance address lists corresponding to one or more services included in the service and interface description information with corresponding relationship at target time intervals;
s62, sequentially accessing each service instance address in the service instance address list corresponding to each service in the one or more services;
and S63, under the condition that the service interface description updating information of the target service instance address is obtained, the service interface description updating information is used for updating the service and interface description information with the corresponding relation.
Optionally, in this embodiment, the interface description information corresponding to the service cached in the API gateway cluster may be updated synchronously at regular time.
Through the process, the interface description information of the service can be cached in the API gateway cluster, the speed of request response is improved, the effectiveness of the cache can be improved by updating the cache at regular time, and therefore the operation performance of the API gateway is improved.
In an alternative embodiment, a procedure of timing synchronization service interface description information is provided, and fig. 6 is a schematic diagram of a procedure of timing synchronization service interface description information according to the alternative embodiment, as shown in fig. 6, the procedure may include the following steps:
step S602, obtains a dependent service list.
Step S604, an instance address list of a certain service is acquired.
Step S606, sequentially accessing the service instance to obtain the service interface description information.
Step S608, update the service interface description information in the local cache, and return to step S604 until all dependent services are traversed.
In step S610, the user sleeps for 30 seconds to re-execute step S602 for timing synchronization.
The present application further provides an alternative embodiment, which provides a gRPC-based micro service architecture API gateway protocol conversion system, and fig. 7 is a schematic diagram of the gRPC-based micro service architecture API gateway protocol conversion system according to the alternative embodiment of the present application, and as shown in fig. 7, the system includes: the API gateway protocol conversion system adopts a micro-service architecture of bidirectional stream RPC, the client and the server can independently send or receive streams to each other, and the sending or receiving sequence of the client and the server is arbitrary. The implementation mode of each module in the system is as follows:
the service registry is a bridge that connects service providers and service consumers to maintain the latest network location of service provider instances, and a distributed, consistent key-value store system may be used to maintain service registration information, such as etcd, consul, zookeeper, etc.
The service registration function comprises that the service instance calls a registration interface of the service registry to register an instance address, and the service instance can also call a heartbeat interface of the service registry periodically to prevent the registration information of the service instance from being out of date.
The service discovery function comprises that when the front end accesses the target service, the API gateway accesses the service registry according to the service name to obtain a service instance address list. To improve performance, the API gateway caches the service instance address list and monitors and synchronizes the service instance address list of the service registry in real-time.
The ServerReflectionInfo interface registration function comprises a process that all micro-services open monitoring ports and start services, and can register ServerReflectionInfo interfaces and provide the functions for an API gateway to inquire the description information of the service interfaces.
The service interface description information timing synchronous updating and local cache maintaining functions comprise that an API gateway analyzes a front end request URL to obtain a target service name, inquires a local cache to obtain a service instance address list, constructs a ServerReflectionInfo interface request, inquires and obtains the interface description information of the target service, and updates the local cache. In order to ensure the compatibility of the new interface and the old interface in the service updating process, the interface description information returned by the service can maintain a version number, and meanwhile, the API gateway can maintain the corresponding interface description information aiming at different instances of the service. In order to meet the condition that the address list of the service instance cached by the API gateway is inconsistent with the actual condition caused by the abnormal on-line and off-line of the compatible service, the API gateway can synchronize the interface description information of the service at regular time.
The protocol conversion process comprises the steps that the API gateway locally caches and maintains the latest interface description information of the service, and when a request of the front end based on the HTTP protocol and JSON format data is received, the API gateway converts the JSON format data into Protobuf format data based on the interface description information of the service.
After the protocol conversion is completed, the API gateway selects an available instance address for service based on a load balancing algorithm, constructs request data based on a gRPC protocol and in a Protobuf format, and forwards the request data to a target service instance.
It should be noted that, for simplicity of description, the above-mentioned method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present application is not limited by the order of acts described, as some steps may occur in other orders or concurrently depending on the application. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required in this application.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present application.
According to another aspect of the embodiments of the present application, there is also provided a service request transmission apparatus for implementing the service request transmission method. Fig. 8 is a schematic diagram of an alternative service request transmission apparatus according to an embodiment of the present application, and as shown in fig. 8, the apparatus may include:
a receiving module 82, configured to receive a first service request transmitted through a first communication protocol and sent by a front end, where the first service request is used to request to transmit data in a first format to a target service interface of a first service;
the query module 84 is configured to query the service and the interface description information having the corresponding relationship, so as to obtain target interface description information corresponding to the first service;
a conversion module 86, configured to convert the data in the first format into data in a second format using the target interface description information;
a transmission module 88, configured to transmit the data in the second format to the target service interface of the first service through a second communication protocol.
It should be noted that the receiving module 82 in this embodiment may be configured to execute the step S202 in this embodiment, the querying module 84 in this embodiment may be configured to execute the step S204 in this embodiment, the converting module 86 in this embodiment may be configured to execute the step S206 in this embodiment, and the transmitting module 88 in this embodiment may be configured to execute the step S208 in this embodiment.
It should be noted here that the modules described above are the same as the examples and application scenarios implemented by the corresponding steps, but are not limited to the disclosure of the above embodiments. It should be noted that the modules described above as a part of the apparatus may operate in a hardware environment as shown in fig. 1, and may be implemented by software or hardware.
Through the module, the target interface description information corresponding to the first service is dynamically updated through the inquiry of the interface description information, the dynamically acquired target interface description information is used for data conversion and transmission, if the interface of the service is changed, the API gateway does not need to be updated, the API gateway of each product service is unified, the development and maintenance cost of the product service is greatly reduced, the development and function optimization of new characteristics can be facilitated, the unified management of gateway flow is facilitated, the technical effect of reducing the complexity of the transmission process of the service request is achieved, and the technical problem of high complexity of the transmission process of the service request in the related technology is solved.
Optionally, the query module includes:
the searching unit is used for searching the first service from the cached service and interface description information with the corresponding relation;
the query unit is configured to query, when the first service is not found, the interface description information corresponding to the first service, and receive the target interface description information corresponding to the first service returned by the first service;
a first obtaining unit, configured to obtain, when the first service is found, the target interface description information corresponding to the first service from the service and interface description information having a correspondence relationship.
Optionally, the querying unit is configured to:
acquiring a first service instance address from a service instance address list corresponding to the first service;
sending a query request to the first service instance address, wherein the query request is used for requesting to query interface description information corresponding to the first service;
and receiving a query response returned by the first service instance address, wherein the query response is used for indicating that the first service corresponds to the target interface description information.
Optionally, the apparatus further comprises:
the cache module is configured to cache the first service and the target interface description information having a corresponding relationship in service and interface description information having a corresponding relationship after receiving the target interface description information corresponding to the first service returned by the first service.
Optionally, the transmission module includes:
the second acquisition unit is used for acquiring a first service instance address list corresponding to the first service from the service and service instance address list with the corresponding relation;
a third obtaining unit, configured to obtain a second service instance address from the first service instance address list;
a constructing unit, configured to construct a second service request based on the second communication protocol, where the second service request is used to request transmission of the data in the second format to the target service interface;
a transmission unit, configured to transmit the second service request to the second service instance address.
Optionally, the apparatus further comprises:
a first obtaining module, configured to obtain service instance address update information of a second service before obtaining a first service instance address list corresponding to a first service from a service and service instance address list having a corresponding relationship, where the service instance address update information is used to indicate that a second service instance address list corresponding to the second service is updated to a third service instance address list;
a first updating module, configured to update the second service and the second service instance address list having a correspondence relationship in the service and service instance address lists having a correspondence relationship into the second service and the third service instance address list having a correspondence relationship.
Optionally, the apparatus further comprises:
a second obtaining module, configured to obtain, at target time intervals, a service instance address list corresponding to one or more services included in service and interface description information having a correspondence relationship before querying the service and interface description information having the correspondence relationship;
the access module is used for sequentially accessing each service instance address in a service instance address list corresponding to each service in the one or more services;
and the second updating module is used for updating the service and interface description information with the corresponding relation by using the service interface description updating information under the condition of acquiring the service interface description updating information of the target service instance address.
It should be noted here that the modules described above are the same as the examples and application scenarios implemented by the corresponding steps, but are not limited to the disclosure of the above embodiments. It should be noted that the modules described above as a part of the apparatus may be operated in a hardware environment as shown in fig. 1, and may be implemented by software, or may be implemented by hardware, where the hardware environment includes a network environment.
According to another aspect of the embodiment of the present application, there is also provided a server or a terminal for implementing the transmission method of the service request.
Fig. 9 is a block diagram of a terminal according to an embodiment of the present application, and as shown in fig. 9, the terminal may include: one or more processors 901 (only one of which is shown), a memory 903, and a transmitting device 905, as shown in fig. 9, the terminal may further include an input/output device 907.
The memory 903 may be used to store software programs and modules, such as program instructions/modules corresponding to the service request transmission method and apparatus in the embodiment of the present application, and the processor 901 executes various functional applications and data processing by running the software programs and modules stored in the memory 903, that is, implementing the service request transmission method described above. The memory 903 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 903 may further include memory located remotely from the processor 901, which may be connected to the terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The above-mentioned transmission device 905 is used for receiving or sending data via a network, and can also be used for data transmission between a processor and a memory. Examples of the network may include a wired network and a wireless network. In one example, the transmission device 905 includes a Network adapter (NIC) that can be connected to a router via a Network cable and other Network devices so as to communicate with the internet or a local area Network. In one example, the transmission device 905 is a Radio Frequency (RF) module, which is used for communicating with the internet in a wireless manner.
The memory 903 is used for storing, among other things, application programs.
The processor 901 may call an application stored in the memory 903 through the transmission device 905 to perform the following steps:
s1, receiving a first service request transmitted by a front end via a first communication protocol, where the first service request is used to request a target service interface of a first service to transmit data in a first format;
s2, inquiring service and interface description information with corresponding relation to obtain target interface description information corresponding to the first service;
s3, converting the data in the first format into the data in the second format by using the target interface description information;
s4, transmitting the data in the second format to the target service interface of the first service through a second communication protocol.
By adopting the embodiment of the application, a scheme for transmitting the service request is provided. The target interface description information corresponding to the first service is dynamically updated through the query of the interface description information, the dynamically acquired target interface description information is used for data conversion and transmission, if the interface of the service is changed, the API gateway does not need to be updated, the API gateways of all product services are unified, the development and maintenance cost of the product services is greatly reduced, the development of new characteristics and the function optimization can be facilitated, the unified management of gateway flow is facilitated, the technical effect of reducing the complexity of the transmission process of the service request is achieved, and the technical problem that the complexity of the transmission process of the service request is higher in the related technology is solved.
Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment is not described herein again.
It can be understood by those skilled in the art that the structure shown in fig. 9 is only an illustration, and the terminal may be a terminal device such as a smart phone (e.g., an Android phone, an iOS phone, etc.), a tablet computer, a palm computer, and a Mobile Internet Device (MID), a PAD, etc. Fig. 9 is a diagram illustrating a structure of the electronic device. For example, the terminal may also include more or fewer components (e.g., network interfaces, display devices, etc.) than shown in FIG. 9, or have a different configuration than shown in FIG. 9.
Those skilled in the art will appreciate that all or part of the steps in the methods of the above embodiments may be implemented by a program instructing hardware associated with the terminal device, where the program may be stored in a computer-readable storage medium, and the storage medium may include: flash disks, Read-Only memories (ROMs), Random Access Memories (RAMs), magnetic or optical disks, and the like.
Embodiments of the present application also provide a storage medium. Alternatively, in this embodiment, the storage medium may be used to execute a program code of a transmission method of a service request.
Optionally, in this embodiment, the storage medium may be located on at least one of a plurality of network devices in a network shown in the above embodiment.
Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps:
s1, receiving a first service request transmitted by a front end via a first communication protocol, where the first service request is used to request a target service interface of a first service to transmit data in a first format;
s2, inquiring service and interface description information with corresponding relation to obtain target interface description information corresponding to the first service;
s3, converting the data in the first format into the data in the second format by using the target interface description information;
s4, transmitting the data in the second format to the target service interface of the first service through a second communication protocol.
Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment is not described herein again.
Optionally, in this embodiment, the storage medium may include, but is not limited to: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
The above-mentioned serial numbers of the embodiments of the present application are merely for description and do not represent the merits of the embodiments.
The integrated unit in the above embodiments, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in the above computer-readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or a part of or all or part of the technical solution contributing to the prior art may be embodied in the form of a software product stored in a storage medium, and including instructions for causing one or more computer devices (which may be personal computers, servers, network devices, or the like) to execute all or part of the steps of the method described in the embodiments of the present application.
In the above embodiments of the present application, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the several embodiments provided in the present application, it should be understood that the disclosed client may be implemented in other manners. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one type of division of logical functions, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
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 units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The foregoing is only a preferred embodiment of the present application and it should be noted that those skilled in the art can make several improvements and modifications without departing from the principle of the present application, and these improvements and modifications should also be considered as the protection scope of the present application.

Claims (9)

1. A method for transmitting a service request, comprising:
receiving a first service request transmitted by a front end through a first communication protocol, wherein the first service request is used for requesting to transmit data in a first format to a target service interface of a first service;
acquiring a service instance address list corresponding to one or more services included in service and interface description information with corresponding relations at intervals of a target time;
sequentially accessing each service instance address in a service instance address list corresponding to each service in the one or more services;
under the condition of acquiring service interface description updating information of a target service instance address, updating service and interface description information with corresponding relation by using the service interface description updating information;
inquiring service and interface description information with a corresponding relation to obtain target interface description information corresponding to the first service;
converting the data in the first format into data in a second format using the target interface description information;
and transmitting the data in the second format to the target service interface of the first service through a second communication protocol.
2. The method of claim 1, wherein querying service and interface description information having a corresponding relationship to obtain target interface description information corresponding to the first service comprises:
searching the first service from the cached service and interface description information with the corresponding relation;
under the condition that the first service is not found, inquiring the interface description information corresponding to the first service from the first service, and receiving the target interface description information corresponding to the first service returned by the first service;
and under the condition that the first service is found, acquiring the target interface description information corresponding to the first service from the service and interface description information with the corresponding relation.
3. The method of claim 2, wherein querying the first service for interface description information corresponding to the first service, and receiving the target interface description information corresponding to the first service returned by the first service comprises:
acquiring a first service instance address from a service instance address list corresponding to the first service;
sending a query request to the first service instance address, wherein the query request is used for requesting to query interface description information corresponding to the first service;
and receiving a query response returned by the first service instance address, wherein the query response is used for indicating that the first service corresponds to the target interface description information.
4. The method of claim 2, wherein after receiving the target interface description information corresponding to the first service returned by the first service, the method further comprises:
caching the first service and the target interface description information with the corresponding relation into the service and interface description information with the corresponding relation.
5. The method of claim 1, wherein transmitting the data in the second format to the target service interface of the first service via a second communication protocol comprises:
acquiring a first service instance address list corresponding to the first service from a service and service instance address list with a corresponding relation;
acquiring a second service instance address from the first service instance address list;
constructing a second service request based on the second communication protocol, wherein the second service request is used for requesting to transmit the data in the second format to the target service interface;
transmitting the second service request to the second service instance address.
6. The method of claim 5, wherein before obtaining the first service instance address list corresponding to the first service from the service and service instance address lists having a corresponding relationship, the method further comprises:
acquiring service instance address updating information of a second service, wherein the service instance address updating information is used for indicating that a second service instance address list corresponding to the second service is updated to be a third service instance address list;
updating the second service and the second service instance address list with the corresponding relation in the service and service instance address list with the corresponding relation into the second service and the third service instance address list with the corresponding relation.
7. An apparatus for transmitting a service request, comprising:
the system comprises a receiving module, a sending module and a receiving module, wherein the receiving module is used for receiving a first service request which is sent by a front end and is transmitted through a first communication protocol, and the first service request is used for requesting to transmit data in a first format to a target service interface of a first service;
a second obtaining module, configured to obtain, at each target time interval, a service instance address list corresponding to one or more services included in the service and interface description information having a correspondence relationship;
the access module is used for sequentially accessing each service instance address in a service instance address list corresponding to each service in the one or more services;
the second updating module is used for updating the service and interface description information with the corresponding relation by using the service interface description updating information under the condition of acquiring the service interface description updating information of the target service instance address;
the query module is used for querying the service and the interface description information with the corresponding relation to obtain the target interface description information corresponding to the first service;
a conversion module, configured to convert the data in the first format into data in a second format using the target interface description information;
and the transmission module is used for transmitting the data in the second format to the target service interface of the first service through a second communication protocol.
8. A storage medium, characterized in that the storage medium comprises a stored program, wherein the program when executed performs the method of any of the preceding claims 1 to 6.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor executes the method of any of the preceding claims 1 to 6 by means of the computer program.
CN201911357446.9A 2019-12-25 2019-12-25 Service request transmission method and device Active CN111049854B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911357446.9A CN111049854B (en) 2019-12-25 2019-12-25 Service request transmission method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911357446.9A CN111049854B (en) 2019-12-25 2019-12-25 Service request transmission method and device

Publications (2)

Publication Number Publication Date
CN111049854A CN111049854A (en) 2020-04-21
CN111049854B true CN111049854B (en) 2021-12-14

Family

ID=70239636

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911357446.9A Active CN111049854B (en) 2019-12-25 2019-12-25 Service request transmission method and device

Country Status (1)

Country Link
CN (1) CN111049854B (en)

Families Citing this family (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113709085A (en) * 2020-05-22 2021-11-26 成都鼎桥通信技术有限公司 Remote procedure call processing method, device and equipment
CN111600909B (en) * 2020-06-24 2023-06-23 腾讯科技(深圳)有限公司 Data processing method, device, protocol conversion equipment and storage medium
CN111722947A (en) * 2020-06-28 2020-09-29 深圳壹账通智能科技有限公司 Service calling method and system
CN112153071B (en) * 2020-09-30 2023-03-17 深圳市腾讯计算机系统有限公司 Message sending method, device, gateway and storage medium
CN112422565B (en) * 2020-11-18 2023-02-03 青岛海尔科技有限公司 Message processing method and device, storage medium and electronic device
CN112948723A (en) * 2021-02-26 2021-06-11 平安普惠企业管理有限公司 Interface calling method and device and related equipment
CN113110896A (en) * 2021-03-31 2021-07-13 青岛海尔科技有限公司 Data calling method and device, storage medium and electronic device
CN113938531B (en) * 2021-09-23 2023-10-31 北京车和家信息技术有限公司 Data transmission method, device, equipment and medium
CN113992641A (en) * 2021-10-11 2022-01-28 北京达佳互联信息技术有限公司 Data processing method, device, equipment and storage medium
CN114221995B (en) * 2021-11-11 2024-04-09 中国建设银行股份有限公司 Service calling method and device and electronic equipment
CN113821363B (en) * 2021-11-25 2022-03-01 北京鲸鲮信息系统技术有限公司 Inter-process communication method and system
CN114389988A (en) * 2022-01-13 2022-04-22 平安付科技服务有限公司 Remote procedure call method, device, equipment and medium based on network architecture
CN114401311A (en) * 2022-01-19 2022-04-26 阿维塔科技(重庆)有限公司 Microservice registration and discovery method, microservice registration and discovery device, electronic equipment and medium
CN114615321B (en) * 2022-03-25 2024-03-12 度小满科技(北京)有限公司 Flow processing method and device
CN114979295A (en) * 2022-05-19 2022-08-30 京东城市(北京)数字科技有限公司 Gateway management method and device

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103095479A (en) * 2011-11-04 2013-05-08 华为技术有限公司 Method and device of business configuration
CN105335310A (en) * 2014-06-05 2016-02-17 阿里巴巴集团控股有限公司 Interface defining method, and data transmission method and apparatus
US9565246B1 (en) * 2012-03-14 2017-02-07 Comindware Ltd. System and method for project and process management by synchronizing custom objects between an application and external server
CN106453288A (en) * 2016-09-29 2017-02-22 上海和付信息技术有限公司 Asynchronous mode supporting distributed micro service framework system and implementation method thereof
CN108901022A (en) * 2018-06-28 2018-11-27 深圳云之家网络有限公司 A kind of micro services universal retrieval method and gateway
CN108989356A (en) * 2018-09-10 2018-12-11 四川长虹电器股份有限公司 A kind of method that API gateway realizes protocol conversion
CN109246251A (en) * 2018-11-13 2019-01-18 杭州数梦工场科技有限公司 A kind of micro services call method, device, system, equipment and readable storage medium storing program for executing
CN109445968A (en) * 2018-11-09 2019-03-08 金瓜子科技发展(北京)有限公司 Service request processing method, device, equipment and the storage medium of different agreement
CN109582472A (en) * 2018-10-19 2019-04-05 华为技术有限公司 A kind of micro services processing method and equipment
CN110300056A (en) * 2019-06-28 2019-10-01 四川长虹电器股份有限公司 A kind of real-time response formula API gateway and its request processing method

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP2973051A4 (en) * 2013-03-15 2016-11-16 Amazon Tech Inc Scalable analysis platform for semi-structured data
US10503568B2 (en) * 2017-09-27 2019-12-10 Oracle International Corporation Asynchronous handling of service requests

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103095479A (en) * 2011-11-04 2013-05-08 华为技术有限公司 Method and device of business configuration
US9565246B1 (en) * 2012-03-14 2017-02-07 Comindware Ltd. System and method for project and process management by synchronizing custom objects between an application and external server
CN105335310A (en) * 2014-06-05 2016-02-17 阿里巴巴集团控股有限公司 Interface defining method, and data transmission method and apparatus
CN106453288A (en) * 2016-09-29 2017-02-22 上海和付信息技术有限公司 Asynchronous mode supporting distributed micro service framework system and implementation method thereof
CN108901022A (en) * 2018-06-28 2018-11-27 深圳云之家网络有限公司 A kind of micro services universal retrieval method and gateway
CN108989356A (en) * 2018-09-10 2018-12-11 四川长虹电器股份有限公司 A kind of method that API gateway realizes protocol conversion
CN109582472A (en) * 2018-10-19 2019-04-05 华为技术有限公司 A kind of micro services processing method and equipment
CN109445968A (en) * 2018-11-09 2019-03-08 金瓜子科技发展(北京)有限公司 Service request processing method, device, equipment and the storage medium of different agreement
CN109246251A (en) * 2018-11-13 2019-01-18 杭州数梦工场科技有限公司 A kind of micro services call method, device, system, equipment and readable storage medium storing program for executing
CN110300056A (en) * 2019-06-28 2019-10-01 四川长虹电器股份有限公司 A kind of real-time response formula API gateway and its request processing method

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
Gajek,Fabian.API diversity for microservice in the domain of connected vehicles.《Online Publikationen der Universität Stuttgart》.2018, *
基于微服务架构的平台化服务框架的设计与实现;谭一鸣;《中国优秀硕士学位论文全文数据库信息科技辑》;20180131;全文 *
微服务API网关的设计及应用;廖俊杰,陶智勇;《自动化技术与应用》;20190825;全文 *

Also Published As

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

Similar Documents

Publication Publication Date Title
CN111049854B (en) Service request transmission method and device
US9608957B2 (en) Request routing using network computing components
KR101574453B1 (en) System and method for mobility and multi-homing content retrieval applications
KR100978336B1 (en) Remote access
US9282137B2 (en) Dynamic package creation for predictive page load optimization
US10341288B2 (en) Methods circuits devices systems and associated computer executable code for providing conditional domain name resolution
CN106791889B (en) A kind of method for processing video frequency and system, distributed objects storage system
CN103765858B (en) For period that browses in communication network monitoring the method for user and server user
CN105827694B (en) Method and device for acquiring network resources
WO2011088725A1 (en) Method and apparatus for synchronization based on hypertext transfer protocol (http)
WO2012151980A1 (en) Service processing server, system, and method
US8838480B2 (en) Method and apparatus for display of operator ads
WO2021104458A1 (en) Domain name query method and related device
CN114466018A (en) Scheduling method and device for content distribution network, storage medium and electronic equipment
KR20100112979A (en) Method and apparatus for providing mobile advertising service in mobile advertising system
CN109194706A (en) Internet resources dial testing method and terminal
CN112769945A (en) Distributed service calling method and device
CN101741877A (en) Method, system and equipment for operating media resource
CN103561068A (en) Method and device for improving speed of web page browsing
CN112995005A (en) Virtual network data exchange method and device
JP4090711B2 (en) Content providing method, content providing apparatus, content providing program, and recording medium on which content providing program is recorded
KR20170021098A (en) Proxy server, method of reconfigurating of web page using the same
WO2012067562A1 (en) Method and network node for distributing customized content
CN105187867A (en) Media stream control method and device thereof
RU2791422C1 (en) Method for determining the source of a call and a call tracking system using cell phones

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant