From a7398842078319dcaa353a708c12bb7b9fa85a4e Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Thu, 29 Jan 2015 09:55:17 -0700 Subject: [PATCH] added preferIpAddress section to eureka and updated ribbon docs to show what beans are created by default and how to override them. --- .../main/asciidoc/spring-cloud-netflix.adoc | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/docs/src/main/asciidoc/spring-cloud-netflix.adoc b/docs/src/main/asciidoc/spring-cloud-netflix.adoc index cc0e1aba..e5970a6d 100644 --- a/docs/src/main/asciidoc/spring-cloud-netflix.adoc +++ b/docs/src/main/asciidoc/spring-cloud-netflix.adoc @@ -308,6 +308,13 @@ the registrations amongst themselves. If the peers are physically separated (inside a data centre or between multiple data centres) then the system can in principle survive split-brain type failures. +=== Prefer IP Address + +In some cases, it is preferable for Eureka to advertise the IP Adresses +of services rather than the hostname. Set `eureka.instance.preferIpAddress` +to `true` and when the application registers with eureka, it will use its +IP Address rather than its hostname. + == Circuit Breaker: Hystrix Clients Netflix has created a library called https://github.com/Netflix/Hystrix[Hystrix] that implements the http://martinfowler.com/bliki/CircuitBreaker.html[circuit breaker pattern]. In a microservice architecture it is common to have multiple layers of service calls. @@ -519,6 +526,41 @@ In this case the client is composed from the components already in `RibbonClientConfiguration` together with any in `FooConfiguration` (where the latter generally will override the former). +Spring Cloud Netflix provides the following beans by default for ribbon +(`BeanType` beanName: `ClassName`): + +* `IClientConfig` ribbonClientConfig: `DefaultClientConfigImpl` +* `IRule` ribbonRule: `ZoneAvoidanceRule` +* `IPing` ribbonPing: `NoOpPing` +* `ServerList ribbonServerList: `ConfigurationBasedServerList` +* `ServerListFilter` ribbonServerListFilter: `ZonePreferenceServerListFilter` +* `ILoadBalancer` ribbonLoadBalancer: `ZoneAwareLoadBalancer` + +Creating a bean of one of those type and placing it in a `@RibbonClient` +configuration (such as `FooConfiguration` above) allows you to override each +one of the beans described. Example: + +[source,java,indent=0] +---- + @Configuration + public class FooConfiguration { + @Bean + public IPing ribbonPing(IClientConfig config) { + return new PingUrl(); + } + } +---- + +This replaces the `NoOpPing` with `PingUrl`. + +=== Using the Ribbon with Eureka + +When Eureka is used in conjunction with Ribbon the `ribbonServerList` is +overridden with an extension of `DiscoveryEnabledNIWSServerList` which +populates the list of servers from Eureka. It also replaces the `IPing` +interface with `NIWSDiscoveryPing` which delegates to Eureka to determine if +a server is up. + === Using the Ribbon API Directly You can also use the `LoadBalancerClient` directly. Example: