-
Notifications
You must be signed in to change notification settings - Fork 44
loadBalancer
This router middleware needs to receive an options object containing the possible targets for the routed API. This object contains the following properties.
Property | Type | Description | Required |
---|---|---|---|
destinations | TrafficDestination[] | A list with possible destinations for the API request. | true |
database | DatabaseConfig | Provide a database configuration to the balancer looks for changes in the targets configurations. | false |
strategy |
round-robin or random or weight
|
The balancer strategy to be used. The dafilt value is random . |
false |
healthCheckOptions | HealthCheckOptions | Configure the health checkers. | false |
Configure a single destination for the balancer. Can contain the following properties:
Property | Type | Description | Required |
---|---|---|---|
target | string | A target destination. | true |
weight | number | A weight to distribute the load to this target. | true |
healthCheck | string | An URL to be used to check the health of this target. It must return a 200 status code, or the balancer will supose that the target is down. If not provided, no health checking will be performed. | false |
Configure a database to be used to store configuration for the filter. Is the configuration changes on the database, the filter will be updated. Support the following properties:
Property | Type | Description | Required |
---|---|---|---|
key | string | The configuration key to be used in database config table. Defaults to ipFilter:whitelist or ipFilter:blacklist
|
false |
checkInterval | string or number | The interval between database checks for changes in the configurations. You can inform the amount of milisencods, or use a human-interval string. Defaults to '30 seconds' . |
false |
Configure how the gateway will perform checks for services health. Support the following properties:
Property | Type | Description | Required |
---|---|---|---|
checkInterval | string or number | The interval between healthchecks. You can inform the amount of milisencods, or use a human-interval string. Defaults to '30 seconds' . |
false |
waitTimeout | string or number | The amount of time to wait for healthcheck requests before fail with a tiemout. You can inform the amount of milisencods, or use a human-interval string. Defaults to '2 seconds' . |
false |
failCount | number | The number of healthcheck failures before remove the server from the available list. Defaults to 2. | false |
Example:
---
name: TestLoadBalancerAPI
version: 1.0.0
path: "/loadBalancer"
proxy:
target:
router:
middleware:
name: loadBalancer
options:
destinations:
- target: http://httpbin.org
weight: 75
healthCheck: http://httpbin.org/get
- target: http://httpbin.org/anything
weight: 25
healthCheck: http://httpbin.org/anything/get
database:
checkInterval: 5 minutes
strategy: weight
healthCheckOptions:
checkInterval: 5 seconds
failCount: 3
waitTimeout: 5 seconds
timeout: 5000
This configuration will route requests to http://httpbin.org
and to http://httpbin.org/anything
. The first target will receive a bigger load (3 times greater than the second one). It will use a database to be able to change the configuration dynamically and a health check will be performed to avoid traffic redirection to unavailable servers.
Round-robin example:
---
name: TestLoadBalancerAPI
version: 1.0.0
path: "/loadBalancer"
proxy:
target:
router:
middleware:
name: loadBalancer
options:
destinations:
- target: http://httpbin.org
healthCheck: http://httpbin.org/get
- target: http://httpbin.org/anything
healthCheck: http://httpbin.org/anything/get
database:
checkInterval: 5 minutes
strategy: round-robin
timeout: 5000