日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

openFeign异步调用问题

發布時間:2024/3/24 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 openFeign异步调用问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

報錯信息

java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83) ~[reactor-core-3.4.15.jar:3.4.15]Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Error has been observed at the following site(s):*__checkpoint ? org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]*__checkpoint ? HTTP GET "/get" [ExceptionHandlingWebHandler]

版本:
springcloud alibaba 2021.0.1.0
springboot 2.7.0
gateway 3.1.1
openfeign 3.1.1
還原場景
網關服務通過openfeign調用授權服務

授權服務

@GetMapping("/get")public String openFeignApi(){return "asdgwe";}

網關服務

@SpringBootApplication @EnableDiscoveryClient @EnableFeignClients public class GatewayServerApplication {public static void main(String[] args) {SpringApplication.run(GatewayServerApplication.class, args);}} @Component @FeignClient(value = "oauth") public interface OauthFeign {@GetMapping("/get")String openFeignApi(); }

controller

@ResourceOauthFeign oauthFeign;@GetMapping("/get")public Object get() {return oauthFeign.openFeignApi();}

此時請求網關的/get就會報上面的錯誤。
需要添加一些配置

  • 添加HttpMessageConverters的bean
  • @Configuration public class HttpMsgConverConfig {@Bean@ConditionalOnMissingBeanpublic HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));} }
  • 異步調用openfeign接口,修改controller
  • @ResourceOauthFeign oauthFeign;@GetMapping("/get")public Object get() {CompletableFuture<Object> completableFuture = CompletableFuture.supplyAsync(() -> {return oauthFeign.openFeignApi();});return completableFuture;}

    總結

    以上是生活随笔為你收集整理的openFeign异步调用问题的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。