Failover
You probably wish to ask what's going to happen if one instance of service discovery breaks down? In order to check how the cluster would behave in case of failure, we are going to modify the earlier sample a little. Now, Zuul has a failover connection to the second service discovery available on port 8762 set in its configuration settings. For testing purposes, we shut down the third instance of the discovery service available on port 8763:
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8763/eureka/,http://localhost:8762/eureka/
registerWithEureka: false
The current situation is illustrated in the following diagram. Testing is performed in the same way as earlier, by calling the gateway's endpoint available under the http://localhost:8765/api/client/ping address. And the result is also the same as for the previous test, load balancing is performed equally among all three client-service instances as expected. Although discovery service #3 has been disabled, two other instances are still able to communicate with each other and have information about the network location of the third client application instance replicated from instance #3 as long as it was active. Now, even if we restart our gateway, it is still able to connect the discovery cluster using the second address in order, set inside the defaultZone field http://localhost:8762/eureka. The same applies to the third instance of the client application, which in turn has discovery service #1 as a backup connection: