Using New Spring Cloud Load Balancer In Microservices Communication

Almost a year ago Spring Cloud has announced that most of Spring Cloud Netflix OSS projects will be moved to the maintenance mode starting from Spring Cloud Greenwich Release Train. In fact the maintenance mode only does not include Eureka, which still will be supported. I referred to that information in one of my previous articles The Future of Spring Cloud Microservices After Netflix Era. I have shared there some opinions about future of microservices with Spring Cloud. Of course, I also included an example of building microservices architecture without Netflix OSS using HashiCorp’s Consul, Spring Cloud Gateway and an early version of Spring Cloud LoadBalancer.

Today, the currently developed version of Spring Cloud Released Train is Hoxton (the next after Greenwich), so I decided get back on track and update my example of microservices shared in the previous article. It might be slightly surprising, but I could find any working example presenting usage of new built-in Spring Cloud LoadBalancer on the Internet. Probable the reason is that it is still under active development. However, I was able to build working example with auto-configured load balancer, without any additional part of source code. Let’s take a look.

Release Train

The Release Train version used in this article is Hoxton.M2. To access it we need to use Spring Milestone repository.

		<name>Spring Milestones</name>
		<name>Spring Milestones</name>

Here’s declaration of release train inside dependency management section:



Besides standard Spring Boot Web Starter we need to include starters for Consul discovery and config client, and of course spring-cloud-loadbalancer library. We should remember about excluding Ribbon and Hystrix artifacts from spring-cloud-starter-consul-discovery starter.


Sample Applications

We have three sample applications. First callme-service exposes some REST endpoints, second caller-service communicates with the first using Consul discovery, RestTemplate and Spring Cloud Loadbalancer, and third gateway-service acts as API gateway in our architecture.


The repository with source code snippets is available on GitHub: For some configuration details related to Consul discovery please refer to my previous article. In fact we don’t have to provide any additional code to make it working. We just have to declare RestTemplate bean annotated with @LoadBalanced:

public class CallerApplication {

   public static void main(String[] args) {, args);

   RestTemplate template() {
      return new RestTemplate();

Then we may call the target service using its name taken from the discovery server:

public class CallerController {

	private static final Logger LOGGER = LoggerFactory.getLogger(CallerController.class);

	Environment environment;
	RestTemplate template;

	public String call() {
		String url = "http://callme-service/callme";
		String callmeResponse = template.getForObject(url, String.class);"Response: {}", callmeResponse);
		return "I'm Caller running on port " + environment.getProperty("local.server.port")
				+ " calling-> " + callmeResponse;


In this article I show you a working example of communication between microservices using new Spring Cloud Load Balancer. I also tried to use that load balancer instead of Spring Cloud Netflix Ribbon inside my application with Spring Cloud Gateway – with no success. According to the newest documentation of Spring Cloud Circuit Breaker build on top of Resilience4J I tried to include circuit breaker in the communication between caller-service and callme-service – also with no success. These new Spring Cloud features are still under active development. I hope to use them succesfully in my applications soon.

9 thoughts on “Using New Spring Cloud Load Balancer In Microservices Communication

  1. You can see this talk here

    to check out how to use the newest recommended stack which includes working SC Load Balancer, SC Circuit Breaker and Resilience4J.


    1. The presentation is ok, however the problem is that it still doesn’t work with Consul-based discovery on Spring Cloud Gateway. They show examples with Eureka discovery – but my article was not about it.


  2. Nice article Piotr.
    I am currently working on a spring boot project using spring cloud zuul (not nee cloud gateway) and I wonder if it is possible to integrate new spring cloud load balancer (instead of ribbon).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.