Setup Client Side Load Balancing With Ribbon

in prvious video we have imvoked the currencyExchangeService From our CurrencyCalculationService to calculate the Currency by the quentry and there currnecy exchange

in last step we added Feign to make calling the currencyExchangeService from currencyExchangeService very easily 

  



So in given Above you can see in Currncy Conversion service we have only 1 Prod instance while Currency Exchange Service we have 4 instances so now hile Conversion service trying to call the Exchange service than we have to load balance means we would need to distribute the load between all these instance 

Thats where Ribbon Comes into the Picture
We were using Feing to call Currency Exchange Service

Ribbon can make use of the Feign Configuration, that we have already done in previous tutotial
and Help us Distirubution the calls between diffrent instances (prod1, prod2 , prod3, prod4) of currency exchange prod service

When we enable Ribbon we will see the load will be distributed between the diffrent instances of the currency exchange 

STEP 1:
Lets go to the Pom.xml of CurrencyConversionService

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>

<version>1.4.7.RELEASE</version>

</dependency>

now we have Ribbon


STEP 2: Add Given below annotation at CurrencyExchangeServiceProxy Interface

@RibbonClient(name="currency-exchange-service")


Also Fiegn not need the URL for now

@FeignClient(name="currency-exchange-service")

@RibbonClient(name="currency-exchange-service")


becasuse the URL we would configure it in a different way, as now we dont want to talk to only

single instance or specific one instance

but we would want to distributed the load between multiple instances of the Currency

Exchange Service

So for that we will do the configuration in the application properties


STEP 3:

add properties in application.properties

currency-conversion-service.ribbon.listOfServers=http://localhost:8000,http://localhost:8001



Comments

Popular posts from this blog

Microservice with Java Spring Cloud

STEP 10 Configure Porfile for Limit service

STEP 9 Connect Limit service to Spring Cloud Config Server