目录
我的话是微服务B调用微服务A的controller层
2.生产者微服务A请求接口如下:
"/listUniteProdPrice")(
public AjaxResult listUniteProdPrice(){
return AjaxResult.success(productService.listUniteProdPrice());
}
为了便于管理,创建一个文件夹名为client,与service、mapper层统计,接口命名规则为xxxFeignService,表明是远程调用的接口;FeignClient注解
的值是微服务A的spring.application.name
value="MICRO-A",fallbackFactory = IProductFallback.class)(
public interface IProductFeignService {
("/product/listProductByDeptId")
AjaxResult listProductByDeptId( ("deptId") Long deptId);
("/product/listUniteProdPrice")
AjaxResult listUniteProdPrice();
}
同时需要在启动类添加注解,并标明远程调用接口的文件夹在哪个位置
@EnableFeignClients({"com.workflow.oa.client"})
加入hystrix/sentinel断路器...
如果接口长时间没有返回或报错,返回消息给前台
public class IProductFallback implements FallbackFactory<IProductService> {
public IProductService create(Throwable cause) {
log.error("获取产品数据调用失败:{}", cause.getMessage());
return new IProductService() {
public AjaxResult listProductByDeptId(Long deptId) {
return AjaxResult.error("获取产品数据调用失败:{}", cause.getMessage());
}
public AjaxResult listUniteProdPrice() {
return AjaxResult.error("获取产品数据调用失败:{}", cause.getMessage());
}
};
}
}