org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient Java Examples
The following examples show how to use
org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestRibbonEasyTransRpcConsumerImpl.java From EasyTransaction with Apache License 2.0 | 6 votes |
private void init(ApplicationContext ctx) { loadBalancedRestTemplate = new RestTemplate(); SpringClientFactory springClientFactory = springClientFactory(); springClientFactory.setApplicationContext(ctx); loadBalancerClient = new RibbonLoadBalancerClient(springClientFactory); //custom restTemplate LoadBalancerRequestFactory requestFactory = new LoadBalancerRequestFactory(loadBalancerClient, Collections.emptyList()); LoadBalancerInterceptor interceptor = new LoadBalancerInterceptor(loadBalancerClient, requestFactory); List<ClientHttpRequestInterceptor> interceptors = loadBalancedRestTemplate.getInterceptors(); ArrayList<ClientHttpRequestInterceptor> customedInterceptors = new ArrayList<>(interceptors.size() + 1); customedInterceptors.addAll(interceptors); customedInterceptors.add(interceptor); loadBalancedRestTemplate.setInterceptors(customedInterceptors); }
Example #2
Source File: CamelCloudNetflixServiceLoadBalancerAutoConfigurationTest.java From camel-spring-boot with Apache License 2.0 | 5 votes |
@Test public void testAutoConfiguration() { new ApplicationContextRunner() .withConfiguration( AutoConfigurations.of( CamelAutoConfiguration.class, CamelCloudAutoConfiguration.class, CamelSpringCloudServiceRegistryAutoConfiguration.class, CamelCloudNetflixServiceLoadBalancerAutoConfiguration.class, RibbonAutoConfiguration.class, RibbonClientConfiguration.class )) .withUserConfiguration( TestConfiguration.class) .withPropertyValues( "debug=true", "spring.main.banner-mode=off", "ribbon.client.name=test") .run( context -> { assertThat(context).hasSingleBean(LoadBalancerClient.class); assertThat(context).getBean(LoadBalancerClient.class).isInstanceOf(RibbonLoadBalancerClient.class); assertThat(context).hasSingleBean(CamelSpringCloudServiceLoadBalancer.LoadBalancerClientAdapter.class); LoadBalancerClient client = context.getBean(LoadBalancerClient.class); ServiceLoadBalancer balancer = context.getBean(CamelSpringCloudServiceLoadBalancer.LoadBalancerClientAdapter.class).adapt(client); assertThat(balancer).isInstanceOf(CamelCloudNetflixServiceLoadBalancer.class); } ); }
Example #3
Source File: LbIsolationFilter.java From microservices-platform with Apache License 2.0 | 5 votes |
@Override protected ServiceInstance choose(ServerWebExchange exchange) { String vresion = exchange.getRequest().getHeaders().getFirst(CommonConstant.Z_L_T_VERSION); if (StrUtil.isNotEmpty(vresion)) { if (this.loadBalancer instanceof RibbonLoadBalancerClient) { RibbonLoadBalancerClient client = (RibbonLoadBalancerClient) this.loadBalancer; String serviceId = ((URI) exchange.getAttribute(GATEWAY_REQUEST_URL_ATTR)).getHost(); return client.choose(serviceId, vresion); } } return super.choose(exchange); }