openFeign异步调用问题
网关服务通过openfeign调用授权服务。
·
报错信息
java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3
at 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
@Resource
OauthFeign oauthFeign;
@GetMapping("/get")
public Object get() {
return oauthFeign.openFeignApi();
}
此时请求网关的/get
就会报上面的错误。
需要添加一些配置
- 添加
HttpMessageConverters
的bean
@Configuration
public class HttpMsgConverConfig {
@Bean
@ConditionalOnMissingBean
public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {
return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
}
}
- 异步调用openfeign接口,修改controller
@Resource
OauthFeign oauthFeign;
@GetMapping("/get")
public Object get() {
CompletableFuture<Object> completableFuture = CompletableFuture.supplyAsync(() -> {
return oauthFeign.openFeignApi();
});
return completableFuture;
}
更多推荐
已为社区贡献1条内容
所有评论(0)