1. pom.xml增加
<!-- spring boot feign-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
2. Application.java增加注解
@EnableFeignClients(basePackages = "com.k2icloud.manager.guard.service")
3. application.yml增加
# 开启feign熔断
feign:
hystrix:
enabled: true
4. 增加feign client类
@Service
@FeignClient(value = "sanyu-water", fallback = FegionBreaker.class)
public interface SanyuWaterFegionClient {
// 与接口提供API保持一致
@GetMapping(value = "/resetSensorStatus/{sensorId}")
ResponseWrapper<Object> resetSensorStatus(@PathVariable("sensorId") String sensorId);
}
5. 增加feign熔断返回类
@Component
@Slf4j
public class FegionBreaker implements SanyuWaterFegionClient{
@Override
public ResponseWrapper<Object> resetSensorStatus(String sensorId) {
log.error("[FegionBreaker] [resetSensorStatus] [failed]");
return ResponseWrapper.failed();
}
}