寻找现在已弃用的 retryWhen 的替代方案

     2023-02-27     16

关键词:

【中文标题】寻找现在已弃用的 retryWhen 的替代方案【英文标题】:Looking for an alternative of retryWhen which is now Deprecated 【发布时间】:2020-10-06 16:34:43 【问题描述】:

我遇到了WebClientreactor-extra 的问题。确实,我有以下方法:

public Employee getEmployee(String employeeId) 
            return webClient.get()
                    .uri(FIND_EMPLOYEE_BY_ID_URL, employeeId)
                    .retrieve()
                    .onStatus(HttpStatus.NOT_FOUND::equals, clientResponse -> Mono.empty())
                    .onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new MyCustomException("Something went wrong calling getEmployeeById")))
                    .bodyToMono(Employee.class)
                    .retryWhen(Retry.onlyIf(ConnectTimeoutException.class)
                             .fixedBackoff(Duration.ofSeconds(10))
                             .retryMax(3))
                    .block();
    

我发现我可以使用retryWhen(Retry.onlyIf(...)),因为我只想在抛出ConnectTimeoutException 时重试。我从这篇文章中找到了这个解决方案:spring webclient: retry with backoff on specific error

但是,在最新版本的reactor 中,不推荐使用以下方法:

public final Mono<T> retryWhen(Function<Flux<Throwable>, ? extends Publisher<?>> whenFactory)

经过数小时的谷歌搜索,我还没有找到任何解决这个问题的方法:retryWhenRetry.onlyIf 有没有最新版本的reactor 的替代品

感谢您的帮助!

【问题讨论】:

【参考方案1】:

Retry 曾经本质上是作为reactor-extra 的一部分分发的实用函数生成器。 API 现在已经进行了一些更改,并被引入reactor-core (reactor.util.retry.Retry),旧的retryWhen() 变体已弃用。因此,无需再包含额外内容 - 在您的情况下,您可以执行以下操作:

.retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(10))
        .filter(e -> e instanceof ConnectTimeoutException))

【讨论】:

非常感谢,这正是我所寻找的 :) 感谢您的解释:D 在 reactor-extra 3.4.1 中找不到 Retry.fixedDelay... @user1955934 正如答案 - 你需要的课程现在在reactor-core,而不是reactor-extra

替代已弃用的 AudioManager.isWiredHeadsetOn?

...】:方法AudioManager.isWiredHeadsetOn()从api级别14被弃用,我们现在如何检测是否连接了有线耳机?【问题讨论】:【参考方案1】:这是我的解决方案:p 查看详情

BitmapDrawable 已弃用的替代方案

】BitmapDrawable已弃用的替代方案【英文标题】:BitmapDrawabledeprecatedalternative【发布时间】:2012-04-1606:11:56【问题描述】:我有以下代码可以将可绘制对象旋转一定的度数。publicDrawablerotateDrawable(floatangle,Contextcontext)BitmaparrowBitmap=Bitm... 查看详情

已弃用的 google plus api 的替代解决方案是啥?

】已弃用的googleplusapi的替代解决方案是啥?【英文标题】:Whatisthealternativesolutionofdeprecatedgoogleplusapi?已弃用的googleplusapi的替代解决方案是什么?【发布时间】:2019-06-2315:43:08【问题描述】:Google宣布在3月7日弃用所有googleplusapi... 查看详情

OAuth2FeignRequestInterceptor 的替代方案,依赖于已弃用的类

】OAuth2FeignRequestInterceptor的替代方案,依赖于已弃用的类【英文标题】:AlternativeforOAuth2FeignRequestInterceptorthatdependsonadeprecatedclass【发布时间】:2020-05-0511:07:44【问题描述】:免责声明:老实说,我尝试在google/github上搜索,扫描了... 查看详情

System.Json 已弃用。啥是替代方案? [关闭]

...动应用程序实现JSONapi。尽管许多示例使用System.Json,但它现在已被弃用。它目前在.NET中的替代品是什么?【问题讨论】 查看详情

iOS 12.0 替代使用已弃用的 archiveRootObject:toFile:

】iOS12.0替代使用已弃用的archiveRootObject:toFile:【英文标题】:iOS12.0AlternativetoUsingDeprecatedarchiveRootObject:toFile:【发布时间】:2019-05-0322:47:12【问题描述】:在iOS12中,archiveRootObject:toFile:已被弃用。任何人都可以提出一种简化的替代... 查看详情

pymxs 替代已弃用的 MaxPlus 实用程序函数

