咱們在作項目開發或多或少的都會使用SpringCloud,其中作遠程調度的時候會將HTTP請求Http請求優化。git
HTTP請求Client存在不少種。github
實例:緩存
這時咱們就能夠使用別的Client進行替換:網絡
1 <dependency> 2 <groupId>com.netflix.feign</groupId> 3 <artifactId>feign-httpclient</artifactId> 4 <version>8.17.0</version> 5 </dependency> 6 7 <dependency> 8 <groupId>io.github.openfeign</groupId> 9 <artifactId>feign-okhttp</artifactId> 10 </dependency> 11 </dependencies>
1 feign: 2 httpclient: 3 enabled: false 4 okhttp: 5 enabled: true
1 @Configuration 2 @ConditionalOnClass(Feign.class) 3 @AutoConfigureBefore(FeignAutoConfiguration.class) 4 public class FeignOkHttpConfig { 5 @Bean 6 public okhttp3.OkHttpClient okHttpClient(){ 7 return new okhttp3.OkHttpClient.Builder() 8 //設置鏈接超時 9 .connectTimeout(60, TimeUnit.SECONDS) 10 //設置讀超時 11 .readTimeout(60, TimeUnit.SECONDS) 12 //設置寫超時 13 .writeTimeout(60,TimeUnit.SECONDS) 14 //是否自動重連 15 .retryOnConnectionFailure(true) 16 .connectionPool(new ConnectionPool()) 17 //構建OkHttpClient對象 18 .build(); 19 } 20 21 }