Coder Social home page Coder Social logo

houbb / sisyphus Goto Github PK

View Code? Open in Web Editor NEW
177.0 7.0 68.0 256 KB

The java retry framework.(支持注解的 java 重试框架)

Home Page: https://sisyphus-doc.github.io/

License: Apache License 2.0

Batchfile 1.32% Shell 3.40% Java 95.28%
retry java-retry gauva guava-retrying spring-retry

sisyphus's Introduction

Sisyphus

Sisyphus 是支持过程式编程和注解编程的 java 重试框架。

Build Status Maven Central Open Source Love

sisyphus.jpg

特性

  • 支持 fluent 过程式编程

  • 基于字节码的代理重试

  • 基于注解的重试,允许自定义注解

  • 无缝接入 spring

  • 无缝接入 spring-boot

  • 接口与注解的统一

  • 解决 spring-retry 与 guava-retrying 中的不足之处

v0.1.0 变更

  • Recover 上下文增加入参,更加便于业务处理

更新记录

更新记录

设计目的

综合了 spring-retry 和 gauva-retrying 的优势。

调整一些特性,使其更利于实际使用。

采用 Netty 类似的接口**,保证接口的一致性,和替换的灵活性。

借鉴 Hibernate-Validator 的设计,允许用户自定义注解。

spring-retry 与 guava-retrying 中的不足之处

开源地址

sisyphus

快速开始

引入

<dependency>
    <groupId>com.github.houbb</groupId>
    <artifactId>sisyphus-core</artifactId>
    <version>0.1.0</version>
</dependency>

入门代码

详情参见 RetryerTest

public void helloTest() {
    Retryer.<String>newInstance()
            .callable(new Callable<String>() {
                @Override
                public String call() throws Exception {
                    System.out.println("called...");
                    throw new RuntimeException();
                }
            }).retryCall();
}

代码分析

  • callable

指定一个 callable 的实现。

我们打印一条日志,并且模拟一个程序异常。

日志信息

日志信息

called...
called...
called...

和一些其他异常信息。

重试触发的条件,默认是程序发生了异常

这里的重试间隔默认为没有时间间隔,一共尝试3次。(包括第一次程序本身执行)

拓展阅读

00-sisyphus 是什么

01-为什么选择 sisyphus

02-sisyphus 模块简介

03-sisyphus 快速开始

04-sisyphus 配置概览

05-sisyphus 注解简介

06-sisyphus 代理模板

07-sisyphus spring 整合

08-sisyphus springboot 整合

后期 Road-MAP

  • 丰富上下文信息

  • 丰富重试统计信息

中间件等工具开源矩阵

heaven: 收集开发中常用的工具类

rpc: 基于 netty4 实现的远程调用工具

mq: 简易版 mq 实现

ioc: 模拟简易版 spring ioc

mybatis: 简易版 mybatis

cache: 渐进式 redis 缓存

jdbc-pool: 数据库连接池实现

sandglass: 任务调度时间工具框架

sisyphus: 支持注解的重试框架

resubmit: 防止重复提交框架,支持注解

auto-log: 日志自动输出

async: 多线程异步并行框架

sisyphus's People

Contributors

dependabot[bot] avatar houbb avatar mystery00 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sisyphus's Issues

重试方法切点定义范围太大

提一个问题,的切点定义的是所有的public方法
@pointcut("execution(public * *(..))")
需要修改成只监听对应注解的方法,不然项目启动不允许这么大范围的AOP,我们目前是自己覆写了

重试时的方法和参数是否能进行持久化

1、对重试的方法和参数进行持久化,当重试超过多少次失败,进行持久化。等待一段时间,再次进行重试。让方法得以最终执行。
2、此种应用场景是在最终一致性的时候进行,比如当外部服务失效一段时间。这个时候我需要进行回补操作,使得数据最终一致。

DefaultRetry的等待时间计算问题

DefaultRetry在计算等待时间时,作者本人默认提供的几种实现中因为默认都是以毫秒为单位的,但是并没有限定其扩展性,自己扩展了一个试了下,发现一个问题,需要将其中的117行的
totalTimeMills += waitTime.unit().convert(waitTime.time(), TimeUnit.MILLISECONDS);
改成:
totalTimeMills += TimeUnit.MILLISECONDS.convert(waitTime.time(), waitTime.unit());

能否在每一次重试之前添加一个回调?

RT,目前将该框架应用到rest请求重试上,一些特殊的框架比如OkHttp在重试时,创建一个新的request时会检查上一个response是否已经关闭,目前没有好的办法去关闭上一个response,导致重试时请求失败

RetryCondition多执行了一次

我设定maxAttempt = 4,重试方法确实是4次。
但是RetryCondition多执行了一次。
image

com.github.houbb sisyphus-springboot-starter 0.0.9

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.