当前位置: 首页 > news >正文

搜索引擎和门户网站的区别全球十大摄影作品

搜索引擎和门户网站的区别,全球十大摄影作品,wordpress 网址导航页,网站建设怎么骗人文章目录 前言正文一、OkHttpFeignConfiguration 的启用1.1 分析配置类1.2 得出结论#xff0c;需要增加配置1.3 调试 二、OkHttpFeignLoadBalancerConfiguration 的启用2.1 分析配置类2.2 得出结论2.3 测试 附录附1#xff1a;本系列文章链接附2#xff1a;OkHttpClient 增… 文章目录 前言正文一、OkHttpFeignConfiguration 的启用1.1 分析配置类1.2 得出结论需要增加配置1.3 调试 二、OkHttpFeignLoadBalancerConfiguration 的启用2.1 分析配置类2.2 得出结论2.3 测试 附录附1本系列文章链接附2OkHttpClient 增加拦截器配置附2.1 新建配置类OkHttpConfig附2.2 调试结果 前言 众所周知我们在使用SpringCloud OpenFeign时默认使用的是老旧的连接器HttpURLConnection。性能以及并发量方面都差强人意。 一般而言都会对其进行优化调整。本文采用OpenFeign整合okHttp的方式替换原有的Client去做请求。 使用java 17spring cloud 4.0.4springboot 3.1.4 使用项目是本系列第一篇中的项目 本文介绍两种方式的配置一个是LoadBalancer 的都是默认带有连接池的。 OkHttpFeignConfigurationOkHttpFeignLoadBalancerConfiguration 正文 一、OkHttpFeignConfiguration 的启用 1.1 分析配置类 首先我们需要加入什么依赖配置呢 依据 OkHttpFeignConfiguration 的配置内容进行分析 Configuration(proxyBeanMethods false) ConditionalOnClass(OkHttpClient.class) ConditionalOnMissingBean(okhttp3.OkHttpClient.class) ConditionalOnProperty(spring.cloud.openfeign.okhttp.enabled) protected static class OkHttpFeignConfiguration {// 类路径下有连接池时构建连接池BeanConditionalOnMissingBean(ConnectionPool.class)public ConnectionPool httpClientConnectionPool(FeignHttpClientProperties httpClientProperties) {int maxTotalConnections httpClientProperties.getMaxConnections();long timeToLive httpClientProperties.getTimeToLive();TimeUnit ttlUnit httpClientProperties.getTimeToLiveUnit();return new ConnectionPool(maxTotalConnections, timeToLive, ttlUnit);}// 构建OkHttpClient实例Beanpublic okhttp3.OkHttpClient okHttpClient(okhttp3.OkHttpClient.Builder builder, ConnectionPool connectionPool,FeignHttpClientProperties httpClientProperties) {boolean followRedirects httpClientProperties.isFollowRedirects();int connectTimeout httpClientProperties.getConnectionTimeout();boolean disableSslValidation httpClientProperties.isDisableSslValidation();Duration readTimeout httpClientProperties.getOkHttp().getReadTimeout();ListProtocol protocols httpClientProperties.getOkHttp().getProtocols().stream().map(Protocol::valueOf).collect(Collectors.toList());if (disableSslValidation) {disableSsl(builder);}this.okHttpClient builder.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS).followRedirects(followRedirects).readTimeout(readTimeout).connectionPool(connectionPool).protocols(protocols).build();return this.okHttpClient;} } 1.2 得出结论需要增加配置 从配置类中观察到它的启用条件有2个一个是需要引入 okhttp的包另一个需要一行启用配置 !-- https://mvnrepository.com/artifact/io.github.openfeign/feign-okhttp -- dependencygroupIdio.github.openfeign/groupIdartifactIdfeign-okhttp/artifactIdversion13.1/version /dependency# 启用okhttp配置 spring.cloud.openfeign.okhttp.enabledtrue1.3 调试 正常请求在SynchronousMethodHandler.executeAndDecode(...) 中打断点调试观察client的类型 发现已经不再是之前的Default 了换成了OkHttpClient 类型。并且也内置了连接池以及一些基本配置信息。 二、OkHttpFeignLoadBalancerConfiguration 的启用 2.1 分析配置类 依据 OkHttpFeignLoadBalancerConfiguration 中的配置项分析 Configuration(proxyBeanMethods false) ConditionalOnClass(OkHttpClient.class) ConditionalOnProperty(spring.cloud.openfeign.okhttp.enabled) ConditionalOnBean({ LoadBalancerClient.class, LoadBalancerClientFactory.class }) EnableConfigurationProperties(LoadBalancerClientsProperties.class) class OkHttpFeignLoadBalancerConfiguration {BeanConditionalOnMissingBeanConditional(OnRetryNotEnabledCondition.class)public Client feignClient(okhttp3.OkHttpClient okHttpClient, LoadBalancerClient loadBalancerClient,LoadBalancerClientFactory loadBalancerClientFactory,ListLoadBalancerFeignRequestTransformer transformers) {OkHttpClient delegate new OkHttpClient(okHttpClient);return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancerClientFactory,transformers);}// 省略其他配置 }2.2 得出结论 想要让这个配置生效需要满足OkHttpClient、LoadBalancerClient、OnRetryNotEnabledCondition。 也就是2个依赖项2个配置 !-- https://mvnrepository.com/artifact/io.github.openfeign/feign-okhttp -- dependencygroupIdio.github.openfeign/groupIdartifactIdfeign-okhttp/artifactIdversion13.1/version /dependency !-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-loadbalancer -- dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-loadbalancer/artifactIdversion4.0.4/version /dependency而配置方面需要增加 # 启用okhttp配置 spring.cloud.openfeign.okhttp.enabledtrue# 关闭负载重试 spring.cloud.loadbalancer.retry.enabledfalse2.3 测试 正常请求在SynchronousMethodHandler.executeAndDecode(...) 中打断点调试观察client的类型 发现已经不再是之前的Default 了换成了OkHttpClient 类型。 附录 附1本系列文章链接 SpringCloud系列文章目录总纲篇 附2OkHttpClient 增加拦截器配置 附2.1 新建配置类OkHttpConfig 增加以下拦截器配置对请求和响应进行日志打印。 package org.feng.config;import lombok.extern.slf4j.Slf4j; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response; import org.jetbrains.annotations.NotNull; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;import java.io.IOException;/*** okhttp配置** author feng*/ Slf4j Configuration public class OkHttpConfig {Beanpublic okhttp3.OkHttpClient.Builder okHttpClientBuilder() {return new okhttp3.OkHttpClient.Builder().addInterceptor(new LoggingInterceptor());}/*** okhttp3 请求日志拦截器*/static class LoggingInterceptor implements Interceptor {NotNullOverridepublic Response intercept(Chain chain) throws IOException {Request request chain.request();long start System.nanoTime();log.info(String.format(Sending request %s on %s%n%s,request.url(), chain.connection(), request.headers()));Response response chain.proceed(request);long end System.nanoTime();log.info(String.format(Received response for %s in %.1fms%n%s,response.request().url(), (end - start) / 1e6d, response.headers()));return response;}} } 附2.2 调试结果 可以观察到日志中打印出来了请求路径、请求头等信息。 2023-11-24T16:48:56.35808:00 INFO 35987 --- [nio-8080-exec-1] org.feng.config.OkHttpConfig : Sending request http://localhost:10080/hello/post on null Content-Length: 100 Accept: */*2023-11-24T16:48:56.71308:00 INFO 35987 --- [nio-8080-exec-1] org.feng.config.OkHttpConfig : Received response for http://localhost:10080/hello/post in 347.4ms Content-Type: application/json Transfer-Encoding: chunked Date: Fri, 24 Nov 2023 08:48:56 GMT Keep-Alive: timeout60 Connection: keep-alive
http://www.hkea.cn/news/14385995/

