no

Learn Circuit Breaking Pattern With Netflix Hystrix

Go Back to Course Outline Introduction In this video, we will learn how to use Hystrix to solve the problem that comes with a distri...


Go Back to Course Outline

Introduction

In this video, we will learn how to use Hystrix to solve the problem that comes with a distributed microservice architecture, like in the project that we have. And these problems are fault and latency tolerance. 

Looking at our business API service, it is fetching data from both catalog and inventory service. But what if those services failed, or the response is delayed? It will affect the overall integrity of the application or even worst it might bring the whole system down.

And that is where Hystrix comes in, it wraps the call to remote services and handles the exception or return a default or computed value.

Setting up Hystrix

  1. Add a dependency to spring-cloud-starter-netflix-hystrix.
  2. Annotate the SpringBoot class with @EnableHystrix.
  3. Set the timeout in application.properties.
    1. feign.client.config.default.connect-timeout=5000
    2. feign.client.config.default.read-timeout=5000
  4. There are 2 ways to use Hystrix with Spring:
    1. Via annotating FeignClient with fallback property
    2. Via annotating FeignClient with fallbackFactory

Project Architecture Review

Using the fallback Property

See the CatalogServiceProxy class below.

CatalogServiceFallback Class

See CatalogServiceFallback class below.

Using the fallbackFactory Property

See the CatalogServiceProxy_fallback class below.

CatalogServiceFallbackFactory Class

See CatalogServiceFallbackFactory class below.

Let’s run the application!

  • Set the following properties
    • terawarehouse-service-discovery
      • eureka.server.enable-self-preservation=false
    • terawarehouse-catalog and terawarehouse-inventory
      • eureka.instance.lease-renewal-interval-in-seconds=1
      • eureka.instance.lease-expiration-duration-in-seconds=1
*These are not production settings.

References

Related

spring-microservice 474448735536479358

Post a Comment Default Comments

item