public ApiResult getXXXXX() {
Mono toMono = webBuilder.baseUrl("lb://" + ServiceNameConstant.ADMIN).build().get()
.uri(uriBuilder -> uriBuilder.path("/getXXXXX")
// .queryParam("参数名称", "参数值")
.build())
// .header(HttpHeaders.AUTHORIZATION, token)
.exchangeToMono(clientResponse -> clientResponse.bodyToMono(ApiResult.class));
// 不调用subscribe或者block是不会调用服务的,另外其他的像toFuture().get()看情况
return toMono.block();
}
调用方:
...
CompletableFuture completableFuture = CompletableFuture.supplyAsync
(()-> {
return userClient.getXXXXX();
});
ApiResult resp = null;
try {
resp = completableFuture.get();
log.info("调用成功:{}", resp);
} catch (Exception ex) {
log.error("调用接口错误", ex);
}
....
推荐!!!【腾讯云】爆款2核4G云服务器首年74元/年 推荐!!!【腾讯云】1核2G5M轻量应用服务器50元/年 【腾讯云】云数据库低至9.9/年!MySQL7.4元/月 【阿里云】ECS云服务器特惠 【阿里云】服务器首购优惠 如果文章对您有帮助,扫个红包码呗



