Load balancing using RestTemplate

Spring Cloud also supports the implementation of load balancing using RestTemplate. In this case, you need to expose the RestTemplate instance with load balancing capabilities instead of using it directly, as follows: 

@LoadBalanced
@Bean
RestTemplate restTemplate() {
    return new RestTemplate();
}

@Autowired
RestTemplate restTemplate;

In the previous case, the @LoadBalanced annotation will do the magic of balancing the load between the instances of other services to which we make a REST call. You need to inject this object in your controller and make the call with it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.137.218