springcloud feign increase fuse Hystrix

1. dependence

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

No additional annotated, feignclient comment on 2.springboot default startup class support hystrix

@EnableFeignClients   // 1. Support Hystrix and his fallback 2. support package will be scanned when the ribbon load balancing 3. Start scanning all the classes with @FeignClient and processed

3. Configure increase

feign.hystrix.enabled=true

4.feign client annotation fallback specified fuse handler class, you need to know the specific cause of the failure can be used to call fallbackFactory

feign

@FeignClient (name = "the Test", fallback = MqSendFeignFallback. Class )
 // @FeignClient (name = "the Test", fallbackFactory = MqsendFeignFallbackFactory.class) // fallbackFactory can call to get the reason for the failure 
public  interface MqSendFeign {

    @PostMapping("/ss/common/sendMq")
    Result sendMq(@RequestBody @Valid MqMessage mqMessage);

}

fallback

@ slf4j
@Component
public class MqSendFeignFallback implements MqSendFeign {

    @Override
    public Result sendMq(MqMessage mqMessage) {
        log.info("MqSendFeignFallback error");
        return new Result();
    }
}

 

fallbackFactory

@ slf4j
@Component
public class MqsendFeignFallbackFactory implements FallbackFactory<MqSendFeign> {

    @Override
    public MqSendFeign create(Throwable throwable) {
        return new MqSendFeign() {
            @Override
            public Result sendMq(MqMessage mqMessage) {
                log.error("MqsendFeignFallbackFactory error",throwable);
                return new Result();
            }
        };
    }
}

 

Guess you like

Origin www.cnblogs.com/liuboyuan/p/12010127.html