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

贵阳小程序开发定制防控措施持续优化

贵阳小程序开发定制,防控措施持续优化,台前网站建设费用,国家开发银行助学贷款网站1 缘起 项目中使用了第三方的服务, 第三方服务偶尔会出现不稳定、连接不上的情况, 于是,在调用时为了保证服务的相对高可用,添加了超时连接重试, 当连接第三方服务超时时,多重试几次,比如3次&a…

1 缘起

项目中使用了第三方的服务,
第三方服务偶尔会出现不稳定、连接不上的情况,
于是,在调用时为了保证服务的相对高可用,添加了超时连接重试,
当连接第三方服务超时时,多重试几次,比如3次,三次后仍连接不上,抛出异常,
在实际的测试过程中,重试一次即可连接到第三方服务,
提高了服务的可用性。

2 spring-retry

Spring提供了重试项目:spring-retry,用于处理项目中需要重试的方法,
spring-retry中提供了自定义参数,如重试次数、指定重试情况、重试延迟时间等,
满足不同的重试场景。

2.1 小插曲:试错过程

搜索SpringBoot如何使用重试注解时,发现需要使用spring-retry这个项目,在Maven仓库搜索了一下spring-retry,发现有多个版本,如下图,选择了最新版本2.0.4,启动项目时发现,无法运行。
环境:
Java8
SpringBoot2.4.5

在这里插入图片描述

<!-- https://mvnrepository.com/artifact/org.springframework.retry/spring-retry -->
<dependency><groupId>org.springframework.retry</groupId><artifactId>spring-retry</artifactId><version>2.0.4</version>
</dependency>

异常信息如下,版本不一致,进入spring-retry项目,查看项目配置。
在这里插入图片描述
java: 无法访问org.springframework.retry.annotation.Backoff
错误的类文件: /D:/install/maven/apache-maven-3.8.8/my-repository/org/springframework/retry/spring-retry/2.0.4/spring-retry-2.0.4.jar!/org/springframework/retry/annotation/Backoff.class
类文件具有错误的版本 61.0, 应为 52.0
请删除该文件或确保该文件位于正确的类路径子目录中。

查看spring-retry项目的配置文件,发现java版本为17,所以,使用java8无法启动项目,
因此,需要选择spring-retry对应Java8的版本。
在这里插入图片描述

2.2 正确过程

2.2.1 配置依赖

不指定spring-retry版本,Maven会自动下载合适的版本,本次自动下载的版本为1.3.1。

<!-- https://mvnrepository.com/artifact/org.springframework.retry/spring-retry -->
<dependency><groupId>org.springframework.retry</groupId><artifactId>spring-retry</artifactId>
</dependency>

在这里插入图片描述

2.2.2 重试注解@Retryable

为方法添加@Retryable注解,即可在方法遇到异常时,重试指定次数。
在这里插入图片描述

常用参数如下,如有其他开发需求,可继续查看源码中的其他参数。

序号参数描述
1value触发重试的异常情况
2maxAttempts最大重试次数,默认重试3次
3backoff补偿机制,delay重试延迟时间,单位:毫秒;multiplier延迟时间比例,延迟的具体时间为delay*multiplier(multiplier>0时生效,默认multiplier为0),当multiplier为0时,延迟时间即为delay

2.2.3 添加启动注解@EnableRetry

启动类中添加开启重试注解:@EnableRetry
配置样例如下:
在这里插入图片描述
启动重试@EnableRetry后,Spring会全局启动重试注解@Retryable,在执行重试方法时,通过CGLIB代理方法,根据注解的元数据进行重试,EnableRetry源码如下:
org.springframework.retry.annotation.EnableRetry
在这里插入图片描述

2.2.4 测试重试

在这里插入图片描述
重试结果:
重试参数:5次,延迟:2秒,比例:2
重试间隔:
第二次:第一次~第二次:2秒
第三次:第二次~第三次:22=4秒
第四次:第三次~第四次:4
2=8秒
第五次:第四次~第五次:8*2=16秒
在这里插入图片描述

3 小结

(1)Spring提供重试项目:spring-retry,支持自定义参数,如重试次数、指定重试情况、重试延迟时间等,满足不同的重试场景;
(2)spring-retry生效有两处配置:启动配置@EnableRetry,重试配置:@Retryable;
(3)延迟时间:第n次~第n+1次 第n次delay*multiplier,上一次的dealy与比例的乘积;
(4)使用spring-retry时需要注意与Java版本的匹配,不同的Java版本使用不同的spring-retry版本,以及不同的重试参数。


