Client-Side Load Balancing with RibbonNetflix RibbonNetflix Ribbon is a Part of Netflix Open Source Software (Netflix OSS). It is a cloud library that provides the client-side load balancing. It automatically interacts with Netflix Service Discovery (Eureka) because it is a member of the Netflix family. The Ribbon mainly provides client-side load balancing algorithms. It is a client-side load balancer that provides control over the behavior of HTTP and TCP client. The important point is that when we use Feign, the Ribbon also applies. Features of Ribbon
Modules
Types of Load Balancing:There are two types of load balancing
Let's configure the Ribbon server in our project. Step 1: Go to the project currency-conversion-service. Step 2: Open pom.xml file and add the ribbon dependency. After adding the dependency, we need to enable ribbon on the proxy. Step 3: Open the CurrencyExchangeServiceProxy.java file. Enable Ribbon by adding an annotation @RibbonClient and specify the name of the service which we want to talk to. Ribbon client provide the declarative configuration for a client. CurrencyExchangeServiceProxy.java Step 4: In the annotation @FeignClient, remove the attribute URL. Because we do not need to talk with one particular service. We will configure that URL in the application.properties file. Step 5: Open the application.properties file of the project currency-conversion-service and configure the servers. The property that we have to configure is: We have configured the two instances of currency-exchange-service that we want to invoke. application.properties Running Client Side Load Balancing with RibbonWe have two instances of CurrentlyExchangeServiceApplication.java, as shown in the following image: First, run the CurrencyExchangeServiceApplication on port 8000 and then run the CurrencyExchangeServiceApplication on port 8001. After running the CurrencyExchangeServiceApplication on both the ports, run the CurrencyConversionServiceApplication.java by sending the request http://localhost:8100/currency-converter-feign/from/EUR/to/INR/quantity/10000. It returns the following response. In the above image, the port 8000 represents that the currency-exchange-service is running on port 8000 and handling the current request. Now, refresh the page. We get the same response except for the port number and quantity because we have changed the quantity in the request. In the above image, the port 8001 represents that the currency-exchange-service is running on port 8001 and handling the current request. Let's understand the load balancing through a figure: In the above figure, Ribbon is distributing the load between three active CurrencyExchangeServices. The CurrencyExchangeService1 is running on port 8000, and CurrencyExchangeService2 is running on port 8001, and so on. So whatever calls are made using Ribbon through the CurrencyCalculationService, are distributed among these three services. Next TopicEureka Naming Server |