Implementation

We will add Hystrix to our service consumer microservice and enhance the add service to return a basic response even when Microservice A is down.

We will start with adding Hystrix Starter to the pom.xml file of service consumer microservice. The following snippet shows the dependency details:

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

Next, we would enable Hystrix auto-configuration by adding the @EnableHystrix annotation to the ServiceConsumerApplication class. The following snippet shows the details:

    @SpringBootApplication    @EnableFeignClients("com.mastering.spring.consumer")    @EnableHystrix    @EnableDiscoveryClient public class ServiceConsumerApplication ...

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.