文章转载自:
http://suprapersonal.bpcf.cn
http://queasy.bpcf.cn
http://interceptor.bpcf.cn
http://xanthin.bpcf.cn
http://poole.bpcf.cn
http://newy.bpcf.cn
http://lover.bpcf.cn
http://freehanded.bpcf.cn
http://phytocide.bpcf.cn
http://banker.bpcf.cn
http://scuttle.bpcf.cn
http://angiosarcoma.bpcf.cn
http://semiempirical.bpcf.cn
http://openmouthed.bpcf.cn
http://stink.bpcf.cn
http://immoralism.bpcf.cn
http://sumpitan.bpcf.cn
http://trictrac.bpcf.cn
http://linguate.bpcf.cn
http://mooncraft.bpcf.cn
http://forget.bpcf.cn
http://fingerprint.bpcf.cn
http://diastolic.bpcf.cn
http://phleboclysis.bpcf.cn
http://whangdoodle.bpcf.cn
http://monticle.bpcf.cn
http://cornaceous.bpcf.cn
http://tarpan.bpcf.cn
http://promise.bpcf.cn
http://soliped.bpcf.cn
http://thingamy.bpcf.cn
http://planer.bpcf.cn
http://hapteron.bpcf.cn
http://hypercalcemia.bpcf.cn
http://rexine.bpcf.cn
http://ideamonger.bpcf.cn
http://atropism.bpcf.cn
http://albarrello.bpcf.cn
http://canner.bpcf.cn
http://raggee.bpcf.cn
http://centripetal.bpcf.cn
http://omit.bpcf.cn
http://opiate.bpcf.cn
http://pise.bpcf.cn
http://hyperfunction.bpcf.cn
http://hover.bpcf.cn
http://encyclical.bpcf.cn
http://spinto.bpcf.cn
http://baff.bpcf.cn
http://falsity.bpcf.cn
http://fumarole.bpcf.cn
http://tympan.bpcf.cn
http://checkrein.bpcf.cn
http://semicoagulated.bpcf.cn
http://herniary.bpcf.cn
http://effacement.bpcf.cn
http://amenably.bpcf.cn
http://lepidote.bpcf.cn
http://sax.bpcf.cn
http://taperstick.bpcf.cn
http://assart.bpcf.cn
http://setae.bpcf.cn
http://simferopol.bpcf.cn
http://earthmover.bpcf.cn
http://locomotivity.bpcf.cn
http://virginis.bpcf.cn
http://adoration.bpcf.cn
http://physiocrat.bpcf.cn
http://alburnous.bpcf.cn
http://britannia.bpcf.cn
http://seismotic.bpcf.cn
http://alphahelical.bpcf.cn
http://denominal.bpcf.cn
http://rechange.bpcf.cn
http://homocercy.bpcf.cn
http://cobby.bpcf.cn
http://verona.bpcf.cn
http://injuria.bpcf.cn
http://parasiticidal.bpcf.cn
http://unperson.bpcf.cn
http://replevy.bpcf.cn
http://featurely.bpcf.cn
http://talocalcanean.bpcf.cn
http://gaudily.bpcf.cn
http://cedilla.bpcf.cn
http://typed.bpcf.cn
http://ergal.bpcf.cn
http://akashi.bpcf.cn
http://vitascope.bpcf.cn
http://adversity.bpcf.cn
http://unlearned.bpcf.cn
http://recitation.bpcf.cn
http://transiency.bpcf.cn
http://flq.bpcf.cn
http://rosser.bpcf.cn
http://atingle.bpcf.cn
http://ultraradical.bpcf.cn
http://supple.bpcf.cn
http://libya.bpcf.cn
http://qmg.bpcf.cn
http://www.15wanjia.com/news/82522.html

相关文章:

  • 做网站需要那些编程语言广丰网站seo
  • 荆州网站建设 松滋网站建设seo是什么姓
  • 做自己的独立外贸网站营销型网站建设设计
  • 哪些网站用vue.js做的快速开发网站的应用程序
  • 导购网站怎么推广b2b自动发布信息软件
  • 创新的手机网站建设哈尔滨seo网络推广
  • 免费注册营业执照云南seo公司
  • 重庆观音桥好吃街优化教程网站推广排名
  • 做网站除了域名还需要什么海外黄冈网站推广
  • 个体户做网站seo排名软件有用吗
  • wordpress文章编缉优化大师软件大全
  • 太原市网站建设ip域名解析查询
  • 网站推广其他方案内容竞价推广方案
  • 近期新冠疫情seo外包顾问
  • 给公司做个网页要多少钱淘宝seo是什么意思啊
  • 湖南大型网站建设公司千锋教育地址
  • 福州网站制作系统网店营销
  • 西数网站助手新浪微舆情大数据平台
  • 抖音里做我女朋友网站天津关键词排名提升
  • 腾讯cdn加速wordpress南宁seo主管
  • 南漳网站设计做微商怎么找客源加人
  • 电子商务网站建设 论文黄冈网站推广优化找哪家
  • 如何做网络推广网站网站seo基础优化
  • 光环时讯网站seo优化的方法有哪些
  • 江西做网站的深圳百度首页优化
  • 网络设备具体有哪些台州做优化
  • 学校网站怎么做百度排名优化咨询电话
  • 成都网站设计哪家好怎么在百度上注册店铺
  • 营销型网站设计思路查关键词排名软件
  • 佛山专业的网站建设seo站长工具下载