美文网首页
gateway 调用 feign

gateway 调用 feign

作者: 川流不息attitude | 来源:发表于2022-09-04 09:30 被阅读0次

    gateway 使用 webflux 异步编程,所以不能直接 feign

    CompletableFuture<R> completableFuture = CompletableFuture.supplyAsync(()->{
                // 这里调用 就行
            },gateWayTaskExecutor);
    
    R result = completableFuture.get();
    
    

    添加 消息转换 配置

        @Bean
        @ConditionalOnMissingBean
        public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {
            return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
        }
    
    拦截符合条件 响应消息
    private Mono<Void> response(String msg ,ServerWebExchange exchange) {
            R<Object> r = R.failed(msg);
            exchange.getResponse().getHeaders().setContentType(MediaType.APPLICATION_JSON);
            DataBuffer buffer = exchange.getResponse().bufferFactory().wrap(JSONObject.toJSONString(r).getBytes(StandardCharsets.UTF_8));
            return exchange.getResponse().writeWith(Flux.just(buffer));
        }
    

    相关文章

      网友评论

          本文标题:gateway 调用 feign

          本文链接:https://www.haomeiwen.com/subject/dmuvnrtx.html