fabric8io / fabric8

fabric8 is an open source microservices platform based on Docker, Kubernetes and Jenkins
http://fabric8.io/
1.76k stars 504 forks source link

create a CDI equivalent of @HystrixCommand in Spring Cloud so folks can easily do circuit breakers / fallbacks when using CDI #5775

Open jstrachan opened 8 years ago

jstrachan commented 8 years ago

Using Hystrix is a nice way to add circuit breakers to your app. Particularly when using the @HystrixCommand from Spring Cloud.

It'd be nice to be able to do similar things to this in CDI too: https://github.com/nklmish/microservice-demo/blob/master/catalog-service/src/main/groovy/com/nklmish/cs/catalogs/integration/ProductBuilder.groovy#L23-L29

    @HystrixCommand(fallbackMethod = "productFallback")
    Product fetchProduct(int id) {
        log.debug("fetching product {}", id)
        return restTemplate.getForObject("http://product-service/product/$id", Product)
    }

    static Product productFallback(int productId) {
        log.error("fallback method invoked, hystrix command failed to retrieve product via product service")
        return new Product(name: "Demo Product")
 }```
jstrachan commented 8 years ago

it looks like most of the heavy lifting is being done by this library: https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-javanica