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

您的位置:首頁技術文章
文章詳情頁

Spring的異常重試框架Spring Retry簡單配置操作

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

相關api見:點擊進入

/* * 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的簡單配置做一個講解:

首先引入maven依賴:

<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('發送消息異常'); JSONObject jsonTexts = (JSONObject) JSON.parse(string); if (jsonTexts.get('errcode') != null) { String errcode = jsonTexts.get('errcode').toString(); if (errcode == null) {throw new RemoteAccessException('發送消息異常'); } if (Integer.parseInt(errcode) == 0) {return true; } else {throw new RemoteAccessException('發送消息異常'); } } else { throw new RemoteAccessException('發送消息異常'); } } catch (Exception e) { logger.error('wz:customSend:{}', ExceptionUtils.getStackTrace(e)); throw new RemoteAccessException('發送消息異常'); }}

注解內容介紹:

@Retryable注解

被注解的方法發生異常時會重試

value:指定發生的異常進行重試

include:和value一樣,默認空,當exclude也為空時,所有異常都重試

exclude:指定異常不重試,默認空,當include也為空時,所有異常都重試

maxAttemps:重試次數,默認3

backoff:重試補償機制,默認沒有

@Backoff注解

delay:指定延遲后重試

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

注意:

1、使用了@Retryable的方法不能在本類被調用,不然重試機制不會生效。也就是要標記為@Service,然后在其它類使用@Autowired注入或者@Bean去實例才能生效。

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

3、在重試期間這個方法是同步的,如果使用類似Spring Cloud這種框架的熔斷機制時,可以結合重試機制來重試后返回結果。

4、Spring Retry不僅能注入方式去實現,還可以通過API的方式實現,類似熔斷處理的機制就基于API方式實現會比較寬松。

以上這篇Spring的異常重試框架Spring Retry簡單配置操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
91九色精品| 亚洲精品极品少妇16p| 麻豆一区二区99久久久久| 国产精品网在线观看| 国产伊人久久| 最新国产精品久久久| 国产在线观看www| 免费久久精品| 欧美精品国产一区| 久久中文精品| 国产精品高清一区二区| 日韩视频精品在线观看| 四虎精品永久免费| 日本免费一区二区三区四区| 国产亚洲一卡2卡3卡4卡新区| 亚洲免费婷婷| 欧美羞羞视频| 久久精品国产网站| 亚洲人成精品久久久| 性欧美xxxx免费岛国不卡电影| 91一区二区| 国产美女亚洲精品7777| 综合激情一区| 国产精品社区| 亚州国产精品| 日韩在线免费| 婷婷激情一区| 在线一区av| 好吊日精品视频| 综合亚洲自拍| 国产伦理一区| 日韩精品中文字幕第1页| 99精品电影| 久久最新视频| 久久99久久久精品欧美| 国产拍在线视频| 欧美日韩视频一区二区三区| 少妇精品久久久一区二区| 国产精品成人一区二区网站软件| 国产资源在线观看入口av| 日本不卡高清| 国产探花一区| 成人精品天堂一区二区三区| 国产精品久久久久久久免费观看| 日韩av字幕| 亚洲三级视频| 亚洲精品看片| 亚洲精品a级片| 国产日韩在线观看视频| 国产一区成人| 伊人久久亚洲美女图片| 亚洲网站视频| 日精品一区二区三区| 蜜臀av免费一区二区三区| 国产精品久久亚洲不卡| 激情久久五月| 日韩激情视频网站| 高清久久精品| 久久中文字幕av| 日韩在线麻豆| 奶水喷射视频一区| 精品99久久| 欧美日韩1区| 爽好久久久欧美精品| 欧美激情视频一区二区三区免费 | 免费一级欧美片在线观看网站 | 国产一区二区三区亚洲| 视频一区日韩| 免费视频一区二区| 国产精品一区二区免费福利视频| 久久不见久久见中文字幕免费 | 综合一区在线| 国产精品2区| 欧美特黄视频| 视频福利一区| 日韩av资源网| 国产精品美女午夜爽爽| 国产一区二区三区不卡视频网站 | 日韩精品一区二区三区免费视频| 精品国产91| 欧美国产另类| 亚洲高清激情| 丝袜亚洲另类欧美| 久久av网址| 免费在线观看日韩欧美| 国产精品亚洲片在线播放| 水野朝阳av一区二区三区| 国产亚洲激情| 免费观看不卡av| 欧美1级日本1级| 国产日韩三级| 蜜桃久久精品一区二区| 国产亚洲激情| 丝袜亚洲另类欧美| 日韩高清在线一区| 黄色网一区二区| 日本中文字幕不卡| 日韩在线观看不卡| 亚洲国产福利| 91青青国产在线观看精品| 国产精品亚洲综合在线观看| 蜜桃免费网站一区二区三区| 红桃视频亚洲| 日韩av免费大片| 免费在线观看日韩欧美| 色婷婷精品视频| 欧美不卡在线| 亚洲免费一区三区| 98精品视频| 亚洲福利专区| 一本大道色婷婷在线| 国产精品久久久久蜜臀| av免费不卡国产观看| 精品高清久久| 久久三级中文| 日韩激情精品| 麻豆传媒一区二区三区| 国产精品jk白丝蜜臀av小说| 天堂va蜜桃一区二区三区| 国产精品日本一区二区三区在线| 亚洲欧美日本日韩| 欧美视频久久| 99国产精品| 国产精品亚洲欧美一级在线| 99在线|亚洲一区二区| 香蕉久久国产| 国产日韩欧美| 欧洲毛片在线视频免费观看| 日韩久久电影| 欧美专区一区二区三区| 国产一区亚洲| а√天堂8资源在线| 久久国产高清| 国产精品人人爽人人做我的可爱| 高清av不卡| 综合日韩av| 精品在线91| 岛国av免费在线观看| 久久蜜桃精品| 亚洲69av| 悠悠资源网久久精品| 亚洲精品影院在线观看| 日韩高清欧美激情| av亚洲免费| 日韩中文字幕不卡| 久久这里只有| 欧美亚洲激情| 国产一区成人| 国产精品magnet| 久久久久一区| 国产一区久久| 日本欧美大码aⅴ在线播放| 国产精品白丝久久av网站| 国产欧美一区二区精品久久久 | 免费精品视频| 首页国产精品| 亚洲国产专区| 日韩精品午夜| 欧美不卡高清一区二区三区| 快she精品国产999| 日本不卡中文字幕| 国产综合亚洲精品一区二| 美女视频黄久久| 日韩中文在线电影| 丝袜美腿亚洲一区二区图片| 精品欧美激情在线观看| 四虎精品一区二区免费| 国产精品久久| 久久精品国产大片免费观看| 欧产日产国产精品视频| 亚洲成人精品| 一区二区精品| 日韩精品欧美| 视频在线观看一区二区三区| 欧美精品自拍| 国产精品久久久久久久久妇女| 亚洲91网站| 欧美精品aa| 免费在线观看一区| 日韩国产欧美视频| 国产精品xxx在线观看| 国产精品成人自拍| 免费在线欧美黄色| 日本不卡的三区四区五区| 亚洲区欧美区| 国产精品亚洲成在人线| 99久久精品网| 婷婷精品视频| 久久av电影| 日本欧美在线看| 国产精品一区二区三区av麻| 欧美xxxx中国| 伊人成人网在线看| 日韩va亚洲va欧美va久久| 成人三级高清视频在线看| 今天的高清视频免费播放成人| 国产不卡av一区二区| 麻豆久久一区| 日本亚州欧洲精品不卡| 麻豆91精品91久久久的内涵|