Tree Gateway - Service Discovery

Service Discovery

Service Discovery --- name: MyDiscovarableAPI version: 1.0.0 path: discoverable/ proxy: target: router: serviceDiscovery: name: consul options: serviceName: testService loadBalancer: round-robin --- serviceDiscovery: provider: - name: consul options: host: localhost port: 8500 defaults: wait: 30 seconds

This sample uses a service discovery configuration to control calls to the target API.

Consul is being used here as our service discovery provider.

The gateway will check the consul provider to find out available service nodes for the service 'testService'.

Once the gateway knows all the available nodes for a given service, it will use a round-robin algorithm to balance the traffic between them.

Dynamic Service Discovery

Dynamic Service Discovery --- name: MyDiscovarableAPI version: 1.0.0 path: discoverable/ proxy: target: router: middleware: name: trafficSplit options: destinations: - target: testService_v1 weight: 97 - target: testService_v2 weight: 3 serviceDiscovery: name: consul options: serviceName: testService loadBalancer: round-robin timeout: five seconds --- serviceDiscovery: provider: - name: consul options: host: localhost port: 8500 defaults: wait: 30 seconds

This sample is similar to the previous one, but it uses a proxy router middleware to resolve the destination (service name) that will be passed as input to the service discovery middleware.

This configuration will route the requests sending 97% of the requests to the service 'testService_v1' and only 3% for the 'testService_v2'. Then the service discovery middleware will find available nodes for the requested service and use a round-robin load balancer to choose one between these nodes.