org.springframework.cloud.client.loadbalancer.LoadBalancerRequestFactory Java Examples

The following examples show how to use org.springframework.cloud.client.loadbalancer.LoadBalancerRequestFactory. 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 vote down vote up
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);
}