CN115037803A - Service calling method, electronic equipment and storage medium - Google Patents
Service calling method, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN115037803A CN115037803A CN202210649261.0A CN202210649261A CN115037803A CN 115037803 A CN115037803 A CN 115037803A CN 202210649261 A CN202210649261 A CN 202210649261A CN 115037803 A CN115037803 A CN 115037803A
- Authority
- CN
- China
- Prior art keywords
- request
- service
- target
- calling
- micro
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 58
- 230000004927 fusion Effects 0.000 claims description 36
- 238000002360 preparation method Methods 0.000 claims description 25
- 230000002776 aggregation Effects 0.000 claims description 20
- 238000004220 aggregation Methods 0.000 claims description 20
- 238000004590 computer program Methods 0.000 claims description 17
- 230000004044 response Effects 0.000 claims description 7
- 230000004931 aggregating effect Effects 0.000 claims description 2
- 230000008569 process Effects 0.000 abstract description 14
- 230000005540 biological transmission Effects 0.000 abstract description 4
- 238000004891 communication Methods 0.000 description 15
- 238000010586 diagram Methods 0.000 description 7
- 238000012545 processing Methods 0.000 description 7
- 230000006870 function Effects 0.000 description 6
- 230000003287 optical effect Effects 0.000 description 3
- 230000003993 interaction Effects 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000000903 blocking effect Effects 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 230000003111 delayed effect Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000011521 glass Substances 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 230000002035 prolonged effect Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 230000001953 sensory effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Images
Landscapes
- Data Exchanges In Wide-Area Networks (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
The invention discloses a micro-service calling method, electronic equipment and a storage medium, wherein service calling requests from various clients are received in a preset time interval, the number of the received service calling requests in the time interval is recorded, the service types of micro-services to which the service calling requests point are recorded, and original request paths and original request parameters included in the service calling requests are recorded, then the service calling requests and various service calling strategies are matched according to the number of the requests, the service types, the original request paths and the original request parameters, the service calling requests are responded according to the successfully matched target service calling strategies, and the micro-services are called for the clients from a server, so that the efficiency of calling the services for the clients is improved, and the accuracy of data transmission among the clients, a gateway and the server is guaranteed in the service calling process.
Description
Technical Field
The present invention relates to the field of service invocation technologies, and in particular, to a service invocation method, an electronic device, and a storage medium.
Background
The rapid development of the internet makes the micro-service architecture more and more widely applied. In a micro-service architecture system, each service module is divided into a plurality of micro-services which are independently developed, deployed and operated, and the micro-services are mutually called and matched through RESTful interfaces to complete various functions. Meanwhile, the service is generally operated in a clustering mode, and multiple operation instances of one service may exist.
In the micro service system, the gateway is used as a uniform inlet of the micro service system and is responsible for receiving the call requests from all the clients, authenticating, forwarding and the like the call requests, and further completing the call of the micro service one by one aiming at each call request.
However, when a gateway is used as a flow inlet of a client request in a microservice system, and when facing a high concurrent request in a complex environment, a single service invocation policy is often implemented for each invocation request from the client, that is, the invocation of microservices is completed for each invocation request one by one, and when facing invocation requests of different types and numbers, flexible processing is difficult, and results such as invocation request response delay, data packet loss and the like for the client are easily caused.
Disclosure of Invention
The invention provides a micro-service calling method, electronic equipment and a storage medium, and aims to solve the problem that a single calling strategy cannot meet a high-concurrency service calling request, so that micro-service calling is delayed.
According to an aspect of the present invention, there is provided a micro service invoking method, including:
receiving service calling requests from all clients in a preset time interval;
recording the request quantity of the service calling requests received in the time interval;
identifying a service type of the micro-service to which the service invocation request is directed;
acquiring an original request path and an original request parameter included in the service calling request;
matching the service calling request with a plurality of service calling strategies according to the request quantity, the service type, the original request path and the original request parameters;
if the service calling request is successfully matched with the service calling strategy, determining that the service calling strategy is a target service calling strategy;
and responding to the service calling request according to the target service calling strategy, and calling the micro service for the client from the server.
According to another aspect of the present invention, there is provided a micro service invocation apparatus, including:
the request receiving module is used for receiving service calling requests from all the clients in a preset time interval;
the request recording module is used for recording the request quantity of the service calling requests received in the time interval;
the service type identification module is used for identifying the service type of the micro service to which the service calling request points;
a path parameter obtaining module, configured to obtain an original request path and an original request parameter included in the service invocation request;
a policy matching module for matching the service invocation request with a plurality of service invocation policies according to the request number, the service type, the original request path and the original request parameters;
the strategy determining module is used for determining that the service calling strategy is a target service calling strategy if the service calling request is successfully matched with the service calling strategy;
and the micro-service calling module is used for responding to the service calling request according to the target service calling strategy and calling micro-service for the client from the server.
According to another aspect of the present invention, there is provided an electronic apparatus including:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores a computer program executable by the at least one processor, the computer program being executable by the at least one processor to enable the at least one processor to perform the microservice calling method of any of the embodiments of the present invention.
According to another aspect of the present invention, there is provided a computer-readable storage medium storing computer instructions for causing a processor to implement the microservice calling method according to any one of the embodiments of the present invention when the computer instructions are executed.
The technical scheme of the invention includes that a gateway receives service call requests from various clients in a preset time interval, the request number of the service call requests, the service type of a service to which the service call requests are directed, and an original request path and an original request parameter included in the service call requests are recorded, the service call requests and various service call strategies stored in the gateway are matched according to the request number, the service type, the original request path and the original request parameter, when the service call requests are successfully matched with any service call strategy, the service call strategy is determined to be a target service call strategy, then the service is called for the clients according to the target service call strategy, and the service call requests are responded compared with a single call strategy, in the invention, the various service call strategies are stored in the gateway in advance, when the gateway receives the service call requests, and selecting a proper service calling strategy for the gateway to respond to the service calling request according to the number of the service calling requests, the service type pointed by the service calling request and the like, so that the efficiency of calling the service for the client is improved, and the accuracy of data transmission among the client, the gateway and the server in the service calling process is ensured.
It should be understood that the statements in this section are not intended to identify key or critical features of the embodiments of the present invention, nor are they intended to limit the scope of the invention. Other features of the present invention will become apparent from the following description.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a flowchart of a method for invoking a micro-service according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a service invocation request transmission applicable in accordance with an embodiment of the present invention;
FIG. 3 is a diagram illustrating service invocation request fusion, according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a micro service invocation device according to a second embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device implementing the micro-service calling method according to an embodiment of the present invention.
Detailed Description
In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the 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 invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention 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 invention described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," or any other variation 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.
Example one
Fig. 1 is a flowchart of a method for invoking a micro-service according to an embodiment of the present invention, where the method is applicable to a situation where a service invocation request is highly concurrent, and the method may be executed by a micro-service invocation device, where the micro-service invocation device may be implemented in a form of hardware and/or software, and the micro-service invocation device may be configured in an electronic device. As shown in fig. 1, the method includes:
and S110, receiving service calling requests from the clients in a preset time interval.
In this embodiment, the gateway, the client, and the server together form a micro service system applying the micro service calling method. The client is also called as a user side, corresponds to the service side, and provides local micro-service for the user. The client in this embodiment can be represented as a mobile application, a desktop application, a browser, and the like. In this embodiment, a plurality of micro services are stored in the server, and when the client sends a service call request, the service call request is forwarded to the server through the gateway, and the server responds to the service call request to provide the micro services. In this embodiment, the micro service refers to that in a micro service architecture system, each service module is divided into micro services that can be independently developed, deployed, and operated, and the micro services can be mutually invoked through a RESTful interface, and are mutually matched to invoke various functions.
The Gateway in this embodiment may be a micro service Gateway based on a Spring Cloud Gateway, the Spring Cloud Gateway is implemented based on a WebFlux framework, and a high-performance Reactor mode communication framework Netty is used at the bottom layer of the WebFlux framework, so as to provide a simple, effective and unified API route management manner for the micro service framework. The protocol between the server and the client programs is very efficient and convenient to realize with the help of Netty, the network programming of TCP or UDP sockets is greatly simplified, and the programs developed by using Netty have high performance and maintainability.
In this embodiment, the Gateway is used as a unified entry of the microservice system, after all service invocation requests sent by clients enter the Gateway, the Gateway can be first handled by a Spring Cloud Gateway request access module, the Spring Cloud Gateway can use few threads to handle a large number of connections asynchronously and non-blocking, and then perform security authentication operations such as routing, authentication, and the like on the service invocation requests. The service invocation strategy in the embodiment comprises a request bureau and strategy, a request cache strategy, a request balancing strategy and a request fusion strategy. As shown in fig. 2, the client sends a service invocation request to the gateway, and after the gateway performs the request access, the service invocation request is processed by each service invocation policy and forwarded to the server.
And S120, recording the request quantity of the service calling requests received in the time interval.
In this embodiment, the time interval is used to measure the state of the service invocation request received by the gateway, and it can be determined whether the service invocation request is in a high concurrency state by recording the number of requests of the service invocation request received by the gateway in the time interval. When the service call request is in a high concurrency state, the gateway is used as an entrance of service call request flow and bears huge load, and at the moment, by applying a corresponding service call strategy, the load pressure of receiving and forwarding the service call request by the gateway can be relieved, and the delay of micro-service call is reduced.
S130, identifying the service type of the micro service pointed by the service calling request.
In this embodiment, the server stores micro services of multiple service types, different service invocation requests may point to the same micro service or may point to different micro services, and the micro service of the server is invoked by selecting a suitable service invocation policy by identifying the service type of the micro service to which the service invocation request points.
S140, acquiring an original request path and original request parameters included in the service calling request.
In this embodiment, the service invocation request includes an original request path and an original request parameter, where the original request path and the original request parameter may be combined to identify, in a cache library of the gateway, service data that corresponds to the service invocation request and is pre-stored in the cache library.
And S150, matching the service calling request with various service calling strategies according to the request quantity, the service type, the original request path and the original request parameters.
In this embodiment, after receiving the service invocation request, the gateway may match the service invocation policy according to the number of requests of the service invocation request, the type of the targeted micro service, and the included original request path and original request parameter, and perform invocation of the micro service to the service end according to the successfully matched service invocation policy. Specifically, in this embodiment, the service invocation request, the request aggregation policy and the request fusion policy may be matched according to the service type,
in this embodiment, matching the service invocation request and the request aggregation policy may be expressed in that, if there are two or more sub-services whose service types of the micro-service to which the service invocation request points are sub-services that implement the same target micro-service, it may be determined that the service invocation request and the request aggregation policy are successfully matched, and the plurality of sub-services jointly form the target micro-service. For example, when the user's request aims at implementing a function or loading a page without considering the UI logic of the client, the client will initiate multiple service call requests, each of which is directed to the micro-service, which is the sub-service, and the implemented function or loaded page may be the target micro-service.
In this embodiment, the process of matching the service invocation request and the request fusion policy is expressed in that if two or more service invocation requests point to a preset micro service of a specific service type, it is determined that the service invocation request and the request fusion policy are successfully matched, and the specific service type includes a query service. Because the micro service architecture is generally realized by remote invocation, the remote invocation has the limitations of network consumption and network connection quantity, and in a state that the service invocation request is highly concurrent, when the gateway forwards the service invocation request to the server, the communication times are greatly increased, so that the invocation time is prolonged, and the communication resource consumption is more. Therefore, in the embodiment, a plurality of service call requests, which are received by the gateway in the same time interval and point to the micro service of the same specific service type, can be fused through the request fusion strategy, so that the communication times are reduced, and the communication resources are saved. The micro-service of a specific service type in this embodiment may be a query-class micro-service, such as querying multiple books with different numbers. But also micro-services that operate on a single parameter, such as acquisition.
Matching service invocation requests and request caching policies in this embodiment may be expressed as matching service invocation requests and request caching policies according to the original request path and the original request parameters.
The method specifically comprises the following steps: the method includes obtaining a provisioning request path and a provisioning request parameter pre-stored in a gateway, where the gateway in this embodiment includes a storage unit, and the storage unit is used to store the provisioning request path and the provisioning request parameter. The prepare request path and the prepare request parameter may be an original request path and an original request parameter of the gateway receiving the service invocation request in a time interval before the current time interval.
That is, in this embodiment, the gateway may store the original request path and the original request parameter of the service invocation request as the preparation request path and the preparation request parameter after forwarding the service invocation request sent by the client to the server, and may correspondingly store the service data returned by the server, the preparation request path, and the preparation request parameter in the storage unit of the gateway. And then matching the original request path with the preparation request path, the original request parameters and the preparation request parameters, and if the preparation request path consistent with the original request path exists and the preparation request parameters consistent with the original request parameters exist, determining that the service invocation request is successfully matched with the request caching strategy.
The process of matching the service invocation request and the request balancing policy in this embodiment may be represented by comparing the request number of the service invocation request received in the time interval with a preset number threshold, and if the request number is greater than the preset number threshold, it may be determined that the service invocation request and the request balancing policy are successfully matched. In this embodiment, because each server has limited performance, when a highly-concurrent service invocation request is encountered, a plurality of service invocation requests can be distributed to different servers by the request balancing policy when the performance of the server is determined to be insufficient based on the number of requests, so that the response pressure of a single server is reduced.
And S160, if the service calling request is successfully matched with the service calling strategy, determining the service calling strategy as a target service calling strategy.
In this embodiment, when the service invocation request and the service invocation policy are successfully matched, the successfully matched service invocation policy may be determined to be a target service invocation policy, and the target service invocation policy is used to instruct the gateway to process the service invocation request matched with the target service invocation policy, and forward the service invocation request to the service end after the processing.
S170, responding to the service calling request according to the target service calling strategy, and calling the micro service for the client from the server.
In this embodiment, after the target service invocation policy of the service invocation request is determined, the service invocation request may be responded according to the target service invocation policy, and after the service invocation request is processed, the processed service invocation request may be forwarded to the server to invoke the micro service for the client.
Specifically, in this embodiment, when the target service invocation policy is a request aggregation policy, the micro service invocation process may be represented as: the method comprises the steps of extracting a plurality of service call requests matched with a request aggregation strategy to be first target requests, obtaining original request paths included by the first target requests to serve as first request paths, and then aggregating the first request paths to serve as target request paths. Service invocation requests, as described above in conjunction with the request aggregation policy, are directed to multiple microservices that, through cooperation, may together implement functionality such as loading a page. After the target request paths are obtained through aggregation, first service data are requested in the server according to the target request paths, so that calls are initiated to a plurality of micro services pointed by a plurality of first target requests at the same time, and finally the first service data formed after the micro services are called are returned to the client.
Specifically, in this embodiment, when the target service invocation policy is a request cache policy, the micro service invocation process may be represented as: and extracting the service calling request matched with the request caching strategy as a second target request, and then acquiring an original request path and original request parameters included in the second target request as a second request path and second request parameters.
According to the second request path and the second request parameter, the gateway queries the provisioning service data as the second service data, where the provisioning service data in this embodiment may be the second service data previously stored in the gateway and returned when the service is called in the server according to the provisioning request path and the provisioning request parameter that are consistent with the second request path and the second request parameter.
In this embodiment, the frequency of each micro service invocation may be recorded, an original request path and an original request parameter in a service invocation request corresponding to a micro service with a higher invocation frequency and service data obtained at a server according to the original request parameter and the original request path are stored in a storage unit of a gateway as a preliminary request path, a preliminary request parameter, and preliminary request data, and the preliminary request path, the preliminary request parameter, and the preliminary request data that refer to the same micro service in the storage unit are in one-to-one correspondence.
Furthermore, in this embodiment, in consideration of the limited storage amount of the storage unit, the preparation request path, the preparation request parameter, and the preparation request data may be subjected to time-limited caching, that is, a caching validity period is set in advance for the relevant data of a certain microservice in the storage unit, and the relevant data is automatically cleared from the storage unit after the caching validity period elapses.
Therefore, in this embodiment, the gateway may directly return the second service data to the client by querying the preparation request path in the gateway, where the preparation request path is consistent with the second request path of the second target request and the preparation request parameter corresponds to the second request parameter, that is, the preparation service data corresponding to the preparation request path and the preparation request parameter and stored in the gateway in advance is omitted, and the step of forwarding the service invocation request to the server by the gateway is omitted, so that the number of communications is reduced and the consumption of communication resources is reduced, and the response time of the service invocation request is shortened by directly returning the service data to the client by the gateway.
Specifically, in this embodiment, when the target service invocation policy is a request balancing policy, the micro service invocation process may be represented as: the service call requests matched with the request balancing strategy are extracted as third target requests, and it can be known that when the target service call strategy is the request balancing strategy, the number of the requests of the service call requests received by a single service end is in an excessive state, so that the plurality of third target requests can be divided into a plurality of service call groups, the number of the third target requests in the service call groups is smaller than a preset number threshold, and different service call groups call micro-services from different service ends, so that the corresponding pressure of the single service end is reduced. In this embodiment, the third target request may be divided by methods such as random load balancing, minimum active number load balancing, consistent hash load balancing, and the like.
And then, requesting third service data at a target server according to an original request path and original request parameters included in the third target request, where the target server is a server pointed by a service invocation group where the third target request is located in the present embodiment, and finally returning the third service data generated by performing micro-service invocation at the target service segment to the client.
Specifically, in this embodiment, when the target service invocation policy is a request fusion policy, the micro service invocation process may be represented as: and extracting the service calling request matched with the request fusion strategy as a fourth target request.
And then fusing the plurality of fourth target requests into a single fused target request, wherein the fused target request comprises a fused request path and a fused request parameter.
After the fusion is finished, fourth service data may be requested at the server according to the fusion request path and the fusion request parameter, the fourth target request may be a micro-service directed to the query class, for example, if the plurality of fourth target requests are query BOOKs, the process of fusing the service call request, that is, the fourth target request, is shown in fig. 3, the plurality of fourth target requests may be expressed as GET/BOOK/1, GET/BOOK/2, GET/BOOK/3, and GET/BOOK/4, after the fourth target request is processed by the request fusion policy, the obtained fusion target request may be expressed as GET/BOOK/1, 2, 3, 4, and then the micro-service call is performed according to the fusion target request.
In this embodiment, after the microservice is called to the server according to the fusion target request to obtain the fourth service data, the fourth service data is returned to the client.
The technical scheme of the invention includes that a gateway receives service call requests from various clients in a preset time interval, the request number of the service call requests, the service type of a service to which the service call requests are directed, and an original request path and an original request parameter included in the service call requests are recorded, the service call requests and various service call strategies stored in the gateway are matched according to the request number, the service type, the original request path and the original request parameter, when the service call requests are successfully matched with any service call strategy, the service call strategy is determined to be a target service call strategy, then the service is called for the clients according to the target service call strategy, and the service call requests are responded compared with a single call strategy, in the invention, the various service call strategies are stored in the gateway in advance, when the gateway receives the service call requests, and selecting a proper service calling strategy for the gateway to respond to the service calling request according to the number of the service calling requests, the service type pointed by the service calling request and the like, so that the efficiency of calling the service for the client is improved, and the accuracy of data transmission among the client, the gateway and the server in the service calling process is ensured.
It should be understood that the statements in this section are not intended to identify key or critical features of the embodiments of the present invention, nor are they intended to limit the scope of the invention. Other features of the present invention will become apparent from the following description.
Example two
Fig. 4 is a schematic structural diagram of a micro service invocation device according to a second embodiment of the present invention. As shown in fig. 4, the apparatus includes:
a request receiving module 410, configured to receive a service invocation request from each client in a preset time interval;
a request recording module 420, configured to record the number of requests of the service invocation request received in the time interval;
a service type identification module 430, configured to identify a service type of the micro service to which the service invocation request is directed;
a path parameter obtaining module 440, configured to obtain an original request path and an original request parameter included in the service invocation request;
a policy matching module 450, configured to match the service invocation request with a plurality of service invocation policies according to the number of requests, the service type, the original request path, and the original request parameter;
a policy determining module 460, configured to determine that the service invocation policy is a target service invocation policy if the service invocation request is successfully matched with the service invocation policy;
and the micro-service invoking module 470 is configured to respond to the service invoking request according to the target service invoking policy, and invoke a micro-service for the client from the server.
Optionally, the policy matching module 450 includes:
the request aggregation/fusion strategy matching module is used for matching the service calling request with the request aggregation strategy and the request fusion strategy according to the service type;
a request cache policy matching module, configured to match the service invocation request with the request cache policy according to the original request path and the original request parameter;
the request quantity comparison module is used for comparing the request quantity with a preset quantity threshold value;
and the balancing strategy matching module is used for determining that the service calling request is successfully matched with the request balancing strategy if the number of the requests is greater than a preset number threshold.
Optionally, the request aggregation/fusion policy matching module includes:
a request aggregation policy determining module, configured to determine that the service invocation request is successfully matched with the request aggregation policy if the service type of a micro service to which two or more service invocation requests are directed is a sub-service for implementing the same target micro service, where the plurality of sub-services jointly form the target micro service;
and the request fusion strategy determining module is used for determining that the service calling request and the request fusion strategy are successfully matched if two or more than two micro services of which the service calling requests point to preset specific service types, wherein the specific service types comprise query services.
Optionally, the request caching policy matching module includes:
a prepared path parameter obtaining module, configured to obtain a prepared request path and a prepared request parameter that are pre-stored in the gateway;
a path parameter matching module, configured to match the original request path and the preparation request path, and the original request parameter and the preparation request parameter;
and the cache policy determining module is used for determining that the service calling request is successfully matched with the request cache policy if the preparation request path consistent with the original request path exists and the preparation request parameter consistent with the original request parameter exists.
Optionally, the microservice calling module 470 includes:
the first target request determining module is used for extracting the service calling requests matched with the request aggregation strategy into first target requests;
a first request path obtaining module, configured to obtain an original request path included in the plurality of first target requests, as a first request path;
a path aggregation module, configured to aggregate the plurality of first request paths as target request paths;
a first service data request module, configured to request first service data in the server according to the target request path;
and the first service data returning module is used for returning the requested first service data to the client.
Optionally, the microservice calling module 470 includes:
the second target request determining module is used for extracting the service calling request matched with the request cache strategy as a second target request;
a second request path/parameter obtaining module, configured to obtain an original request path and an original request parameter included in the second target request, where the original request path and the original request parameter are used as a second request path and a second request parameter;
a second service data query module, configured to query, according to the second request path and the second request parameter, provisioning service data in the gateway as second service data, where the provisioning service data is previously stored in the gateway, and the second service data is returned when the service is called in the server according to the provisioning request path and the provisioning request parameter that are consistent with the second request path and the second request parameter;
and the second service data returning module is used for returning the second service data to the client.
Optionally, the microservice calling module 470 includes:
a third target request determining module, configured to extract the service invocation request matched with the request balancing policy as a third target request;
the third target request dividing module is used for dividing a plurality of third target requests into a plurality of service call groups, the number of the third target requests in the service call groups is smaller than a preset number threshold, and different service call groups call micro-services from different service terminals;
a third service data request module, configured to request, at the target server, third service data according to the original request path and the original request parameter included in the third target request, where the target server is the server to which the service invocation group where the third target request is located points;
and the third service data returning module is used for returning the third service data to the client.
Optionally, the microservice calling module 470 includes:
a fourth target request determining module, configured to extract the service invocation request matched with the request fusion policy as a fourth target request;
a fourth target request fusion module, configured to fuse a plurality of fourth target requests into a single fusion target request, where the fusion target request includes a fusion request path and a fusion request parameter;
a fourth service data request module, configured to request fourth service data at the server according to the fusion request path and the fusion request parameter;
and the fourth service data returning module is used for returning the fourth service data to the client. The micro-service calling device provided by the embodiment of the invention can execute the micro-service calling method provided by any embodiment of the invention, and has the corresponding functional module and beneficial effect of the execution method.
EXAMPLE III
FIG. 5 illustrates a schematic diagram of an electronic device 10 that may be used to implement an embodiment of the invention. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the inventions described and/or claimed herein.
As shown in fig. 5, the electronic device 10 includes at least one processor 11, and a memory communicatively connected to the at least one processor 11, such as a Read Only Memory (ROM)12, a Random Access Memory (RAM)13, and the like, wherein the memory stores a computer program executable by the at least one processor, and the processor 11 can perform various suitable actions and processes according to the computer program stored in the Read Only Memory (ROM)12 or the computer program loaded from a storage unit 18 into the Random Access Memory (RAM) 13. In the RAM 13, various programs and data necessary for the operation of the electronic apparatus 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other via a bus 14. An input/output (I/O) interface 15 is also connected to bus 14.
A number of components in the electronic device 10 are connected to the I/O interface 15, including: an input unit 16 such as a keyboard, a mouse, or the like; an output unit 17 such as various types of displays, speakers, and the like; a storage unit 18 such as a magnetic disk, an optical disk, or the like; and a communication unit 19 such as a network card, modem, wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information/data with other devices via a computer network such as the internet and/or various telecommunication networks.
In some embodiments, the microservice calling method may be implemented as a computer program tangibly embodied on a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 10 via the ROM 12 and/or the communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the above-described microservice calling method may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the microservice invocation method in any other suitable manner (e.g., by way of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Computer programs for implementing the methods of the present invention can be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions/acts specified in the flowchart and/or block diagram block or blocks to be performed. A computer program can execute entirely on a machine, partly on a machine, as a stand-alone software package partly on a machine and partly on a remote machine or entirely on a remote machine or server.
In the context of the present invention, a computer-readable storage medium may be a tangible medium that can contain, or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. A computer readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, the computer readable storage medium may be a machine readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user may provide input to the electronic device. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), Wide Area Networks (WANs), blockchain networks, and the internet.
The computing system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so that the defects of high management difficulty and weak service expansibility in the traditional physical host and VPS service are overcome.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present invention may be executed in parallel, sequentially, or in different orders, and are not limited herein as long as the desired results of the technical solution of the present invention can be achieved.
The above-described embodiments should not be construed as limiting the scope of the invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims (10)
1. A micro-service calling method is applied to a gateway, wherein a plurality of service calling policies are stored in the gateway, the service calling policies comprise at least one of a request aggregation policy, a request caching policy, a request balancing policy and a request fusion policy, the gateway obtains micro-services from a plurality of service terminals, and the service terminals store a plurality of micro-services, and the method comprises the following steps:
receiving service calling requests from all clients in a preset time interval;
recording the request quantity of the service call requests received in the time interval;
identifying a service type of the micro-service to which the service invocation request is directed;
acquiring an original request path and an original request parameter included in the service calling request;
matching the service calling request with a plurality of service calling strategies according to the request quantity, the service type, the original request path and the original request parameters;
if the service calling request is successfully matched with the service calling strategy, determining the service calling strategy as a target service calling strategy;
and responding to the service calling request according to the target service calling strategy, and calling the micro service for the client from the server.
2. The method of claim 1, wherein matching the service invocation request with a plurality of service invocation policies according to the number of requests, the service type, the original request path, and the original request parameters comprises:
matching the service calling request with the request aggregation strategy and the request fusion strategy according to the service type;
matching the service calling request with the request caching strategy according to the original request path and the original request parameter;
comparing the request quantity with a preset quantity threshold value;
and if the request quantity is greater than a preset quantity threshold value, determining that the service calling request is successfully matched with the request balancing strategy.
3. The method of claim 2, wherein said matching said service invocation request with said request aggregation policy and said request fusion policy according to said service type comprises:
if the service types of the micro services pointed by two or more service calling requests are sub-services for realizing the same target micro service, determining that the service calling requests are successfully matched with the request aggregation strategy, and forming the target micro service by a plurality of sub-services together;
and if two or more than two service calling requests point to preset micro-services with specific service types, determining that the service calling requests are successfully matched with the request fusion strategy, wherein the specific service types comprise inquiry services.
4. The method of claim 2, wherein said matching the service invocation request with the request caching policy according to the original request path and the original request parameters comprises:
acquiring a preparation request path and a preparation request parameter which are prestored in the gateway;
matching the original request path and the prepare request path, the original request parameters and the prepare request parameters;
and if the preparation request path consistent with the original request path exists and the preparation request parameter consistent with the original request parameter exists, determining that the service calling request is successfully matched with the request caching policy.
5. The method according to any of claims 1-4, wherein if the target service invocation policy comprises a request aggregation policy, said invoking a microservice for the client in response to the service invocation request according to the target service invocation policy comprises:
extracting a plurality of service calling requests matched with the request aggregation strategy as first target requests;
obtaining an original request path included by a plurality of first target requests as a first request path;
aggregating a plurality of the first request paths as target request paths;
requesting first service data in the server according to the target request path;
and returning the requested first service data to the client.
6. The method according to any one of claims 1-4, wherein if the target service invocation policy includes the request caching policy, the invoking the micro-service for the client in response to the service invocation request according to the target service invocation policy comprises:
extracting the service calling request matched with the request caching strategy as a second target request;
acquiring an original request path and an original request parameter included in the second target request as a second request path and a second request parameter;
according to the second request path and the second request parameter, inquiring reserved service data in the gateway as second service data, wherein the reserved service data is stored in the gateway in advance, and the second service data returned when the service is called in the service terminal according to the reserved request path and the reserved request parameter which are consistent with the second request path and the second request parameter;
and returning the second service data to the client.
7. The method of any of claims 1-4, wherein if the target service invocation policy comprises the request balancing policy, said invoking a microservice for the client in response to the service invocation request according to the target service invocation policy, comprises:
extracting the service calling request matched with the request balancing strategy as a third target request;
dividing the plurality of third target requests into a plurality of service call groups, wherein the number of the third target requests in the service call groups is smaller than a preset number threshold, and different service call groups call micro-services from different service terminals;
requesting third service data at the target server according to the original request path and the original request parameter included in the third target request, wherein the target server is the server pointed by the service call group where the third target request is located;
and returning the third service data to the client.
8. The method according to any one of claims 1-4, wherein if the target invocation policy includes the request fusion policy, the invoking the micro-service for the client in response to the service invocation request according to the target service invocation policy comprises:
extracting the service calling request matched with the request fusion strategy to serve as a fourth target request;
fusing a plurality of fourth target requests into a single fused target request, wherein the fused target request comprises a fused request path and a fused request parameter;
requesting fourth service data at the server according to the fusion request path and the fusion request parameters;
and returning the fourth service data to the client.
9. An electronic device, characterized in that the electronic device comprises:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores a computer program executable by the at least one processor, the computer program being executable by the at least one processor to enable the at least one processor to perform the micro service invocation method of any of claims 1-8.
10. A computer-readable storage medium storing computer instructions for causing a processor to implement the microservice calling method of any of claims 1-8 when executed.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210649261.0A CN115037803B (en) | 2022-06-09 | 2022-06-09 | Service calling method, electronic equipment and storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210649261.0A CN115037803B (en) | 2022-06-09 | 2022-06-09 | Service calling method, electronic equipment and storage medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN115037803A true CN115037803A (en) | 2022-09-09 |
| CN115037803B CN115037803B (en) | 2024-03-22 |
Family
ID=83122087
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202210649261.0A Active CN115037803B (en) | 2022-06-09 | 2022-06-09 | Service calling method, electronic equipment and storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN115037803B (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN116567094A (en) * | 2023-06-08 | 2023-08-08 | 北京锐安科技有限公司 | Service information processing method based on micro service system |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2014005455A1 (en) * | 2012-04-12 | 2014-01-09 | 华为技术有限公司 | Policy control method, device, and system for data service |
| CN104780184A (en) * | 2014-01-09 | 2015-07-15 | 华耀(中国)科技有限公司 | A Method of Using Geographical Location Information for Load Balancing |
| US20190372847A1 (en) * | 2018-05-29 | 2019-12-05 | University-Industry Cooperation Group Of Kyung-Hee University | Policy-based storage service federation method and apparatus |
| CN111600930A (en) * | 2020-04-09 | 2020-08-28 | 网宿科技股份有限公司 | Traffic management method, device, server and storage medium for microservice request |
| WO2020211365A1 (en) * | 2019-04-19 | 2020-10-22 | 平安科技(深圳)有限公司 | Flow load balancing method and apparatus, computer device and storage medium |
-
2022
- 2022-06-09 CN CN202210649261.0A patent/CN115037803B/en active Active
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2014005455A1 (en) * | 2012-04-12 | 2014-01-09 | 华为技术有限公司 | Policy control method, device, and system for data service |
| CN104780184A (en) * | 2014-01-09 | 2015-07-15 | 华耀(中国)科技有限公司 | A Method of Using Geographical Location Information for Load Balancing |
| US20190372847A1 (en) * | 2018-05-29 | 2019-12-05 | University-Industry Cooperation Group Of Kyung-Hee University | Policy-based storage service federation method and apparatus |
| WO2020211365A1 (en) * | 2019-04-19 | 2020-10-22 | 平安科技(深圳)有限公司 | Flow load balancing method and apparatus, computer device and storage medium |
| CN111600930A (en) * | 2020-04-09 | 2020-08-28 | 网宿科技股份有限公司 | Traffic management method, device, server and storage medium for microservice request |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN116567094A (en) * | 2023-06-08 | 2023-08-08 | 北京锐安科技有限公司 | Service information processing method based on micro service system |
Also Published As
| Publication number | Publication date |
|---|---|
| CN115037803B (en) | 2024-03-22 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN109597643A (en) | Using gray scale dissemination method, device, electronic equipment and storage medium | |
| US11978025B2 (en) | Method and device for processing virtual cards | |
| CN110267314A (en) | Method and device for switching network slices | |
| WO2016127796A1 (en) | Information interaction method and server | |
| CN114490071A (en) | Resource scheduling method, device, equipment and medium based on cloud game | |
| CN115883647B (en) | Business log recording method, system, device, terminal, server and medium | |
| CN113691403A (en) | Topological node configuration method, related device and computer program product | |
| CN115037803B (en) | Service calling method, electronic equipment and storage medium | |
| CN115529271B (en) | Service request distribution method, device, equipment and medium | |
| CN113765958A (en) | Job task processing method and job client | |
| CN115314509B (en) | Synchronization method, device, equipment and storage medium of application registration information | |
| CN115529186B (en) | SSL certificate unloading method, device and system based on soft load balancing | |
| CN116521739A (en) | Data processing method and device and electronic equipment | |
| CN116016677A (en) | Service request processing method and device and computer equipment | |
| CN113420275A (en) | Data connection processing method, related device and computer program product | |
| CN114584605B (en) | Service distribution method and device, electronic equipment and storage medium | |
| CN114968534B (en) | Method, device, electronic device and medium for implementing distributed lock | |
| CN115665240B (en) | Proxy service adding method, proxy service adding device, electronic equipment and storage medium | |
| CN119809624B (en) | Hot account control method, device, equipment, medium and product | |
| CN119603272B (en) | Virtual cipher machine management method, device, equipment, medium and product | |
| CN115988124B (en) | Method and device for determining equipment ID | |
| CN119071361B (en) | Isolation method, device, equipment and storage medium for service request | |
| CN112351072B (en) | Message pushing method and terminal | |
| CN119759576A (en) | A server resource allocation method, device, equipment, storage medium and product | |
| CN120475076A (en) | Front-end and back-end communication request response method, device, equipment, storage medium and product |
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 |