Service discovery and load balancing in practice

Now we will write some code to interact with our service discovery and load balance infrastructure. Now we know how it works, it will help us to understand the source code.

We will create a DiscoveryService class which will discover the addresses from a requested service name. The class code should be like this:

package springfive.airline.airlineflights.service;import org.springframework.cloud.client.discovery.DiscoveryClient;import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;import org.springframework.stereotype.Service;import reactor.core.publisher.Flux;import reactor.core.publisher.Mono;@Servicepublic class DiscoveryService {  private final LoadBalancerClient lbClient ...

Get Developing Java Applications with Spring and Spring Boot 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.