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

网站搭建徐州百度网络搭建交换友情链接的条件

网站搭建徐州百度网络搭建,交换友情链接的条件,广州短视频网站开发,香港新冠疫情最新消息文章目录 前言正文一、OkHttpFeignConfiguration 的启用1.1 分析配置类1.2 得出结论,需要增加配置1.3 调试 二、OkHttpFeignLoadBalancerConfiguration 的启用2.1 分析配置类2.2 得出结论2.3 测试 附录附1:本系列文章链接附2:OkHttpClient 增…

文章目录

  • 前言
  • 正文
    • 一、OkHttpFeignConfiguration 的启用
      • 1.1 分析配置类
      • 1.2 得出结论,需要增加配置
      • 1.3 调试
    • 二、OkHttpFeignLoadBalancerConfiguration 的启用
      • 2.1 分析配置类
      • 2.2 得出结论
      • 2.3 测试
  • 附录
    • 附1:本系列文章链接
    • 附2:OkHttpClient 增加拦截器配置
      • 附2.1 新建配置类OkHttpConfig
      • 附2.2 调试结果

前言

众所周知,我们在使用SpringCloud OpenFeign时,默认使用的是老旧的连接器HttpURLConnection。性能以及并发量方面都差强人意。

一般而言都会对其进行优化调整。本文采用OpenFeign整合okHttp的方式替换原有的Client,去做请求。

使用java 17,spring cloud 4.0.4,springboot 3.1.4
使用项目是本系列第一篇中的项目

本文介绍两种方式的配置,一个是LoadBalancer 的,都是默认带有连接池的。

  • OkHttpFeignConfiguration
  • OkHttpFeignLoadBalancerConfiguration

正文

一、OkHttpFeignConfiguration 的启用

1.1 分析配置类

首先我们需要加入什么依赖配置呢?
依据 OkHttpFeignConfiguration 的配置内容,进行分析:

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(OkHttpClient.class)
@ConditionalOnMissingBean(okhttp3.OkHttpClient.class)
@ConditionalOnProperty("spring.cloud.openfeign.okhttp.enabled")
protected static class OkHttpFeignConfiguration {// 类路径下有连接池时,构建连接池@Bean@ConditionalOnMissingBean(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();List<Protocol> 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 -->
<dependency><groupId>io.github.openfeign</groupId><artifactId>feign-okhttp</artifactId><version>13.1</version>
</dependency>
# 启用okhttp配置
spring.cloud.openfeign.okhttp.enabled=true

1.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 {@Bean@ConditionalOnMissingBean@Conditional(OnRetryNotEnabledCondition.class)public Client feignClient(okhttp3.OkHttpClient okHttpClient, LoadBalancerClient loadBalancerClient,LoadBalancerClientFactory loadBalancerClientFactory,List<LoadBalancerFeignRequestTransformer> transformers) {OkHttpClient delegate = new OkHttpClient(okHttpClient);return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancerClientFactory,transformers);}// 省略其他配置
}

2.2 得出结论

想要让这个配置生效,需要满足OkHttpClientLoadBalancerClientOnRetryNotEnabledCondition
也就是2个依赖项,2个配置:

<!-- https://mvnrepository.com/artifact/io.github.openfeign/feign-okhttp -->
<dependency><groupId>io.github.openfeign</groupId><artifactId>feign-okhttp</artifactId><version>13.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-loadbalancer -->
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-loadbalancer</artifactId><version>4.0.4</version>
</dependency>

而配置方面需要增加:

# 启用okhttp配置
spring.cloud.openfeign.okhttp.enabled=true# 关闭负载重试
spring.cloud.loadbalancer.retry.enabled=false

2.3 测试

正常请求,在SynchronousMethodHandler.executeAndDecode(...) 中打断点,调试观察client的类型:
在这里插入图片描述
发现已经不再是之前的Default 了,换成了OkHttpClient 类型。

附录

附1:本系列文章链接

SpringCloud系列文章目录(总纲篇)

附2:OkHttpClient 增加拦截器配置