相关文章:

  • 广州网站开发招聘信息soso搜搜
  • 庐江住房建设局网站开发公司网签的流程
  • 兰陵网站建设网站建设软文推广
  • 翡翠原石网站首页怎么做做黑网站赚钱吗
  • 安徽省建设安全协会网站某商贸网站建设方案
  • 入境游旅游网站建设大连新图闻科技
  • 东莞做网站公司百度竞价推广课程
  • 庆阳网站设计 贝壳下拉wordpress主题academy
  • 个人网站怎样做超链接家在深圳坪山
  • 广告最多的网站响应式自助建站平台
  • 受欢迎的永州网站建设wordpress发文章的id怎么不连续
  • 旅游前 做攻略有什么网站好用网站的特效代码
  • 建设高端网站公司的目的google收录网站
  • 给企业做网站运营网站建设设计开发公司
  • 政务网站的建设原则网站建设投标文件
  • 比特币网站做任务手机怎么做程序
  • 网站建设的功能有哪些婚纱制作网站
  • 上海网站建设要多少钱wordpress标签生成器
  • 建网站多少费用织梦手机网站源码
  • 章丘环保网站建设 中企动力免费推广渠道
  • 如何做网站推广的方案设计wordpress建站打不开二级页面
  • 做项目网站深圳的网站建设公司 湖南岚鸿
  • 网站没有做301定向企业管理咨询合同书范本
  • 网站建设cms系统上海网站开发公司
  • 网站代码规范工商注册公司需要哪些材料
  • 做网站不给源码一键logo生成器免费
  • 绵阳网站建设联系电话国外推广渠道平台
  • 西安网站建设资讯丹东seo
  • 星裕建设网站根据一个网站仿做新网站是什么网站
  • 如何做网站模版微信可以做网站吗