feat: 1.0.0

1. 优化代码
2. 修复客户端发生异常时,一直重试问题
This commit is contained in:
www.byteblogs.com 2023-04-19 22:46:51 +08:00 committed by byteblogs168
parent 90b802596e
commit 9260348e93
7 changed files with 32 additions and 21 deletions

View File

@ -60,7 +60,7 @@
<dependency> <dependency>
<groupId>com.caucho</groupId> <groupId>com.caucho</groupId>
<artifactId>hessian</artifactId> <artifactId>hessian</artifactId>
<version>4.0.60</version> <version>4.0.66</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>

View File

@ -57,12 +57,12 @@
<dependency> <dependency>
<groupId>net.javacrumbs.shedlock</groupId> <groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-jdbc-template</artifactId> <artifactId>shedlock-provider-jdbc-template</artifactId>
<version>5.2.0</version> <version>4.0.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.javacrumbs.shedlock</groupId> <groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId> <artifactId>shedlock-spring</artifactId>
<version>5.2.0</version> <version>4.0.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>

View File

@ -2,8 +2,8 @@ package com.aizuda.easy.retry.server.support.dispatch.actor.exec;
import akka.actor.AbstractActor; import akka.actor.AbstractActor;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.x.retry.client.model.DispatchRetryDTO; import com.aizuda.easy.retry.client.model.DispatchRetryDTO;
import com.x.retry.client.model.DispatchRetryResultDTO; import com.aizuda.easy.retry.client.model.DispatchRetryResultDTO;
import com.aizuda.easy.retry.common.core.constant.SystemConstants; import com.aizuda.easy.retry.common.core.constant.SystemConstants;
import com.aizuda.easy.retry.common.core.log.LogUtils; import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.common.core.model.Result; import com.aizuda.easy.retry.common.core.model.Result;

View File

@ -10,7 +10,7 @@ import org.springframework.util.CollectionUtils;
import java.util.*; import java.util.*;
/** /**
* 重试构建 * 重试构建
* *
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2021-11-29 18:42 * @date : 2021-11-29 18:42

View File

@ -6,6 +6,7 @@ import com.aizuda.easy.retry.server.support.FilterStrategy;
import com.aizuda.easy.retry.server.support.RetryContext; import com.aizuda.easy.retry.server.support.RetryContext;
import com.aizuda.easy.retry.server.support.StopStrategy; import com.aizuda.easy.retry.server.support.StopStrategy;
import com.aizuda.easy.retry.server.support.WaitStrategy; import com.aizuda.easy.retry.server.support.WaitStrategy;
import lombok.extern.slf4j.Slf4j;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -16,17 +17,18 @@ import java.util.concurrent.Callable;
* @author: www.byteblogs.com * @author: www.byteblogs.com
* @date : 2021-11-29 18:57 * @date : 2021-11-29 18:57
*/ */
@Slf4j
public class RetryExecutor<V> { public class RetryExecutor<V> {
private StopStrategy stopStrategy; private final StopStrategy stopStrategy;
private WaitStrategy waitStrategy; private final WaitStrategy waitStrategy;
private List<FilterStrategy> filterStrategies; private final List<FilterStrategy> filterStrategies;
private RetryContext<V> retryContext; private final RetryContext<V> retryContext;
public RetryExecutor(StopStrategy stopStrategy, public RetryExecutor(StopStrategy stopStrategy,
WaitStrategy waitStrategy, WaitStrategy waitStrategy,
List<FilterStrategy> filterStrategies, List<FilterStrategy> filterStrategies,
RetryContext retryContext) { RetryContext<V> retryContext) {
this.stopStrategy = stopStrategy; this.stopStrategy = stopStrategy;
this.waitStrategy = waitStrategy; this.waitStrategy = waitStrategy;
this.filterStrategies = filterStrategies; this.filterStrategies = filterStrategies;
@ -37,8 +39,6 @@ public class RetryExecutor<V> {
for (FilterStrategy filterStrategy : filterStrategies) { for (FilterStrategy filterStrategy : filterStrategies) {
if (!filterStrategy.filter(retryContext)) { if (!filterStrategy.filter(retryContext)) {
return false; return false;
} }
} }
@ -55,8 +55,13 @@ public class RetryExecutor<V> {
*/ */
public V call(Callable<V> callable) throws Exception { public V call(Callable<V> callable) throws Exception {
// 调用重试 // 这里调用客户端可能会出现网络异常
V call = callable.call(); V call = null;
try {
call = callable.call();
} catch (Exception e) {
log.error("客户端执行失败: [{}]", retryContext.getRetryTask());
}
retryContext.setCallResult(call); retryContext.setCallResult(call);

View File

@ -1,6 +1,6 @@
package com.aizuda.easy.retry.server.support.strategy; package com.aizuda.easy.retry.server.support.strategy;
import com.x.retry.client.model.DispatchRetryResultDTO; import com.aizuda.easy.retry.client.model.DispatchRetryResultDTO;
import com.aizuda.easy.retry.common.core.enums.RetryResultStatusEnum; import com.aizuda.easy.retry.common.core.enums.RetryResultStatusEnum;
import com.aizuda.easy.retry.common.core.enums.StatusEnum; import com.aizuda.easy.retry.common.core.enums.StatusEnum;
import com.aizuda.easy.retry.common.core.model.Result; import com.aizuda.easy.retry.common.core.model.Result;
@ -45,8 +45,13 @@ public class StopStrategies {
(MaxAttemptsPersistenceRetryContext<Result<DispatchRetryResultDTO>>) retryContext; (MaxAttemptsPersistenceRetryContext<Result<DispatchRetryResultDTO>>) retryContext;
Result<DispatchRetryResultDTO> response = context.getCallResult(); Result<DispatchRetryResultDTO> response = context.getCallResult();
if (Objects.isNull(response) || StatusEnum.YES.getStatus() != response.getStatus()) {
return Boolean.FALSE;
}
DispatchRetryResultDTO data = response.getData(); DispatchRetryResultDTO data = response.getData();
if (StatusEnum.YES.getStatus() != response.getStatus() || Objects.isNull(data)) { if (Objects.isNull(data)) {
return Boolean.FALSE; return Boolean.FALSE;
} }

View File

@ -2,7 +2,7 @@ spring:
profiles: profiles:
active: dev active: dev
datasource: datasource:
name: x_retry name: easy_retry
url: jdbc:mysql://localhost:3306/x_retry?useSSL=false&characterEncoding=utf8&useUnicode=true url: jdbc:mysql://localhost:3306/x_retry?useSSL=false&characterEncoding=utf8&useUnicode=true
username: root username: root
password: root password: root
@ -17,11 +17,12 @@ spring:
pool-name: x_retry pool-name: x_retry
max-lifetime: 1800000 max-lifetime: 1800000
connection-test-query: SELECT 1 connection-test-query: SELECT 1
resources: web:
static-locations: classpath:admin/ resources:
static-locations: classpath:admin/
mybatis-plus: mybatis-plus:
mapper-locations: classpath:/mapper/*.xml mapper-locations: classpath:/mapper/*.xml
typeAliasesPackage: com.x.retry.server.persistence.mybatis.po typeAliasesPackage: com.aizuda.easy.retry.server.persistence.mybatis.po
global-config: global-config:
db-config: db-config:
field-strategy: NOT_EMPTY field-strategy: NOT_EMPTY