Search in sources :

Example 6 with ZoneAffinityServerListFilter

use of com.netflix.loadbalancer.ZoneAffinityServerListFilter in project nutzboot by nutzam.

the class FeignStarter method getLoadBalancer.

public Object getLoadBalancer(String name, FeignInject fc) {
    EurekaClient eurekaClient = ioc.get(EurekaClient.class, "eurekaClient");
    DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.getClientConfigWithDefaultValues(name);
    ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList(name, () -> eurekaClient);
    ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(clientConfig);
    ServerListUpdater updater = new EurekaNotificationServerListUpdater(() -> eurekaClient);
    IRule rule = null;
    switch(getLbRuleString(fc.lbRule())) {
        case "random":
            rule = new RandomRule();
            break;
        case "availability":
        default:
            AvailabilityFilteringRule _rule = new AvailabilityFilteringRule();
            _rule.initWithNiwsConfig(clientConfig);
            rule = _rule;
            break;
    }
    ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder().withDynamicServerList(list).withRule(rule).withServerListFilter(filter).withServerListUpdater(updater).withClientConfig(clientConfig).buildDynamicServerListLoadBalancerWithUpdater();
    return LBClient.create(lb, clientConfig);
}
Also used : DiscoveryEnabledNIWSServerList(com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) EurekaClient(com.netflix.discovery.EurekaClient) RandomRule(com.netflix.loadbalancer.RandomRule) IRule(com.netflix.loadbalancer.IRule) ServerListUpdater(com.netflix.loadbalancer.ServerListUpdater) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl)

Aggregations

ZoneAffinityServerListFilter (com.netflix.loadbalancer.ZoneAffinityServerListFilter)6 Test (org.junit.Test)5 DynamicServerListLoadBalancer (com.netflix.loadbalancer.DynamicServerListLoadBalancer)4 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)3 LoadBalancerStats (com.netflix.loadbalancer.LoadBalancerStats)3 ArrayList (java.util.ArrayList)3 IRule (com.netflix.loadbalancer.IRule)2 Server (com.netflix.loadbalancer.Server)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 IClientConfig (com.netflix.client.config.IClientConfig)1 EurekaClient (com.netflix.discovery.EurekaClient)1 DummyPing (com.netflix.loadbalancer.DummyPing)1 ILoadBalancer (com.netflix.loadbalancer.ILoadBalancer)1 RandomRule (com.netflix.loadbalancer.RandomRule)1 RoundRobinRule (com.netflix.loadbalancer.RoundRobinRule)1 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)1 DiscoveryEnabledNIWSServerList (com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList)1 DiscoveryEnabledServer (com.netflix.niws.loadbalancer.DiscoveryEnabledServer)1 EurekaNotificationServerListUpdater (com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater)1