zoukankan      html  css  js  c++  java
  • Guava-Retrying 请求重试机制

    使用Guava-Retrying,请求重试

    public static Object callMethod(String url, String method, Object[] args, Class[] clzs){
            Callable<Object> task = ()->{
                System.out.println("远程调用");
                if(isDebug) {
                    log.debug("远程调用方法地址, ip:{},  method:{}", url, method);
                }
                Object[] objs = getRPCSvcClient(url + CAS_PATH, TIME_OUT_MILL_SECONDS)
                        .invokeBlocking(new QName(NS_ESBMNG, method), args, clzs);
                if(isDebug) {
                    log.debug("远程调用方法结束:" + Arrays.toString(objs));
                }
                return objs == null ? null: objs[0];
            };
    
            Retryer<Object> retryer = RetryerBuilder.<Object>newBuilder()
                            .retryIfException()
                            .withWaitStrategy(WaitStrategies.fixedWait(3, TimeUnit.SECONDS))
                            .withStopStrategy(StopStrategies.stopAfterAttempt(3)).build();
            Object object = null;
            try{
                object = retryer.call(task);
            }catch (Exception e){
                log.error("重试三次后,远程调用失败:"+e.getMessage(),e);
                OprResult oprResult = new OprResult();
                oprResult.setRspCode("8888");
                oprResult.setRspMessage(e.getMessage());
                return oprResult;
            }
            return object;
        }

    进行代码重试

    待完善。。。

  • 相关阅读:
    HashMap数据结构分析(jdk8)
    ConcurrentHashMap数据结构(jdk8)
    TOJ1373_多项式规律
    Windows程序基础——Windows应用程序的基本概念
    Why to learn MFC?
    TOJ1062
    TOJ1369
    TOJ1003
    vue 生命周期~~
    如何跨域访问的两种方法~
  • 原文地址:https://www.cnblogs.com/lidedong/p/14700193.html
Copyright © 2011-2022 走看看