How to create Client Load Balancing with Spring Cloud Ribbon + Spring Boot
Tags: springboot, springcloud, ribbon
Published: 2021-04-22 13:10:50

https://grokonez.com/spring-framework/spring-cloud/create-client-load-balancing-spring-cloud-ribbon-spring-boot

How to create Client Load Balancing with Spring Cloud Ribbon + Spring Boot


In the tutorial, <strong>JavaSampleApproach</strong> will show you the steps of creating a <strong>Client Load Balancing</strong> with <strong>Spring Cloud Ribbon</strong>.

Related articles:
- <a href="https://grokonez.com/spring-framework/spring-boot/configure-springboot-zuul-routing-filtering">How to configure SpringBoot Zuul – Routing and Filtering</a>
- <a href="https://grokonez.com/java-integration/start-spring-cloud-centralized-configuration">How to start with Spring Cloud Centralized Configuration</a>

<!--more-->
<iframe width="853" height="480" src="https://www.youtube.com/embed/20oWFLtr6NM?rel=0" frameborder="0" allowfullscreen></iframe>
<div id="tuttoc" class="jsa-toc"></div>

<div id="tutcontents">
<h2>I. Technologies</h2>
– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.1.RELEASE
<h2>II. Load Balancer</h2>
<h3>1. Proxy Load Balancer</h3>
<img src="https://grokonez.com/wp-content/uploads/2017/05/spring-cloud-ribbon-proxy-load-balancer.png" alt="spring cloud ribbon - proxy load balancer" width="598" height="395" class="alignnone size-full wp-image-5016" />

<strong>Advantage & Disadvantage</strong>:
- Centralized Load Balancing
- Can be bottle neck
- Single point of failure
<h3>2. Client Load Balancer</h3>
<strong>Spring Cloud Ribbon</strong> is a solution for <strong>Client Load Balancing</strong>.

<img src="https://grokonez.com/wp-content/uploads/2017/05/spring-cloud-ribbon-ribbon-load-balancer.png" alt="spring cloud ribbon - ribbon load balancer" width="534" height="347" class="alignnone size-full wp-image-5017" />

<strong>Advantage & Disadvantage</strong>:
- Decentralized Load Balancing
- No bottle neck
- Resilent
- Data can be inconsistent
<h2>III. Practice</h2>
Create 2 projects:
- a Spring Boot project for simple restful services, running at addresses: <code>{localhost:8090,localhost:8091,localhost:8092}</code>
- a Spring Boot project for <strong>Load Balancing</strong> - <strong>Ribbon Client</strong>, running at address: <code>localhost:8080</code>

<strong>Step to do:</strong>
- Create Spring Boot project for simple <strong>Restful service</strong> 
- Create Spring Boot project for <strong>Ribbon client</strong>
- Config <strong>Ribbon client</strong>
- Create a <strong>Load Balancing</strong> Rest controller
- Run & check results
<h3>1. Create Spring Boot project for simple Restful service</h3>
- Using <strong>SpringToolSuite</strong>, create a SpringBoot project. Then add <strong>web</strong> dependency:
<pre><code class="language-html">
&lt;dependency&gt;
	&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
	&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>

- Create a simple <strong>RestController</strong> with 2 requestmappings:

More at:

https://grokonez.com/spring-framework/spring-cloud/create-client-load-balancing-spring-cloud-ribbon-spring-boot

How to create Client Load Balancing with Spring Cloud Ribbon + Spring Boot