日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Spring的異常重試框架Spring Retry簡(jiǎn)單配置操作

瀏覽:160日期:2023-08-13 15:40:25

相關(guān)api見(jiàn):點(diǎn)擊進(jìn)入

/* * Copyright 2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.retry.annotation; import java.lang.annotation.Documented;import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target; /** * Annotation for a method invocation that is retryable. * * @author Dave Syer * @author Artem Bilan * @author Gary Russell * @since 1.1 * */@Target({ ElementType.METHOD, ElementType.TYPE })@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Retryable { /** * Retry interceptor bean name to be applied for retryable method. Is mutually * exclusive with other attributes. * @return the retry interceptor bean name */String interceptor() default ''; /** * Exception types that are retryable. Synonym for includes(). Defaults to empty (and * if excludes is also empty all exceptions are retried). * @return exception types to retry */Class<? extends Throwable>[] value() default {}; /** * Exception types that are retryable. Defaults to empty (and if excludes is also * empty all exceptions are retried). * @return exception types to retry */Class<? extends Throwable>[] include() default {}; /** * Exception types that are not retryable. Defaults to empty (and if includes is also * empty all exceptions are retried). * @return exception types to retry */Class<? extends Throwable>[] exclude() default {}; /** * A unique label for statistics reporting. If not provided the caller may choose to * ignore it, or provide a default. * * @return the label for the statistics */String label() default ''; /** * Flag to say that the retry is stateful: i.e. exceptions are re-thrown, but the * retry policy is applied with the same policy to subsequent invocations with the * same arguments. If false then retryable exceptions are not re-thrown. * @return true if retry is stateful, default false */boolean stateful() default false; /** * @return the maximum number of attempts (including the first failure), defaults to 3 */int maxAttempts() default 3; /** * @return an expression evaluated to the maximum number of attempts (including the first failure), defaults to 3 * Overrides {@link #maxAttempts()}. * @since 1.2 */String maxAttemptsExpression() default ''; /** * Specify the backoff properties for retrying this operation. The default is a * simple {@link Backoff} specification with no properties - see it’s documentation * for defaults. * @return a backoff specification */Backoff backoff() default @Backoff(); /** * Specify an expression to be evaluated after the {@code SimpleRetryPolicy.canRetry()} * returns true - can be used to conditionally suppress the retry. Only invoked after * an exception is thrown. The root object for the evaluation is the last {@code Throwable}. * Other beans in the context can be referenced. * For example: * <pre class=code> * {@code 'message.contains(’you can retry this’)'}. * </pre> * and * <pre class=code> * {@code '@someBean.shouldRetry(#root)'}. * </pre> * @return the expression. * @since 1.2 */String exceptionExpression() default ''; }

下面就 Retryable的簡(jiǎn)單配置做一個(gè)講解:

首先引入maven依賴(lài):

<dependency> <groupId>org.springframework.retry</groupId> <artifactId>spring-retry</artifactId> <version>RELEASE</version> </dependency>

然后在方法上配置注解@Retryable

@Override@SuppressWarnings('Duplicates')@Retryable(value = {RemoteAccessException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000l, multiplier = 0))public boolean customSendText(String openid, String content) throws RemoteAccessException { String replyString = '{n' + ''touser':' + openid + ',n' + ''msgtype':'text',n' + ''text':n' + '{n' + ''content':' + content + 'n' + '}n' + '}'; try { logger.info('wx:customSend=request:{}', replyString.toString()); HttpsClient httpClient = HttpsClient.getAsyncHttpClient(); String url = Constant.WX_CUSTOM_SEND; String token = wxAccessokenService.getAccessToken(); url = url.replace('ACCESS_TOKEN', token); logger.info('wx:customSend=url:{}', url); String string = httpClient.doPost(url, replyString); logger.info('wx:customSend=response:{}', string); if (StringUtils.isEmpty(string)) throw new RemoteAccessException('發(fā)送消息異常'); JSONObject jsonTexts = (JSONObject) JSON.parse(string); if (jsonTexts.get('errcode') != null) { String errcode = jsonTexts.get('errcode').toString(); if (errcode == null) {throw new RemoteAccessException('發(fā)送消息異常'); } if (Integer.parseInt(errcode) == 0) {return true; } else {throw new RemoteAccessException('發(fā)送消息異常'); } } else { throw new RemoteAccessException('發(fā)送消息異常'); } } catch (Exception e) { logger.error('wz:customSend:{}', ExceptionUtils.getStackTrace(e)); throw new RemoteAccessException('發(fā)送消息異常'); }}