...400:11:17【问题描述】:随着Autodesk从3dsMax中删除MaxPlus,我现在不得不重新编写一些代码,并且想知道是否有其他方法可以访问某些MaxPlus实用程序功能。虽然我认为将python开发整合到pymxs下的决定 查看详情

Android:替代已弃用的 Context.MODE_WORLD_READABLE?

...写入文件并可供其他应用程序和其他意图访问的方法,但现在Context.MODE_WORLD_READABLE已弃用,我该如何安 查看详情

图像中已弃用的 Notification 类的替代方法是啥?

】图像中已弃用的Notification类的替代方法是啥?【英文标题】:WhatisthealternativeforthedeprecatedNotificationclassintheimage?图像中已弃用的Notification类的替代方法是什么?【发布时间】:2014-02-1811:14:20【问题描述】:我打算在android设备的... 查看详情

是否有快速替代已弃用的“SKPaymentTransaction.transactionReceipt”?

】是否有快速替代已弃用的“SKPaymentTransaction.transactionReceipt”?【英文标题】:Isthereafastreplacementfordeprecate`SKPaymentTransaction.transactionReceipt`?【发布时间】:2014-05-1513:41:45【问题描述】:是否有快速替代已弃用的SKPaymentTransaction.tran... 查看详情

已弃用的 Hibernate.createClob(Reader reader, int length) 的替代方法是啥

】已弃用的Hibernate.createClob(Readerreader,intlength)的替代方法是啥【英文标题】:WhatisthealternatefordeprecatedHibernate.createClob(Readerreader,intlength)已弃用的Hibernate.createClob(Readerreader,intlength)的替代方法是什么【发布时间】:2012-02-1601:23:11【 查看详情

Gtk.stock 已弃用,有啥替代方案?

】Gtk.stock已弃用,有啥替代方案?【英文标题】:Gtk.stockisdeprecated,what\'sthealternative?Gtk.stock已弃用,有什么替代方案?【发布时间】:2016-08-1618:34:43【问题描述】:我一直在学习开发Gtk,网上的大多数示例都建议使用Gtk.stock图标... 查看详情

已弃用的 NSURLConnection 方法,有替代方法吗?

】已弃用的NSURLConnection方法,有替代方法吗?【英文标题】:DeprecatedNSURLConnectionMethods,isthereanalternative?【发布时间】:2012-02-2814:12:26【问题描述】:我正在设置一个NSURLConnection来访问远程服务器:NSURL*url=[[NSURLalloc]initWithString:proj... 查看详情

如何为已弃用的英特尔 IPP API 找到替代 API?

】如何为已弃用的英特尔IPPAPI找到替代API?【英文标题】:HowtofindalternativeAPIsfordeprecatedIntelIPPAPIs?【发布时间】:2014-11-0410:11:49【问题描述】:我正在与IntelIntegratedPerformancePrimitives(IntelIPP8.2)合作。我正在尝试使用来自UtilityFunction... 查看详情

[FFmpeg]啥是已弃用的 avpicture_alloc、avpicture::data 的替代品

】[FFmpeg]啥是已弃用的avpicture_alloc、avpicture::data的替代品【英文标题】:[FFmpeg]whatisreplacementsofavpicture_alloc,avpicture::datawhichweredeprecated[FFmpeg]什么是已弃用的avpicture_alloc、avpicture::data的替代品【发布时间】:2016-04-1204:47:35【问题描... 查看详情

Android getAllNetworkInfo() 已弃用。啥是替代方案?

】AndroidgetAllNetworkInfo()已弃用。啥是替代方案?【英文标题】:AndroidgetAllNetworkInfo()isDeprecated.Whatisthealternative?AndroidgetAllNetworkInfo()已弃用。什么是替代方案?【发布时间】:2015-11-2110:09:26【问题描述】:我想使用ConnectivityManager提... 查看详情

Facebook 的 ShareLinkContent 已弃用 Android 功能的替代解决方案是啥?

】Facebook的ShareLinkContent已弃用Android功能的替代解决方案是啥?【英文标题】:WhatisthealternatesolutionforFacebook\'sShareLinkContentdeprecatedfunctionsforAndroid?Facebook的ShareLinkContent已弃用Android功能的替代解决方案是什么?【发布时间】:2018-03-... 查看详情

channel 或 mutablesharedflow ,哪个是已弃用的 localbroadcastmanager 的更好替代品

】channel或mutablesharedflow,哪个是已弃用的localbroadcastmanager的更好替代品【英文标题】:channelormutablesharedflow,whichoneisabetterreplacementfordeprecatedlocalbroadcastmanager【发布时间】:2021-04-0321:15:20【问题描述】:过去,我在聊天和出租车应... 查看详情