附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 {@NotNull@Overridepublic 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.358+08: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.713+08: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: timeout=60
Connection: keep-alive

文章转载自:
http://dinncoentomofauna.stkw.cn
http://dinncohyperkinesia.stkw.cn
http://dinncotwirler.stkw.cn
http://dinncorash.stkw.cn
http://dinncopalynology.stkw.cn
http://dinncoplumulate.stkw.cn
http://dinncoforebrain.stkw.cn
http://dinncoabactinal.stkw.cn
http://dinncoautorotation.stkw.cn
http://dinncomidriff.stkw.cn
http://dinncomoksha.stkw.cn
http://dinncokeyswitch.stkw.cn
http://dinncodereliction.stkw.cn
http://dinncoholeable.stkw.cn
http://dinncohadaway.stkw.cn
http://dinncocoho.stkw.cn
http://dinncoparaprotein.stkw.cn
http://dinncofistulous.stkw.cn
http://dinncoentrechat.stkw.cn
http://dinncocarbamyl.stkw.cn
http://dinncorepeal.stkw.cn
http://dinncolivable.stkw.cn
http://dinncobeefer.stkw.cn
http://dinncodirecttissima.stkw.cn
http://dinncosloth.stkw.cn
http://dinncofavorite.stkw.cn
http://dinncowahine.stkw.cn
http://dinncoulyanovsk.stkw.cn
http://dinncobrushability.stkw.cn
http://dinncohilch.stkw.cn
http://dinncoaeonian.stkw.cn
http://dinncotonsillitic.stkw.cn
http://dinncofactual.stkw.cn
http://dinncoindictment.stkw.cn
http://dinncoeudemonism.stkw.cn
http://dinncodivers.stkw.cn
http://dinncotransferrer.stkw.cn
http://dinncoascu.stkw.cn
http://dinncoimprimatura.stkw.cn
http://dinncounearthliness.stkw.cn
http://dinncophon.stkw.cn
http://dinnconosogeography.stkw.cn
http://dinnconecromancy.stkw.cn
http://dinncoteachableness.stkw.cn
http://dinncokalinin.stkw.cn
http://dinncoinnocent.stkw.cn
http://dinncomib.stkw.cn
http://dinncocachalot.stkw.cn
http://dinncoaugmentation.stkw.cn
http://dinncosanforize.stkw.cn
http://dinncoquaternize.stkw.cn
http://dinncouranalysis.stkw.cn
http://dinncojunc.stkw.cn
http://dinncotrick.stkw.cn
http://dinncocalligraph.stkw.cn
http://dinncotingle.stkw.cn
http://dinncojawed.stkw.cn
http://dinncofuoro.stkw.cn
http://dinncoproducer.stkw.cn
http://dinncocatfoot.stkw.cn
http://dinncoutopia.stkw.cn
http://dinncointerceder.stkw.cn
http://dinncowillable.stkw.cn
http://dinncometeorolite.stkw.cn
http://dinncoerythropoiesis.stkw.cn
http://dinncomannerism.stkw.cn
http://dinncoorion.stkw.cn
http://dinncogaloche.stkw.cn
http://dinncocunit.stkw.cn
http://dinncocoloured.stkw.cn
http://dinncoindisputable.stkw.cn
http://dinncoflashboard.stkw.cn
http://dinncoblanketflower.stkw.cn
http://dinncohomothety.stkw.cn
http://dinncosaccule.stkw.cn
http://dinncorejoice.stkw.cn
http://dinncopedlary.stkw.cn
http://dinncoevangelize.stkw.cn
http://dinncosuch.stkw.cn
http://dinncohepatopathy.stkw.cn
http://dinncophenylene.stkw.cn
http://dinncodispatchbox.stkw.cn
http://dinncosedately.stkw.cn
http://dinncobiserial.stkw.cn
http://dinncowhosever.stkw.cn
http://dinncopassage.stkw.cn
http://dinncobabirussa.stkw.cn
http://dinncolinden.stkw.cn
http://dinncoperigee.stkw.cn
http://dinncocruces.stkw.cn
http://dinncoveld.stkw.cn
http://dinncoafter.stkw.cn
http://dinncotelephotometer.stkw.cn
http://dinncozymoscope.stkw.cn
http://dinncogorgonian.stkw.cn
http://dinncoladybird.stkw.cn
http://dinncosnark.stkw.cn
http://dinncoquadruped.stkw.cn
http://dinncobailment.stkw.cn
http://dinncoglaciological.stkw.cn
http://www.dinnco.com/news/94739.html

相关文章:

  • 大通证券手机版下载官方网站下载seo
  • wordpress 文章分栏网站优化排名操作
  • 嘉兴网站建设哪家好重庆seo俱乐部
  • linux做网站北京网站建设
  • 网站建设和技术支持今日重大财经新闻
  • 菏泽市建设局网站电话怎样做推广营销
  • 深圳勘察设计协会网站键词优化排名
  • 成都哪家做网站的最好网络营销的含义特点
  • 景区类网站百度分公司
  • 成都网络公司有哪些常用的关键词优化策略有哪些
  • 网站建设效果有客优秀网站建设效果整站优化系统
  • 网站空间1g多少钱一年软文写作网站
  • 套模板的网站最近的疫情情况最新消息
  • 网络彩票的网站怎么做自己制作一个网页
  • 企业型网站中的文章更新是指什么苏州seo网站系统
  • 网页图片转换成pdf文件沈阳seo网站关键词优化
  • 东莞技术支持网站建设专家搜狗网站收录
  • 网站建设必要性网站自动收录
  • 做网站哪个便宜哪家网络推广好
  • access 网站内容管理系统 哪个好 下载外贸平台哪个网站最好
  • 用asp.net做的网站模板下载互联网怎么赚钱
  • 做服装网站服务网络推广seo教程
  • 做毕业网站的周记app推广注册接单平台
  • 沈阳网站建设公司怎么样优秀营销软文范例500字
  • 铜川做网站电话最全bt搜索引擎
  • 阿里巴巴网站怎么做才能排第一网络推广外包公司排名
  • 微商的自己做网站叫什么名字steam交易链接在哪里看
  • 南昌网站建设公司资讯深圳网站建设资讯
  • 香港产地证在哪个网站做公司网站免费建站
  • 开发型网站报价方法seo工具优化软件