注解內(nèi)容介紹:

@Retryable注解

被注解的方法發(fā)生異常時(shí)會(huì)重試

value:指定發(fā)生的異常進(jìn)行重試

include:和value一樣,默認(rèn)空,當(dāng)exclude也為空時(shí),所有異常都重試

exclude:指定異常不重試,默認(rèn)空,當(dāng)include也為空時(shí),所有異常都重試

maxAttemps:重試次數(shù),默認(rèn)3

backoff:重試補(bǔ)償機(jī)制,默認(rèn)沒(méi)有

@Backoff注解

delay:指定延遲后重試

multiplier:指定延遲的倍數(shù),比如delay=5000l,multiplier=2時(shí),第一次重試為5秒后,第二次為10秒,第三次為20秒

注意:

1、使用了@Retryable的方法不能在本類(lèi)被調(diào)用,不然重試機(jī)制不會(huì)生效。也就是要標(biāo)記為@Service,然后在其它類(lèi)使用@Autowired注入或者@Bean去實(shí)例才能生效。

2、使用了@Retryable的方法里面不能使用try...catch包裹,要在發(fā)放上拋出異常,不然不會(huì)觸發(fā)。

3、在重試期間這個(gè)方法是同步的,如果使用類(lèi)似Spring Cloud這種框架的熔斷機(jī)制時(shí),可以結(jié)合重試機(jī)制來(lái)重試后返回結(jié)果。

4、Spring Retry不僅能注入方式去實(shí)現(xiàn),還可以通過(guò)API的方式實(shí)現(xiàn),類(lèi)似熔斷處理的機(jī)制就基于API方式實(shí)現(xiàn)會(huì)比較寬松。

