@ConfigurationpublicclassHttpPool{@BeanpublicHttpClienthttpClient(){System.out.println("init feign httpclient configuration ");RequestConfig.Builder requestConfigBuilder=RequestConfig.custom(); requestConfigBuilder.setSocketTimeout(5*1000); requestConfigBuilder.setConnectTimeout(5*1000);RequestConfig defaultRequestConfig= requestConfigBuilder.build();finalPoolingHttpClientConnectionManager pollingConnectionManager=newPoolingHttpClientConnectionManager(30,TimeUnit.MILLISECONDS); pollingConnectionManager.setMaxTotal(5000); pollingConnectionManager.setDefaultMaxPerRoute(100);HttpClientBuilder httpClientBuilder=HttpClientBuilder.create(); httpClientBuilder.setKeepAliveStrategy(newDefaultConnectionKeepAliveStrategy()); httpClientBuilder.setConnectionManager(pollingConnectionManager); httpClientBuilder.setDefaultRequestConfig(defaultRequestConfig);HttpClient client= httpClientBuilder.build();Timer timer=newTimer(); timer.schedule(newTimerTask(){@Overridepublicvoidrun(){ pollingConnectionManager.closeExpiredConnections(); pollingConnectionManager.closeIdleConnections(5,TimeUnit.SECONDS);}},10*1000,5*1000);System.out.println("===== Apache httpclient 初始化连接池===");return client;}}
@ConfigurationpublicclassFeignClientConfig{@BeanLogger.LevelfeignLoggerLevel(){returnLogger.Level.FULL;}}
<configurationscan="true"scanPeriod="60 seconds"debug="false"><appendername="stdout"class="ch.qos.logback.core.ConsoleAppender"><layoutclass="ch.qos.logback.classic.PatternLayout"><pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{40} - %msg%n</pattern></layout></appender><appendername="AllLog"class="ch.qos.logback.core.rolling.RollingFileAppender"><rollingPolicyclass="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><fileNamePattern>D:/temp/idea/%d{yyyy-MM-dd}.log</fileNamePattern><maxHistory>30</maxHistory></rollingPolicy><encoder><pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{40} - %msg%n</pattern></encoder></appender><rootlevel="DEBUG"><appender-refref="AllLog"/><appender-refref="stdout"/></root></configuration>