新增本地重试自定义方法的测试接口

This commit is contained in:
byteblogs168 2023-09-10 10:04:49 +08:00
parent a5e745ad28
commit 4a3644e7c7
3 changed files with 26 additions and 5 deletions

View File

@ -1,12 +1,10 @@
package com.example.easy.retry.controller;
import com.example.easy.retry.service.LocalRetryService;
import com.example.easy.retry.vo.OrderVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.example.easy.retry.service.impl.LocalRetryServiceImpl;
@ -92,4 +90,16 @@ public class LocalRetryController {
public void localRetryIsThrowException(@RequestParam("params") String params){
localRetryService.localRetryIsThrowException(params);
}
@PostMapping("/localRetryWithRetryMethod")
/**
* 使用自定义的异常处理类 OrderRetryMethod
*/
@ApiOperation(
value = "指定自定义的异常处理类",
notes ="🥇什么是自定义的异常处理类: https://www.easyretry.com/pages/540554/#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E6%89%A7%E8%A1%8C%E5%99%A8"
)
public boolean localRetryWithRetryMethod(@RequestBody OrderVo orderVo){
return localRetryService.localRetryWithRetryMethod(orderVo);
}
}

View File

@ -2,6 +2,7 @@ package com.example.easy.retry.service;
import com.aizuda.easy.retry.client.core.annotation.Retryable;
import com.aizuda.easy.retry.client.core.retryer.RetryType;
import com.example.easy.retry.vo.OrderVo;
/**
* @author: www.byteblogs.com
@ -22,5 +23,6 @@ public interface LocalRetryService {
void localRetryIsThrowException(String params);
boolean localRetryWithRetryMethod(OrderVo orderVo);
}

View File

@ -1,7 +1,9 @@
package com.example.easy.retry.service.impl;
import com.aizuda.easy.retry.client.core.retryer.RetryType;
import com.example.easy.retry.customized.OrderRetryMethod;
import com.example.easy.retry.service.LocalRetryService;
import com.example.easy.retry.vo.OrderVo;
import org.springframework.stereotype.Component;
import com.aizuda.easy.retry.client.core.annotation.Retryable;
@ -9,7 +11,6 @@ import com.example.easy.retry.exception.ParamException;
/**
* easy-retry中的本地重试demo
* 测试类入口见 {@link com.example.easy.retry.local.RetryableTest}
*/
@Component
@ -93,4 +94,12 @@ public class LocalRetryServiceImpl implements LocalRetryService {
System.out.println("local retry is throw exception 方法开始执行");
throw new ParamException("此处发生了参数异常");
}
@Override
@Retryable(scene = "localRetryWithRetryMethod", retryStrategy = RetryType.ONLY_LOCAL,
retryMethod = OrderRetryMethod.class)
public boolean localRetryWithRetryMethod(OrderVo orderVo) {
throw new NullPointerException();
}
}