2
  @Bean
    public ApacheHttpClient client() {
        RequestConfig config = RequestConfig.custom().setConnectTimeout(30)
                .setSocketTimeout(30).build();

        CloseableHttpClient httpClientObject = HttpClientBuilder.create()
                .setDefaultRequestConfig(config)
                .build();
        return new ApacheHttpClient(httpClientObject);
    }


@Autowired
    public HTTPRequestClient(Decoder decoder, Encoder encoder, ApacheHttpClient client) {
        this.client = client;

        setHttpRequestAdaptor(Feign.builder()
                .client(client)
                .encoder(encoder)
                .decoder(decoder)
                .logLevel(feign.Logger.Level.FULL)
                .target(Target.EmptyTarget.create(HTTPRequestAdaptor.class)));

    }

连接超时和套接字超时不起作用。需要哪些属性与 feign http 客户端配合使用?我一直在使用

feign.httpclient.enabled=true
feign.httpclient.connection-timeout=2

但它没有奏效。

4

1 回答 1

0

你可以添加一个.options(new Request.Options(30, 30)) 到 feign builder

如果失败,那么可能会将整个班级添加到问题中。this.client =client部分的代码看起来有点奇怪。

于 2021-03-30T14:52:07.167 回答