Questions Management – Load balancing using Ribbon of Spring Cloud Netflix

Check out the full series of Questions Management tutorial here.

I introduced you to client load balancing using Spring Cloud Ribbon with its benefits. To ensure High Availability for services in the Questions Management application, I will apply the client load balancing using Spring Cloud Ribbon to those services that call other services.

Services that call other services in the Questions Management application are services that are in the API Service and Composite Service. To apply Spring Cloud Ribbon, I will open the pom.xml file of each service project and add Spring Cloud Ribbon dependency as follows:

Next, we will modify the code to apply the client load balancing for the service project using the Ribbon.

We will modify the API Category Service first!

This service calls the Core Category Service in the CoreCategoryServiceImpl class so I will autowire the interface LoadBalancerClient into this class and then edit the getServiceUrl() method as follows:

Because now we don’t use the coreCategoryServiceUrl variable anymore, I will also remove this variable and the “corecategoryservice.url” property in the application.properties file.

Same for the API Option Service

CompositeOptionServiceImpl:

CoreOptionServiceImpl:

Same for API Question Service

CompositeQuestionServiceImpl:

Same for Composite Option Service

CoreOptionServiceImpl:

CoreQuestionServiceImpl:

Same for Composite Question Service

CoreCategoryServiceImpl:

CoreOptionServiceImpl:

CoreQuestionServiceImpl:

Rerun the Questions Management application, you will see the features we have built are working normally.

Add Comment