Circuit Breaker www.thoughts-on-java.org Handle unavailable / - - PowerPoint PPT Presentation

circuit breaker
SMART_READER_LITE
LIVE PREVIEW

Circuit Breaker www.thoughts-on-java.org Handle unavailable / - - PowerPoint PPT Presentation

Circuit Breaker www.thoughts-on-java.org Handle unavailable / unresponsive services Circuit Breaker Stop if X requests failed Goals Dont block local resource Dont overload unresponsive services Provide fallbacks


slide-1
SLIDE 1

Circuit Breaker

www.thoughts-on-java.org

slide-2
SLIDE 2

Circuit Breaker

  • Handle unavailable / unresponsive services
  • Stop if X requests failed
  • Goals
  • Don‘t block local resource
  • Don‘t overload unresponsive services
  • Provide fallbacks

www.thoughts-on-java.org

slide-3
SLIDE 3

Spring Cloud Hystrix

  • Based on Netflix Hystrix
  • https://github.com/Netflix/hystrix
  • Spring Cloud Starter
  • spring-cloud-starter-hystrix

www.thoughts-on-java.org

slide-4
SLIDE 4

Spring Cloud Hystrix

  • @EnableCircuitBreaker on configuration class
  • @HystrixCommand on method
  • Works within a @Service or @Component
  • Don‘t call internally

www.thoughts-on-java.org

slide-5
SLIDE 5

Code Samples

www.thoughts-on-java.org

slide-6
SLIDE 6

Hystrix Configuration

www.thoughts-on-java.org

slide-7
SLIDE 7

Hystrix Configuration

  • Hystrix configuration
  • https://github.com/Netflix/Hystrix/wiki/Configuration
  • Set via
  • @HystrixProperty annotations
  • External configuration

www.thoughts-on-java.org

slide-8
SLIDE 8

Hystrix Property

  • execution.isolation.thread.timeoutInMilliseconds
  • Timeout in ms for command execution
  • Default: 1000

www.thoughts-on-java.org

slide-9
SLIDE 9

Hystrix Property

  • circuitBreaker.requestVolumeThreshold
  • Minimum number of requests to trip the circuit
  • Default: 20

www.thoughts-on-java.org

slide-10
SLIDE 10

Hystrix Property

  • circuitBreaker.errorThresholdPercentage
  • Error percentage that trips the circuit
  • Default: 50

www.thoughts-on-java.org

slide-11
SLIDE 11

Hystrix Property

  • circuitBreaker.sleepWindowInMilliseconds
  • Time until new attempt
  • Default: 5000

www.thoughts-on-java.org

slide-12
SLIDE 12

Annotation-based

  • Add commandProperties to @HystrixCommand
  • Array of @HystrixProperty

www.thoughts-on-java.org

slide-13
SLIDE 13

Code Samples

www.thoughts-on-java.org

slide-14
SLIDE 14

File-based

  • Define commandKey for @HystrixCommand

www.thoughts-on-java.org

slide-15
SLIDE 15

File-based

  • Same as annotation-based
  • Requires prefix
  • hystrix.command.<CommandKey>.<ParamName>

www.thoughts-on-java.org

slide-16
SLIDE 16

Code Samples

www.thoughts-on-java.org

slide-17
SLIDE 17

Summary

  • Handle unavailable / unresponsive services
  • Release local resources
  • Don‘t overload other services
  • Avoid cascading effects
  • Provide fallbacks

www.thoughts-on-java.org