Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hystrix Warstories

Hystrix Warstories

Hystrix Warstories slides from our talk @ JAX 2016

Benjamin Wilms

April 21, 2016
Tweet

More Decks by Benjamin Wilms

Other Decks in Programming

Transcript

  1. 3 Agenda Hystrix Einführung Resilience Patterns Praxis 1: Hystrix Erfahrungen

    Demo Praxis 2: Hystrix und Legacy Backends Advanced Features
  2. 4 About us Benjamin Wilms Felix Braun Senior Agile IT-Consultant

    www.codecentric.de blog.codecentric.de Senior IT-Consultant
  3. 6

  4. 11

  5. 12

  6. 13 Hello World public class CommandHelloWorld extends HystrixCommand<String> { private

    final String name; public CommandHelloWorld(String name) { super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup")); this.name = name; } @Override protected String run() { return "Hello " + name; } }
  7. 14 Hello World public class CommandHelloWorld extends HystrixCommand<String> { [...]

    @Override protected String run() { return getLocalizedHello(name); } @Override protected String getFallback(){ return "Hello " + name; } }
  8. 16 Pattern • Timeout (Hystrix) • Bulkheads (Hystrix) • Circuit

    Breaker (Hystrix) • Steady State • Fail Fast • Handshaking • Test harness • Decoupling middleware
  9. 26 Java 8 public class LambdaHystrixCommand<T> extends HystrixCommand<T> { private

    Supplier<T> runSupplier; private Supplier<T> fallbackSupplier; public LambdaHystrixCommand(String cmdkey, Supplier<T> runSup, Supplier<T> fallbackSup) { [...] } @Override protected T run() throws Exception { return runSupplier.get();} @Override protected T getFallback() { return fallbackSupplier.get();} }
  10. 44 Hystrix & Archaius • dynamic & typed • thread

    safe • polling framework • callback mechanism • dynamic configuration
  11. 48 Archaius & etcd // Config fallback (config.properties) and Etcd

    configuration compositeConfig = new ConcurrentCompositeConfiguration(); ClasspathPropertiesConfiguration.initialize(); // File based config // CoreOS Etcd service configuration etcdConfigSource = new EtcdConfigurationSource(etcd, "/hystrix/"); etcdConfig = new DynamicWatchedConfiguration(etcdConfigSource); compositeConfig.addConfiguration(etcdConfig,"etcd dynamic override config"); ConfigurationManager.install(compositeConfig);
  12. 56 Spring Cloud Netflix & Spring Boot @SpringBootApplication @EnableCircuitBreaker @EnableHystrixDashboard

    @Import(ArchaiusConfiguration.class) public class TransportServiceAppl { public static void main(String[] args) { SpringApplication.run(TransportServiceApp.class, args); } }
  13. 59 Zusammenfassung • Chaos Monkey aktiviert • Remote Services konfiguriert

    • Hystrix Timeouts gesetzt • Hystrix Circuit Breaker open/close • Hystrix Fallbacks deaktiviert
  14. 64 Cache-Example @GET @Path("/cacheTest/{name}") public void cacheTest(@PathParam("name") String name) {

    try (HystrixRequestContext context = HystrixRequestContext.initializeContext()) { for (int i = 0; i < 3; i++) { LambdaHystrixCommand<String> pingCmd = new LambdaHystrixCommand<>( „CacheCmd", „CacheCmdCache",() -> getPing(name), () -> "pong"); String result = pingCmd.execute(); System.out.println(i + ": " + result + " is from cache: " + pingCmd.isResponseFromCache()); }} }
  15. 65 Cache-Example @GET @Path("/cacheTest/{name}") public void cacheTest(@PathParam("name") String name) {

    try (HystrixRequestContext context = HystrixRequestContext.initializeContext()) { for (int i = 0; i < 3; i++) { LambdaHystrixCommand<String> pingCmd = new LambdaHystrixCommand<>( „CacheCmd", „CacheCmdCache",() -> getPing(name), () -> "pong"); String result = pingCmd.execute(); System.out.println(i + ": " + result + " is from cache: " + pingCmd.isResponseFromCache()); }} }
  16. 66 Cache-Example @GET @Path("/cacheTest/{name}") public void cacheTest(@PathParam("name") String name) {

    try (HystrixRequestContext context = HystrixRequestContext.initializeContext()) { for (int i = 0; i < 3; i++) { LambdaHystrixCommand<String> pingCmd = new LambdaHystrixCommand<>( „CacheCmd", „CacheCmdCache",() -> getPing(name), () -> "pong"); String result = pingCmd.execute(); System.out.println(i + ": " + result + " is from cache: " + pingCmd.isResponseFromCache()); }} }
  17. 69