Skip to content

Programmers Guide

allenxwang edited this page Jan 26, 2013 · 17 revisions

Client Configuration Options

The easiest way to configure client and load balancer is through loading properties into Archaius that conform to the specific format:


<clientName>.<nameSpace>.<propertyName>=<value>

You can define properties in a file on classpath or as system properties. If former, ConfigurationManager.loadPropertiesFromResources() API should be called to load the file.

By default, “ribbon” should be the nameSpace.

If there is no property specified for a named client, ClientFactory will still create the client and load balancer with default values for all necessary properties. The default values are specified in DefaultClientConfigImpl.

If a property is missing the clientName, it is interpreted as a property that applies to all clients.

for example


ribbon.ReadTimeout=1000

This will establish the default ReadTimeout property for all clients.

You can also programmatically set properties by constructing instance of DefaultClientConfigImpl and set all required properties by calling its setProperty() API. Then pass this instance together with client name to proper ClientFactory API.

If it is desired to have properties defined in a different name space, for example, “foo”


myclient.foo.ReadTimeout=1000

you should use DefaultClientConfigImpl(String nameSpace) constructor – in this case DefaultClientConfigImpl(“foo”) – and pass the instance to ClientFactory.


Implement your own client with load balancer support

You need to extend com.netflix.client.AbstractLoadBalancerAwareClient and implement a few methods. Specifically, IClient.execute() method should be implemented to carry out protocol specific operations.

AbstractLoadBalancerAwareClient takes care of the load balancer integration, retry logic, and collection of statistics that is used as input to load balancer algorithms and for monitoring.


Integration with Eureka

Eureka provides service discovery functionality and can be integrated with ribbon to provide dynamic list of servers. To use Eureka with ribbon, follow these steps:

  • Include ribbon-eureka in your dependency
  • (Done by default) Enable the load balancer for the client and configure the load balancer to be DynamicServerListLoadBalancer or its sub class. This is true by default.
  • Configure the ServerList to be com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList
  • Configure the server refresh rate. (optional, default is 30 seconds)

Here is an example


myclient.ribbon.NIWSServerListClassName=com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList

# refresh every minute 
myclient.ribbon.ServerListRefreshInterval=60000

In addition, your need to have proper configuration files for Eureka client. See here.