Spring Cloud: Feign and Http Connection Pooling

前端 未结 2 884
忘了有多久
忘了有多久 2021-02-09 00:37

Can anyone please tell me if the Spring Cloud Feign Client provides or supports Http Connection Pooling, and if so how to configure settings like pool size? I can\'t seem to fin

2条回答
  •  梦如初夏
    2021-02-09 01:06

    This is an example.

    @Bean
    public ServiceXFeignClient serviceXClient(Encoder encoder, Decoder decoder,
      Contract contract, ClientProperties properties, ProxyProperties proxyProperties) {
    
      OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder()
        .connectionPool(
          new ConnectionPool(properties.getPoolConnectionMaxIdle(),
          properties.getPoolConnectionKeepMinutesAlive(), TimeUnit.MINUTES))
        .build();
    
      return Feign.builder()
            .client(new feign.okhttp.OkHttpClient(okHttpClient))
        .encoder(encoder)
        .decoder(decoder)
        .contract(contract)
        .target(ServiceXFeignClient.class, properties.getUrl());
    }

提交回复
热议问题