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 PDFInfo
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 30
- 238000010187 selection method Methods 0.000 claims abstract description 8
- 230000004931 aggregating effect Effects 0.000 claims abstract description 4
- 238000006243 chemical reaction Methods 0.000 claims description 4
- 238000004590 computer program Methods 0.000 claims description 2
- 238000010586 diagram Methods 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000013507 mapping Methods 0.000 description 1
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
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.
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) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118524139A (en) * | 2024-05-10 | 2024-08-20 | 佛山众陶联供应链服务有限公司 | Method and system for forwarding Android application request to different environments and designating ip service |
-
2023
- 2023-09-12 CN CN202311169979.0A patent/CN117221325A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118524139A (en) * | 2024-05-10 | 2024-08-20 | 佛山众陶联供应链服务有限公司 | Method and system for forwarding Android application request to different environments and designating ip service |
CN118524139B (en) * | 2024-05-10 | 2025-02-25 | 佛山众陶联供应链服务有限公司 | Method and system for forwarding Android application requests to different environments and designated IP services |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106131213B (en) | Service management method and system | |
CN111258978B (en) | Data storage method | |
US8713182B2 (en) | Selection of a suitable node to host a virtual machine in an environment containing a large number of nodes | |
CN111641676B (en) | Method and device for constructing third-party cloud monitoring service | |
CN101902505B (en) | A real-time statistical device and method for distributed DNS query logs | |
US20120078948A1 (en) | Systems and methods for searching a cloud-based distributed storage resources using a set of expandable probes | |
Kotenko et al. | Aggregation of elastic stack instruments for collecting, storing and processing of security information and events | |
CN111314450B (en) | Data transmission method and device, electronic equipment and computer storage medium | |
US7818752B2 (en) | Interface for application components | |
US20200042424A1 (en) | Method, apparatus and system for processing log data | |
CN102081605A (en) | Data warehouse-based data encapsulation device and service data acquisition method | |
CN114745295A (en) | Data acquisition method, device, equipment and readable storage medium | |
CN114389792B (en) | WEB log NAT (network Address translation) front-back association method and system | |
CN111752681A (en) | Request processing method, apparatus, server, and computer-readable storage medium | |
CN109298937A (en) | File parsing method and network device | |
CN117389830A (en) | Cluster log acquisition method and device, computer equipment and storage medium | |
CN117221325A (en) | Custom load balancing device, method, equipment and storage medium based on gateway | |
EP3306471B1 (en) | Automatic server cluster discovery | |
CN111310230B (en) | Spatial data processing method, device, equipment and medium | |
CN114301988B (en) | Distributed calling method, device, storage medium and electronic device | |
CN111600929B (en) | Transmission line detection method, routing strategy generation method and proxy server | |
CN117807344A (en) | Method and device for constructing IP database | |
CN116680061A (en) | Task execution method, device, equipment and storage medium | |
Zhou et al. | An interactive and reductive graph processing library for edge computing in smart society | |
CN115757570A (en) | Log data analysis method and device, electronic equipment and 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 |