CN117221325A - Custom load balancing device, method, equipment and storage medium based on gateway - Google Patents

Custom load balancing device, method, equipment and storage medium based on gateway Download PDF

Info

Publication number
CN117221325A
CN117221325A CN202311169979.0A CN202311169979A CN117221325A CN 117221325 A CN117221325 A CN 117221325A CN 202311169979 A CN202311169979 A CN 202311169979A CN 117221325 A CN117221325 A CN 117221325A
Authority
CN
China
Prior art keywords
service
gateway
load balancing
port
client
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311169979.0A
Other languages
Chinese (zh)
Inventor
于腾辉
付新
姚宇吉
王艺撒
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Dameng Data Technology Jiangsu Co ltd
Original Assignee
Dameng Data Technology Jiangsu 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 Dameng Data Technology Jiangsu Co ltd filed Critical Dameng Data Technology Jiangsu Co ltd
Priority to CN202311169979.0A priority Critical patent/CN117221325A/en
Publication of CN117221325A publication Critical patent/CN117221325A/en
Pending legal-status Critical Current

Links

Landscapes

  • Data Exchanges In Wide-Area Networks (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention discloses a self-defined load balancing device, method, equipment and storage medium based on gateway, the device includes: a client, a gateway server, and a plurality of micro-services. The method comprises the following steps: reading request parameters sent by a client in an analysis selection method; acquiring all the service objects, and aggregating and analyzing the service objects to form a key value pair format to be stored in a cache; if the client does not specify the service IP and the PORT, randomly selecting a service object from the service list provider objects and returning; if the client designates the service IP and the PORT, the service objects corresponding to the IP and the PORT do not exist in the key value pair cache, and an empty object is returned; if the client designates the service IP and the PORT, the service objects corresponding to the IP and the PORT exist in the key value pair cache, and the existing service objects are acquired and returned; the gateway automatically invokes the corresponding service according to the returned micro-service object. The invention meets the requirement of accessing the specific micro service and does not affect other functional characteristics of the gateway.

Description

Custom load balancing device, method, equipment and storage medium based on gateway
Technical Field
The invention relates to the technical field of micro-services and distribution, in particular to a self-defined load balancing device, method, equipment and storage medium based on a gateway.
Background
Load balancing is a critical component of a high availability network infrastructure, typically used to distribute workload to multiple servers to improve the performance and reliability of websites, applications, databases, or other services.
The micro service is to split each business module of a large project into a plurality of independent small projects, and the small projects are focused on completing their own functions, and can call methods of other small projects, thereby completing the whole functions.
The distributed type is to distribute the back-end work to a plurality of hosts or services through a computer network, and the plurality of hosts or services cooperate together to complete the work.
Spring Cloud is a scaffold tool for developing java web systems, with which multiple micro services can be organized into a large distributed system.
Spring Cloud Gateway is a gateway developed by Spring authorities based on Spring 5.0,Spring Boot 2.0 and Project Reactor, etc., and Spring Cloud Gateway is intended to provide a simple and effective unified API route management manner for micro-service architecture. Spring Cloud Gateway it not only provides a unified routing way, but also the gateway can gather the addresses accessed by a plurality of micro services, which micro service interface you want to access, directly accesses the gateway, and the gateway is responsible for forwarding to the corresponding micro service address, so that the client only needs to know the service address of the gateway.
In some service scenarios, the client knows the IP and PORT of a certain service, and accesses the micro service corresponding to the IP and PORT through the gateway to perform service processing, but the gateway does not support the function (the gateway defaults to support algorithms such as random, weight, rotation, etc.), so a custom algorithm needs to be used to realize the function characteristic.
Disclosure of Invention
The invention aims to solve the technical problem of providing a self-defined load balancing device, method, equipment and storage medium based on a gateway, which ensure the safety, standardization and compatibility of codes, meet the requirement of accessing specific micro services, do not influence other functional characteristics of the gateway, and ensure the integrity of a system.
In order to solve the above technical problems, the present invention provides a self-defined load balancing device based on a gateway, including: a client, a gateway server, and a plurality of micro services; the client accesses the gateway server in the form of carrying the service IP and the PORT through the request header, and the gateway service finds the corresponding service object according to the service IP and the PORT carried in the request header through a self-defined load balancing algorithm and then carries out remote call.
Preferably, if the service corresponding to the IP and the PORT designated by the client does not exist in the cache, the gateway server automatically reports errors to the client; if so, the corresponding service is returned directly.
Correspondingly, the self-defined load balancing method based on the gateway comprises the following steps:
step 1, in a selection method in a self-defined load balancing algorithm class, reading request parameters sent by a client in an analysis selection method, and acquiring a service address IP and a PORT designated by the client in a request head;
step 2, obtaining all the service objects from the service list provider objects, and aggregating and analyzing the service objects to form a key value pair format to be stored in a cache;
step 3, if the client does not specify the service IP and the PORT, randomly selecting a service object from the service list provider objects and returning;
step 4, if the client has the appointed service IP and PORT, and the service objects corresponding to the IP and the PORT do not exist in the key value pair cache, returning an empty object, automatically reporting errors by the gateway and responding to the client;
step 5, if the client has the appointed service IP and PORT, the service objects corresponding to the IP and the PORT exist in the key value pair cache, and the existing service objects are acquired and returned;
and 6, automatically calling the corresponding service according to the returned micro-service object by the gateway so as to realize a self-defined routing mode and load balancing.
Preferably, in step 1, when the client requests, it is confirmed whether the request header needs to carry the service IP and the PORT, and then the request is sent to the backend.
Preferably, in step 2, the key stores the IP and PORT of the micro service, and the value stores the micro service instance object information corresponding to the IP and PORT.
Preferably, in step 2, a conversion method in a lambda expression stream function of a service list provider built in the gateway service is called, so as to obtain a service list set.
Preferably, in step 2, a collection method and a grouping method in a streaming function of the service list set are executed, the data format of IP + ":" +port is used as a key to perform grouping, the corresponding value is used as an object of the service, and a cache data set using IP and PORT as keys and the service object as a value is collected.
Preferably, in step 6, load balancing client annotation is added on the gateway service start class, and a service ID of the custom load balancing algorithm and a class where the custom load balancing algorithm is located are set.
Correspondingly, the self-defined load balancing device based on the gateway is characterized by comprising the following components: one or more processors;
a storage means for storing one or more programs, user data;
the one or more programs, when executed by one or more processors, cause the one or more processors to implement the gateway-based custom load balancing method of any of claims 3 to 8.
Correspondingly, a custom load balancing storage medium based on a gateway, wherein a computer program is stored thereon, which when executed by a processor, implements the custom load balancing method based on a gateway according to any of claims 3 to 8.
The beneficial effects of the invention are as follows: the gateway component based on the spring group framework utilizes the expansion interface to carry out secondary development, ensures the safety, standardization and compatibility of codes, meets the requirement of accessing specific micro services according to IP and PORT, does not influence other functional characteristics of the gateway, and also ensures the integrity of the system.
Drawings
Fig. 1 is a schematic structural diagram of a load balancing device according to the present invention.
Fig. 2 is a flow chart of a load balancing method according to the present invention.
FIG. 3 is a diagram illustrating a mapping relationship between key values and cache data according to the present invention.
Detailed Description
As shown in fig. 1, a gateway-based custom load balancing device includes: a client, a gateway server, and a plurality of micro services; the client designates the service IP and PORT to be accessed, performs a load balancing algorithm through the gateway server, searches for the corresponding micro-service, and then performs remote call.
If the service corresponding to the IP and the PORT appointed by the client does not exist, reporting errors to the client by the gateway server; if so, executing remote call to access the corresponding micro-service.
As shown in fig. 2, a self-defined load balancing method based on a gateway includes the following steps:
step 1, in a selection method in a self-defined load balancing algorithm class, reading request parameters sent by a client in an analysis selection method, and acquiring a service address IP and a PORT designated by the client in a request head;
step 2, obtaining all service objects from the service list provider objects, and aggregating and analyzing the service objects to form a key value pair format to store the key value pair format in a cache, wherein the key stores the IP and PORT of the micro service, and the value stores micro service example object information corresponding to the IP and the PORT, as shown in fig. 3; calling a conversion method in a lambda expression streaming function of a service list provider built in a gateway service, acquiring a service list set according to the conversion method, executing a collection method and a grouping method in the streaming function of the service list set, grouping according to a data format of IP+ ":" +PORT, taking a corresponding value as a service object, and collecting a cache data set taking the IP and the PORT as keys and taking the service object as a value;
step 3, if the client does not specify the service IP and the PORT, randomly selecting a service object from the service list provider objects and returning;
step 4, if the client has the appointed service IP and PORT, and the service objects corresponding to the IP and the PORT do not exist in the key value pair cache, returning an empty object, automatically reporting errors by the gateway and responding to the client;
step 5, if the client has the appointed service IP and PORT, the service objects corresponding to the IP and the PORT exist in the key value pair cache, and the existing service objects are acquired and returned;
and 6, automatically calling the corresponding service according to the returned micro-service object by the gateway so as to realize a self-defined routing mode and load balancing.
And adding load balancing client annotation on the gateway service starting class, and designating the class of service ID and custom load balancing algorithm which need load balancing. The gateway can carry out self-defined load balancing on the micro-services with the same ID according to the set service ID and the load balancing algorithm class.
Redefining the gateway load balancer. Creating a class to realize gateway load balancer interface, and injecting the service object list object of gateway service into the interface, wherein the service object list stores all micro service example address information, rewrites the selection method, analyzes the request parameters, and carries out self-defined load balancing algorithm according to the parameters to realize access to the micro service corresponding to the address through the client specified address (IP+PORT).
The gateway component based on the spring closed framework utilizes the custom expansion interface to carry out secondary development of the load balancing algorithm, ensures the safety, standardization and compatibility of codes, meets the requirement of accessing specific micro services, does not influence other functional characteristics of the gateway, and ensures the integrity of the system.

Claims (10)

1. A gateway-based custom load balancing apparatus, comprising: a client, a gateway server, and a plurality of micro services; the client accesses the gateway server in the form of carrying the service IP and the PORT through the request header, and the gateway service finds the corresponding service object according to the service IP and the PORT carried in the request header through a self-defined load balancing algorithm and then carries out remote call.
2. The gateway-based custom load balancing apparatus according to claim 1, wherein if the service corresponding to the IP and PORT specified by the client does not exist in the cache, the gateway server automatically reports an error to the client; if so, the corresponding service is returned directly.
3. A self-defined load balancing method based on a gateway is characterized by comprising the following steps:
step 1, in a selection method in a self-defined load balancing algorithm class, reading request parameters sent by a client in an analysis selection method, and acquiring a service address IP and a PORT designated by the client in a request head;
step 2, obtaining all the service objects from the service list provider objects, and aggregating and analyzing the service objects to form a key value pair format to be stored in a cache;
step 3, if the client does not specify the service IP and the PORT, randomly selecting a service object from the service list provider objects and returning;
step 4, if the client has the appointed service IP and PORT, and the service objects corresponding to the IP and the PORT do not exist in the key value pair cache, returning an empty object, automatically reporting errors by the gateway and responding to the client;
step 5, if the client has the appointed service IP and PORT, the service objects corresponding to the IP and the PORT exist in the key value pair cache, and the existing service objects are acquired and returned;
and 6, automatically calling the corresponding service according to the returned micro-service object by the gateway so as to realize a self-defined routing mode and load balancing.
4. The gateway-based custom load balancing method according to claim 3, wherein in step 1, when the client requests, it is confirmed whether the request header needs to carry the service IP and the PORT, and then the request is sent to the back end.
5. The gateway-based custom load balancing method according to claim 3, wherein in step 2, the keys store the IP and PORT of the micro service, and the values store the micro service instance object information corresponding to the IP and PORT.
6. The gateway-based custom load balancing method according to claim 3, wherein in step 2, a conversion method in a service list provider lambda expression streaming function built in a gateway service is invoked to obtain a service list set.
7. The gateway-based custom load balancing method according to claim 3, wherein in step 2, a collection method and a grouping method in a streaming function of a service list set are executed, grouping is performed by using a data format of IP + ":" +port as a key, a corresponding value is an object of a service, and a cached data set with IP and PORT as keys and a service object as a value is collected.
8. The gateway-based custom load balancing method according to claim 3, wherein in step 6, load balancing client annotations are added to a gateway service start class, and a service ID requiring the use of a custom load balancing algorithm and a class in which the custom load balancing algorithm is located are set.
9. A gateway-based custom load balancing device, comprising: one or more processors;
a storage means for storing one or more programs, user data;
the one or more programs, when executed by one or more processors, cause the one or more processors to implement the gateway-based custom load balancing method of any of claims 3 to 8.
10. A gateway-based custom load balancing storage medium having stored thereon a computer program which when executed by a processor implements a gateway-based custom load balancing method as claimed in any one of claims 3 to 8.
CN202311169979.0A 2023-09-12 2023-09-12 Custom load balancing device, method, equipment and storage medium based on gateway Pending CN117221325A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311169979.0A CN117221325A (en) 2023-09-12 2023-09-12 Custom load balancing device, method, equipment and storage medium based on gateway

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311169979.0A CN117221325A (en) 2023-09-12 2023-09-12 Custom load balancing device, method, equipment and storage medium based on gateway

Publications (1)

Publication Number Publication Date
CN117221325A true CN117221325A (en) 2023-12-12

Family

ID=89041912

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311169979.0A Pending CN117221325A (en) 2023-09-12 2023-09-12 Custom load balancing device, method, equipment and storage medium based on gateway

Country Status (1)

Country Link
CN (1) CN117221325A (en)

Similar Documents

Publication Publication Date Title
CN109074377B (en) Managed function execution for real-time processing of data streams
CN106131213B (en) Service management method and system
US11775501B2 (en) Trace and span sampling and analysis for instrumented software
CN101902505B (en) Distributed DNS inquiry log real-time statistic device and method thereof
US9298732B2 (en) Searching cloud-based distributed storage resources using a set of expendable probes
US8713182B2 (en) Selection of a suitable node to host a virtual machine in an environment containing a large number of nodes
Kotenko et al. Aggregation of elastic stack instruments for collecting, storing and processing of security information and events
CN111641676B (en) Method and device for constructing third-party cloud monitoring service
CN111314450B (en) Data transmission method and device, electronic equipment and computer storage medium
US7818752B2 (en) Interface for application components
CN114389792B (en) WEB log NAT (network Address translation) front-back association method and system
CN114745295A (en) Data acquisition method, device, equipment and readable storage medium
CN111310230B (en) Spatial data processing method, device, equipment and medium
CN117389830A (en) Cluster log acquisition method and device, computer equipment and storage medium
CN111600929B (en) Transmission line detection method, routing strategy generation method and proxy server
CN113760562A (en) Link tracking method, device, system, server and storage medium
CN114466031B (en) CDN system node configuration method, device, equipment and storage medium
IL268670A (en) Automatic server cluster discovery
CN117221325A (en) Custom load balancing device, method, equipment and storage medium based on gateway
Zhou et al. An interactive and reductive graph processing library for edge computing in smart society
CN114297495A (en) Service data searching method and device, electronic equipment and storage medium
CN114817256A (en) Quick unified storage system of thing networking
CN115129708A (en) Data processing method, data processing device, storage medium and electronic equipment
CN115516842A (en) Orchestration broker service
CN116680061B (en) Task execution method, device, equipment and storage medium

Legal Events

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