到了需要服务间调用的需求,踩了个坑,在此记录一下。
需求是这样的 A 服务需要调用 B 服务的接口
这是 A 服务调用 B 服务写的接口
A 服务 配置spring ApplicationName
spring:
application:
name: a-service
B 服务 配置spring ApplicationName
spring:
application:
name: b-service
@FeignClient(name = "b-service", fallback = B.class)
public interface Aservice{
@PostMapping("/selectA/{typeId}")
String selectPlanCount(@PathVariable("typeId")Integer typeId);
}
熔断
@Slf4j
@Component
public class AserviceImpl implements Aservice{
@Override
public String selectPlanCount(Integer typeId) {
String errorMsg = "触发接口熔断,默认返回";
log.info(errorMsg);
return errorMsg ;
}
}
发现只要一调用就熔断 ,结果发现是 rest 地址没写全
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("anls")
@Api(tags = {"分析服务"})
public class AnalysisController {
@PostMapping("/selectA/{typeId}")
public ResultDTO<PageInfo<BizEcOrderVo>> getAllOrderByPage(@PathVariable("typeId") Integer typeId) {
return "ok";
}
}
修改后 正常访问
@FeignClient(name = "b-service", fallback = B.class)
public interface Aservice{
@PostMapping("anls/selectA/{typeId}")
String selectPlanCount(@PathVariable("typeId")Integer typeId);
}
本次feign 服务间调用踩坑到此结束。
如有哪里写的不好请指出,共同进步。