Should I use EnableCircuitBreaker?
I only add these in my pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
I can use fallback now, it looks work.
@FeignClient(value = "xxxx-server-controller", fallback = TestDataFeignClientFallBack.class) public interface TestDataFeignClient { @GetMapping("/xxxx/xxxx") JSONObject xxxxx(@RequestParam(name = "id") int id); }
but I found CircuitBreaker not work.
@SpringBootApplication @EnableEurekaClient @EnableFeignClients public class TransportApplication { public static void main(String[] args) { SpringApplication.run(TransportApplication.class, args); } }
feign: hystrix: enabled: true client: config: default: connectTimeout: 10000 readTimeout: 10000
hystrix: command: default: execution: timeout: enabled: true isolation: thread: timeoutInMilliseconds: 12000 circuitBreaker: enabled: true forceOpen: false forceClosed: false requestVolumeThreshold: 4 errorThresholdPercentage: 50 sleepWindowInMilliseconds: 10000
but I want to use CircuitBreaker,should I add this dependency?
@Felfan I need your help
Questions like this are more appropriate for Stack Overflow. Issues in this repository are for bug fixes and feature requests for the project.
首先要看你的版本,应该是从3.x版本之后,
1 对于Netflix来说所需要引用依赖
@Override
protected ConfigBuilder configBuilder(String id) {
return new ConfigBuilder() {
@Override
public Object build() {
return null;
}
};
}
@Override
public void configureDefault(Function defaultConfiguration) {
}
}
public class MyCircuitBreaker implements CircuitBreaker {
@Override
public <T> T run(Supplier<T> toRun, Function<Throwable, T> fallback) {
try {
return toRun.get();
} catch (Exception ex) {
return fallback.apply(ex);
}
}
}