从一个微服务到另一个微服务的WebClient构建器调用,第一次在Webflux中给出错误的请求错误

问题描述 投票:1回答:1

[我们正在使用WebClient Builder调用在我们的项目中的微服务之间进行通信。它是基于springboot-thymleaf-webflux的应用程序。到目前为止,一切都运行良好,但是我们要求Client要求将thymleaf中的GET调用更改为POST调用。在UI和后端进行了这些更改之后,Thymleaf调用工作正常,但是XHR之一(即来自UI的后调用)给Web客户端调用第二次微服务以实现第一次单击并为第二次单击提供了错误的请求错误。标头和两次点击请求都没有任何区别。我无法理解为什么网络客户端第一次运行异常,而第二次运行良好。下面是用于webclient调用的代码段,它路由到WebclientResponseException而不通过说http://second-microservice -eureka-address / endpoint-url]的BAD请求到达第二个微服务

     * Submitting xyz 
     * @param submitFlowRequest
     */
    @Override
    public Mono<ApiResponse<SubmitResponse>> submitFlow(SubmitFlowRequest submitFlowRequest,
            Map<String, String> headers) {
        long startTime = System.currentTimeMillis();
        String uri = propertyConfig.getAggregationService()
                + propertyConfig.getAggregationSubmitCCInfoURL();
        DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(uri);
        factory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.URI_COMPONENT);
        MultiValueMap<String, String> clientHeaders = buildHeaders(headers);
        return webClientBuilder.uriBuilderFactory(factory).build().post()
                .headers(httpHeaders -> httpHeaders.addAll(clientHeaders)).accept(MediaType.APPLICATION_JSON)
                .syncBody(submitFlowRequest).retrieve().bodyToMono(ApiResponse.class)
                .onErrorMap(ConnectException.class,
                        error -> new VzwRuntimeException(ErrorCodeEnum.V404.toString(), Constants.OPP_TC_SYSTEM_ERROR,
                                (Constants.CONNECTION_FAILURE_TEXT + Constants.AGGREGATION)))
                .onErrorMap(WebClientResponseException.class,
                        error -> new VzwRuntimeException(ErrorCodeEnum.V404.toString(), Constants.OPP_TC_SYSTEM_ERROR,
                                (Constants.CONNECTION_FAILURE_TEXT + Constants.AGGREGATION)))
                .flatMap(res -> {
                    Audit apiAudit = Audit.builder().apiUrl(uri).request(LoggerUtil.asJson(submitFlowRequest))
                            .response(LoggerUtil.asJson(res))
                            .executionTime(String.valueOf(System.currentTimeMillis() - startTime))
                            .headers(LoggerUtil.asJson(clientHeaders)).transactionType(res.getData()!=null?mapper.map(res.getData(), SubmitResponse.class).getTransactionType():"").build();
                    LoggerUtil.logExternalApiCalls(apiAudit);
                    return Mono.just((ApiResponse<SubmitResponse>) res);
                });
    }```

Please provide me some lead.I am tired of finding solution for this.

[我们正在使用WebClient Builder调用项目中的微服务之间的通信。它是基于springboot-thymleaf-webflux的应用程序。到目前为止,一切都运行良好,但是我们得到了...

spring-boot webclient spring-webflow spring-webclient spring-reactive
1个回答
0
投票
这是Netty的持续性问题。 Netty持有一些状态为HttpObjectEncoder的连接。当客户端从池中获得此类连接并将其用于向目标服务器发出请求时,该连接将立即失败,因为HttpObjectEncoder无法编码DefaultHttpRequest。禁用连接池可以解决问题。
© www.soinside.com 2019 - 2024. All rights reserved.