(Thirty-five) java version of spring cloud micro Services Architecture b2b2c e-commerce platform -Feign support of Hystrix

If Hystrix at classpath, by default all methods include Feign of the circuit breaker. Returns a com.netflix.hystrix.HystrixCommand to use, it allows you to use reaction mode (call .toObservable or .observe () or asynchronously (.queue ())). To disable Feign of Hystrix support, set feign.hystrix.enable = false.

To disable Hystrix supported on each client, create a Feign.Builder and scope is set to "prototype", for example:

@Configuration
public class FooConfiguration {
    @Bean
    @Scope("prototype")
    public Feign.Builder feignBuilder() {
        return Feign.builder();
    }
}

Feign Hystrix Fallbacks (failure fallback)

Hystrix failed to support the concept of fallback, when there is an error line is the default code execution path, enable rollback to give @FeignClient fallback attribute set to achieve rollback of the class name.

Write an implementation class that implements the Client Interface

@Component
public class MenuClientFallback implements MenuClient {

    @Override
    public ResponseResult saveOrUpdateMenu(MenuModel menuModel) {
        System.out.println("调用服务失败");
        return new ResponseResult("-1", "调用服务失败");
    }

}

@FeignClient notes plus the value attribute fallback, fallback attribute is the implementation class .class

@FeignClient(name = "WishfulCloud-Authority-Service", fallback=MenuClientFallback.class)
public interface MenuClient {

    @RequestMapping(value = "/menu/saveOrUpdateMenu", method = RequestMethod.POST)
    public ResponseResult saveOrUpdateMenu(@RequestBody MenuModel menuModel);

}

fallbackFactory

If you need to access the cause rollback trigger, you can use the fallbackFactory property in @FeginClient

Guess you like

Origin blog.csdn.net/vvx0206/article/details/93846095