Spring Cloud Gateway 网关过滤器中请求网关,首次请求出现 Read Timed Out ?

1、问题:Spring Cloud Gateway 网关过滤器中请求网关,首次请求出现 .java.net.SocketTimeoutException: Read Timed Out

代码:

@Slf4j
@Component
public class MyAuthorizationFilter implements GlobalFilter, Ordered {

    private static final ObjectMapper OM = new ObjectMapper();

    @Autowired
    private AuthorClient authorClient;

    @Override
    public int getOrder() {
        return -200;
    }

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpRequest request = exchange.getRequest();
        URI uri = request.getURI();
        GsonUtils.prettyInfoPrint(String.format("接收到请求:%s", uri.getPath()));


        // 登陆 这边时发起登录请求,走本身这个网关,第一次会超时
        Object data = authorClient.login(request);
        return completeFilter(exchange.getResponse(), data);

    }

    private Mono<Void> completeFilter(ServerHttpResponse response, Object data) {
        if (data != null) {
            response.getHeaders().add("Content-Type",
                    MediaType.APPLICATION_JSON_UTF8_VALUE);
            byte[] bytes = getDataAsBytes(data);
            DataBuffer buffer = response.bufferFactory().wrap(bytes);
            return response.writeWith(Flux.just(buffer));
        }
        return response.setComplete();
    }

    private byte[] getDataAsBytes(Object data) {
        try {
            return OM.writeValueAsBytes(data);
        } catch (JsonProcessingException e) {
            log.error("转换 Object - Bytes 失败", e);
        }
        return GsonUtils.toJson(Result.out(ResultCode.FAIL))
                .getBytes(StandardCharsets.UTF_8);
    }

}

代码中 带有注解的这一段是发起http请求代码:有没有人遇到过这样的问题?求解!!!!!!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问