Solon v3.0.3

Retry 调度(重试)

</> markdown

引入调度相关的插件。v2.4.1 后支持

<dependency>
    <groupId>org.noear</groupId>
    <artifactId>solon-scheduling</artifactId>
</dependency>

启用重试调度

@EnableRetry
public class DemoApp{
    public void static void main(String[] args){
        Solon.start(DemoApp.class, args);
    }
}

定义重试执行的服务

//定义个服务
@Component
public class RetryTask {
    //有异常,会重试执行
    @Retry(Throwable.class)
    public void test(String hint){
        System.out.println(Thread.currentThread().getName());
    }
}

//如果需要保底
@Component
public class RetryTask implements Recover {
    //有异常,会重试执行
    @Retry(include=Throwable.class, recover=RetryTask.class) //保底可能是任何 Recover 实现
    public void test(String hint){
        System.out.println(Thread.currentThread().getName());
    }
    
    @Override
    public Object recover(Callee callee, Throwable e) throws Throwable{
        //保底处理
        return null;
    }
}

应用示例

//应用
@Controller
public class DemoController{
    @Inject
    RetryTask retryTask;
    
    @Mapping("/test")
    public void test(){
        //调用
        retryTask.test("test");
    }
}