use of com.netflix.loadbalancer.ZoneAwareLoadBalancer in project camel by apache.
the class RibbonLoadBalancer method createLoadBalancer.
// ************************
// Helpers
// ************************
private ZoneAwareLoadBalancer<RibbonServiceDefinition> createLoadBalancer(String serviceName, ServiceDiscovery serviceDiscovery) {
// setup client config
IClientConfig config = configuration.getClientName() != null ? IClientConfig.Builder.newBuilder(configuration.getClientName()).build() : IClientConfig.Builder.newBuilder().build();
if (configuration.getClientConfig() != null) {
for (Map.Entry<String, String> entry : configuration.getClientConfig().entrySet()) {
IClientConfigKey key = IClientConfigKey.Keys.valueOf(entry.getKey());
String value = entry.getValue();
LOGGER.debug("RibbonClientConfig: {}={}", key.key(), value);
config.set(key, value);
}
}
return new ZoneAwareLoadBalancer<>(config, configuration.getRuleOrDefault(RoundRobinRule::new), configuration.getPingOrDefault(DummyPing::new), new RibbonServerList(serviceName, serviceDiscovery, serviceFilter), null, new PollingServerListUpdater(config));
}
use of com.netflix.loadbalancer.ZoneAwareLoadBalancer in project spring-cloud-netflix by spring-cloud.
the class EurekaRibbonClientConfigurationTests method basicConfigurationCreatedForLoadBalancer.
@Test
@Ignore
public void basicConfigurationCreatedForLoadBalancer() {
EurekaClientConfigBean client = new EurekaClientConfigBean();
EurekaInstanceConfigBean configBean = getEurekaInstanceConfigBean();
client.getAvailabilityZones().put(client.getRegion(), "foo");
SpringClientFactory clientFactory = new SpringClientFactory();
EurekaRibbonClientConfiguration clientPreprocessor = new EurekaRibbonClientConfiguration(client, "service", configBean, false);
clientPreprocessor.preprocess();
ILoadBalancer balancer = clientFactory.getLoadBalancer("service");
assertNotNull(balancer);
@SuppressWarnings("unchecked") ZoneAwareLoadBalancer<DiscoveryEnabledServer> aware = (ZoneAwareLoadBalancer<DiscoveryEnabledServer>) balancer;
assertTrue(aware.getServerListImpl() instanceof DomainExtractingServerList);
assertEquals("foo", ConfigurationManager.getDeploymentContext().getValue(ContextKey.zone));
}
use of com.netflix.loadbalancer.ZoneAwareLoadBalancer in project spring-cloud-netflix by spring-cloud.
the class RibbonClientConfigurationIntegrationTests method testLoadBalancerConstruction.
@Test
public void testLoadBalancerConstruction() {
ILoadBalancer loadBalancer = clientFactory.getInstance("test", ILoadBalancer.class);
assertThat(loadBalancer, is(instanceOf(ZoneAwareLoadBalancer.class)));
ZoneAwareLoadBalancer lb = (ZoneAwareLoadBalancer) loadBalancer;
ServerListUpdater serverListUpdater = (PollingServerListUpdater) ReflectionTestUtils.getField(loadBalancer, "serverListUpdater");
Long refreshIntervalMs = (Long) ReflectionTestUtils.getField(serverListUpdater, "refreshIntervalMs");
// assertThat(refreshIntervalMs, equalTo(999L));
ServerListUpdater updater = clientFactory.getInstance("test", ServerListUpdater.class);
assertThat(updater, is(sameInstance(serverListUpdater)));
}
use of com.netflix.loadbalancer.ZoneAwareLoadBalancer in project ribbon by Netflix.
the class SampleApp method main.
public static void main(String[] args) throws Exception {
// 1
ConfigurationManager.loadPropertiesFromResources("sample-client.properties");
System.out.println(ConfigurationManager.getConfigInstance().getProperty("sample-client.ribbon.listOfServers"));
// 2
RestClient client = (RestClient) ClientFactory.getNamedClient("sample-client");
// 3
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
for (int i = 0; i < 20; i++) {
// 4
HttpResponse response = client.executeWithLoadBalancer(request);
System.out.println("Status code for " + response.getRequestedURI() + " :" + response.getStatus());
}
ZoneAwareLoadBalancer lb = (ZoneAwareLoadBalancer) client.getLoadBalancer();
System.out.println(lb.getLoadBalancerStats());
ConfigurationManager.getConfigInstance().setProperty("sample-client.ribbon.listOfServers", // 5
"www.linkedin.com:80,www.google.com:80");
System.out.println("changing servers ...");
// 6
Thread.sleep(3000);
for (int i = 0; i < 20; i++) {
HttpResponse response = client.executeWithLoadBalancer(request);
System.out.println("Status code for " + response.getRequestedURI() + " : " + response.getStatus());
}
// 7
System.out.println(lb.getLoadBalancerStats());
}
use of com.netflix.loadbalancer.ZoneAwareLoadBalancer in project ribbon by Netflix.
the class SampleApp method main.
public static void main(String[] args) throws Exception {
// 1
ConfigurationManager.loadPropertiesFromResources("sample-client.properties");
System.out.println(ConfigurationManager.getConfigInstance().getProperty("sample-client.ribbon.listOfServers"));
// 2
RestClient client = (RestClient) ClientFactory.getNamedClient("sample-client");
// 3
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/")).build();
for (int i = 0; i < 20; i++) {
// 4
HttpResponse response = client.executeWithLoadBalancer(request);
System.out.println("Status code for " + response.getRequestedURI() + " :" + response.getStatus());
}
@SuppressWarnings("rawtypes") ZoneAwareLoadBalancer lb = (ZoneAwareLoadBalancer) client.getLoadBalancer();
System.out.println(lb.getLoadBalancerStats());
ConfigurationManager.getConfigInstance().setProperty("sample-client.ribbon.listOfServers", // 5
"www.linkedin.com:80,www.google.com:80");
System.out.println("changing servers ...");
// 6
Thread.sleep(3000);
for (int i = 0; i < 20; i++) {
HttpResponse response = null;
try {
response = client.executeWithLoadBalancer(request);
System.out.println("Status code for " + response.getRequestedURI() + " : " + response.getStatus());
} finally {
if (response != null) {
response.close();
}
}
}
// 7
System.out.println(lb.getLoadBalancerStats());
}
Aggregations