Implementation

We will add Ribbon to service consumer microservice. The service consumer microservice will distribute the load among two instances of Microservice A.

Let's start with adding the Ribbon dependency to the pom.xml file of service consumer microservice:

    <dependency>      <groupId>org.springframework.cloud</groupId>      <artifactId>spring-cloud-starter-ribbon</artifactId>    </dependency>

Next, we can configure the URLs for the different instances of Microservice A. Add the following configuration to application.properties in service consumer microservice:

    random-proxy.ribbon.listOfServers=       http://localhost:8080,http://localhost:8081

We will then specify the @RibbonClient annotation on the service proxy--RandomServiceProxy in this example. ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.