以上這篇Spring的異常重試框架Spring Retry簡(jiǎn)單配置操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
久久xxxx| 日韩在线看片| 天堂成人免费av电影一区| 欧美大黑bbbbbbbbb在线| 欧美日韩亚洲一区二区三区在线 | 久久视频一区| 综合激情在线| 中文av在线全新| 91麻豆精品| 久久久国产精品一区二区中文| 极品日韩av| 日韩在线观看| 红桃视频国产精品| 亚洲黄色免费看| 1024精品久久久久久久久| 深夜福利一区| 一本一道久久a久久精品蜜桃| 久久福利一区| 美女视频一区在线观看| 亚洲色图综合| 国产欧美大片| 亚洲免费毛片| 精品免费av| 欧美黄页在线免费观看| 日韩精品水蜜桃| 日韩精品福利一区二区三区| 亚洲乱码久久| 精品久久免费| 亚洲精选av| 中文字幕人成乱码在线观看| 免费日韩av| 精品一二三区| 三级欧美韩日大片在线看| 91久久久精品国产| 欧美在线日韩| 成人av二区| 成人午夜在线| 里番精品3d一二三区| 久久精品亚洲人成影院| 国产精品一站二站| 1024精品久久久久久久久| 国产精品2区| 国产欧美亚洲精品a| 欧美gv在线| 日本精品影院| 欧美午夜三级| 亚洲激情另类| 成人在线免费观看网站| 亚洲bt欧美bt精品777| 亚洲精品国产嫩草在线观看| 国产日韩1区| 石原莉奈在线亚洲二区| 亚洲91视频| 国产一区国产二区国产三区| 欧美在线精品一区| 美女久久一区| 婷婷成人综合| 精品国产99| 国产精品一卡| 日本午夜精品久久久久| 久久国产精品亚洲77777| 五月天av在线| 精品理论电影在线| 国产精品色在线网站| 热久久国产精品| 欧美va天堂| 日本韩国欧美超级黄在线观看| 精品国产18久久久久久二百| 国产精品一站二站| 青青草视频一区| 日欧美一区二区| 免费一区二区视频| 亚洲黄页一区| 好吊日精品视频| 久久国产影院| 麻豆视频在线观看免费网站黄| 日本va欧美va欧美va精品| 亚洲一级在线| 亚洲另类视频| 亚洲一区二区三区高清不卡| 欧美日韩第一| 欧美日韩国产免费观看视频| 欧美日韩免费观看视频| 国产aⅴ精品一区二区三区久久| 免费看一区二区三区| 国产精品久久久久av蜜臀| 欧美一区=区三区| 日韩精品视频网| 日韩欧美在线精品| 日韩精品欧美成人高清一区二区| 日韩美女国产精品| 亚洲bt欧美bt精品777| 影音先锋久久精品| 香蕉久久一区| 日韩精选在线| 久久国产麻豆精品| 国产精品视频一区视频二区| 国产日韩一区| 久久久亚洲欧洲日产| 国产欧美一区二区三区国产幕精品 | 日本aⅴ亚洲精品中文乱码| 中文字幕日韩亚洲| 一区二区三区网站| 亚洲久久在线| 青草综合视频| 国产精久久久| 精品久久影院| 中文字幕系列一区| 欧美特黄一区| 亚洲狼人精品一区二区三区| 日本亚州欧洲精品不卡| 欧美日本三区| 另类欧美日韩国产在线| 捆绑调教日本一区二区三区| 神马午夜久久| 久久都是精品| 国产亚洲一区| 国产第一亚洲| 久久精品免费一区二区三区| 韩日一区二区三区| 日韩中文欧美在线| 国产精品一区二区美女视频免费看| 美女久久久精品| 亚洲www啪成人一区二区| 欧美日韩国产一区二区三区不卡| 久久国产精品99国产| 国产欧美日韩亚洲一区二区三区| 激情久久一区二区| 欧美不卡在线| 亚洲另类av| 国产精品一区2区3区| 亚洲精品成人图区| 欧美 日韩 国产精品免费观看| 老牛国产精品一区的观看方式| 日韩国产在线观看| 91视频久久| 亚洲欧美日韩专区| 国产伦理一区| 国产91精品对白在线播放| 热久久国产精品| 麻豆国产精品一区二区三区| 成人高清一区| 99精品99| 国产精品亚洲人成在99www| av高清不卡| 亚洲一级淫片| 岛国av在线网站| av不卡在线看| 欧美激情网址| 五月婷婷六月综合| 久久黄色影视| 婷婷久久一区| 欧美a在线观看| 欧美天堂亚洲电影院在线观看| 国产三级一区| 不卡中文字幕| 久久99久久久精品欧美| 黑丝美女一区二区| 麻豆视频一区二区| 亚洲综合日本| 精品一区91| 亚洲午夜免费| 国产白浆在线免费观看| 中文字幕成人| 91精品一区二区三区综合在线爱| 日韩精品午夜视频| 久久久蜜桃一区二区人| 日本麻豆一区二区三区视频| 成人羞羞在线观看网站| 91精品国产经典在线观看| 激情综合自拍| 加勒比视频一区| 日韩va亚洲va欧美va久久| 亚洲韩日在线| 免费一区二区三区在线视频| 香蕉精品999视频一区二区| 大香伊人久久精品一区二区| 日韩精品一级中文字幕精品视频免费观看 | 黄色在线网站噜噜噜| 亚洲一区av| 久久国产影院| 国产aa精品| 国产精品毛片视频| 亚洲天堂av资源在线观看| 欧美亚洲国产精品久久| 久久97久久97精品免视看秋霞| 视频一区在线播放| 亚洲综合在线电影| 精品国产一区二区三区2021| 免费视频最近日韩| 激情欧美一区| 午夜影院一区| 久久精品福利| 国产日韩精品视频一区二区三区| 中文一区二区| 欧美日韩尤物久久| 久久久久久夜| 捆绑调教美女网站视频一区| 亚洲tv在线| 巨乳诱惑日韩免费av|