feat:2.4.0

1. 调整包结构
This commit is contained in:
byteblogs168 2023-09-18 23:30:15 +08:00
parent 3345311d04
commit 2183d16c15
275 changed files with 1526 additions and 761 deletions

View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.aizuda</groupId>
<artifactId>easy-retry-server</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>easy-retry-server-common</artifactId>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor-typed_2.13</artifactId>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor-testkit-typed_2.13</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.aizuda</groupId>
<artifactId>easy-retry-common-core</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
</dependency>
<dependency>
<groupId>com.aizuda</groupId>
<artifactId>easy-retry-common-client-api</artifactId>
</dependency>
<dependency>
<groupId>com.aizuda</groupId>
<artifactId>easy-retry-common-client-api</artifactId>
</dependency>
<dependency>
<groupId>com.aizuda</groupId>
<artifactId>easy-retry-datasource-template</artifactId>
</dependency>
<dependency>
<groupId>org.perf4j</groupId>
<artifactId>perf4j</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>none</mainClass> <!-- 取消查找本项目下的Main方法为了解决Unable to find main class的问题 -->
<classifier>execute</classifier> <!-- 为了解决依赖模块找不到此模块中的类或属性 -->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support;
package com.aizuda.easy.retry.server.common;
import java.util.TreeSet;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support;
package com.aizuda.easy.retry.server.common;
/**
* 组件生命周期

View File

@ -1,7 +1,7 @@
package com.aizuda.easy.retry.server.support;
package com.aizuda.easy.retry.server.common;
import com.aizuda.easy.retry.common.core.enums.NodeTypeEnum;
import com.aizuda.easy.retry.server.support.register.RegisterContext;
import com.aizuda.easy.retry.server.common.register.RegisterContext;
/**
* @author www.byteblogs.com

View File

@ -1,6 +1,6 @@
package com.aizuda.easy.retry.server.service.convert;
package com.aizuda.easy.retry.server.common;
import com.aizuda.easy.retry.server.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.common.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

View File

@ -14,32 +14,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aizuda.easy.retry.server.support;
package com.aizuda.easy.retry.server.common;
import java.util.List;
/**
* Strategy Algorithm for message allocating between consumers
* 服务端负载均衡分配算法
*/
public interface ServerLoadBalance {
public interface ServerLoadBalance<T,D> {
/**
* Allocating by consumer id
* 将waitAllocateList通过算法分配到currentCID中
*
* @param currentCID current consumer id
* @param groupNameList consumer set in current consumer group
* @return The allocate result of given strategy
* @param currentCID 当前节点的id
* @param waitAllocateList 待分配的列表
* @param nodeList 节点信息
* @return 当前节点负责消费的桶数量
*/
List<String> allocate(
final String currentCID,
final List<String> groupNameList,
final List<String> serverList
List<T> allocate(
String currentCID,
List<T> waitAllocateList,
List<D> nodeList
);
/**
* Algorithm name
* 算法名称
*
* @return The strategy name
* @return 策略名称
*/
String getName();
}

View File

@ -1,17 +1,9 @@
package com.aizuda.easy.retry.server.akka;
package com.aizuda.easy.retry.server.common.akka;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import com.aizuda.easy.retry.common.core.context.SpringContext;
import com.aizuda.easy.retry.server.server.RequestHandlerActor;
import com.aizuda.easy.retry.server.support.dispatch.actor.exec.ExecCallbackUnitActor;
import com.aizuda.easy.retry.server.support.dispatch.actor.exec.ExecUnitActor;
import com.aizuda.easy.retry.server.support.dispatch.actor.log.LogActor;
import com.aizuda.easy.retry.server.support.dispatch.actor.result.FailureActor;
import com.aizuda.easy.retry.server.support.dispatch.actor.result.FinishActor;
import com.aizuda.easy.retry.server.support.dispatch.actor.result.NoRetryActor;
import com.aizuda.easy.retry.server.support.dispatch.actor.scan.ScanCallbackGroupActor;
import com.aizuda.easy.retry.server.support.dispatch.actor.scan.ScanGroupActor;
/**
* Actor生成器
@ -21,6 +13,17 @@ import com.aizuda.easy.retry.server.support.dispatch.actor.scan.ScanGroupActor;
*/
public class ActorGenerator {
public static final String SCAN_CALLBACK_GROUP_ACTOR = "ScanCallbackGroupActor";
public static final String SCAN_RETRY_GROUP_ACTOR = "ScanGroupActor";
public static final String FINISH_ACTOR = "FinishActor";
public static final String FAILURE_ACTOR = "FailureActor";
public static final String NO_RETRY_ACTOR = "NoRetryActor";
public static final String EXEC_CALLBACK_UNIT_ACTOR = "ExecCallbackUnitActor";
public static final String EXEC_UNIT_ACTOR = "ExecUnitActor";
public static final String LOG_ACTOR = "LogActor";
public static final String REQUEST_HANDLER_ACTOR = "RequestHandlerActor";
private ActorGenerator() {}
/**
@ -29,7 +32,7 @@ public class ActorGenerator {
* @return actor 引用
*/
public static ActorRef finishActor() {
return getDispatchResultActorSystem().actorOf(getSpringExtension().props(FinishActor.BEAN_NAME));
return getDispatchResultActorSystem().actorOf(getSpringExtension().props(FINISH_ACTOR));
}
/**
@ -38,7 +41,7 @@ public class ActorGenerator {
* @return actor 引用
*/
public static ActorRef failureActor() {
return getDispatchResultActorSystem().actorOf(getSpringExtension().props(FailureActor.BEAN_NAME));
return getDispatchResultActorSystem().actorOf(getSpringExtension().props(FAILURE_ACTOR));
}
/**
@ -47,7 +50,7 @@ public class ActorGenerator {
* @return actor 引用
*/
public static ActorRef noRetryActor() {
return getDispatchResultActorSystem().actorOf(getSpringExtension().props(NoRetryActor.BEAN_NAME));
return getDispatchResultActorSystem().actorOf(getSpringExtension().props(NO_RETRY_ACTOR));
}
/**
@ -56,7 +59,7 @@ public class ActorGenerator {
* @return actor 引用
*/
public static ActorRef execCallbackUnitActor() {
return getDispatchResultActorSystem().actorOf(getSpringExtension().props(ExecCallbackUnitActor.BEAN_NAME));
return getDispatchResultActorSystem().actorOf(getSpringExtension().props(EXEC_CALLBACK_UNIT_ACTOR));
}
/**
@ -65,7 +68,7 @@ public class ActorGenerator {
* @return actor 引用
*/
public static ActorRef execUnitActor() {
return getDispatchExecUnitActorSystem().actorOf(getSpringExtension().props(ExecUnitActor.BEAN_NAME));
return getDispatchExecUnitActorSystem().actorOf(getSpringExtension().props(EXEC_UNIT_ACTOR));
}
/**
@ -74,7 +77,7 @@ public class ActorGenerator {
* @return actor 引用
*/
public static ActorRef scanGroupActor() {
return getDispatchRetryActorSystem().actorOf(getSpringExtension().props(ScanGroupActor.BEAN_NAME));
return getDispatchRetryActorSystem().actorOf(getSpringExtension().props(SCAN_RETRY_GROUP_ACTOR));
}
/**
@ -83,7 +86,7 @@ public class ActorGenerator {
* @return actor 引用
*/
public static ActorRef scanCallbackGroupActor() {
return getDispatchRetryActorSystem().actorOf(getSpringExtension().props(ScanCallbackGroupActor.BEAN_NAME));
return getDispatchRetryActorSystem().actorOf(getSpringExtension().props(SCAN_CALLBACK_GROUP_ACTOR));
}
/**
@ -92,7 +95,7 @@ public class ActorGenerator {
* @return actor 引用
*/
public static ActorRef logActor() {
return getLogActorSystemSystem().actorOf(getSpringExtension().props(LogActor.BEAN_NAME));
return getLogActorSystemSystem().actorOf(getSpringExtension().props(LOG_ACTOR));
}
/**
@ -101,7 +104,7 @@ public class ActorGenerator {
* @return actor 引用
*/
public static ActorRef requestHandlerActor() {
return getNettyActorSystem().actorOf(getSpringExtension().props(RequestHandlerActor.BEAN_NAME));
return getNettyActorSystem().actorOf(getSpringExtension().props(REQUEST_HANDLER_ACTOR));
}
public static SpringExtension getSpringExtension() {

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.akka;
package com.aizuda.easy.retry.server.common.akka;
import akka.actor.ActorSystem;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.akka;
package com.aizuda.easy.retry.server.common.akka;
import akka.actor.Actor;
import akka.actor.IndirectActorProducer;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.akka;
package com.aizuda.easy.retry.server.common.akka;
import akka.actor.Extension;
import akka.actor.Props;

View File

@ -1,9 +1,9 @@
package com.aizuda.easy.retry.server.support.allocate.client;
package com.aizuda.easy.retry.server.common.allocate.client;
import com.aizuda.easy.retry.server.support.allocate.common.ConsistentHashRouter;
import com.aizuda.easy.retry.server.support.allocate.common.Node;
import com.aizuda.easy.retry.server.enums.AllocationAlgorithmEnum;
import com.aizuda.easy.retry.server.support.ClientLoadBalance;
import com.aizuda.easy.retry.server.common.ClientLoadBalance;
import com.aizuda.easy.retry.server.common.enums.AllocationAlgorithmEnum;
import com.aizuda.easy.retry.server.common.allocate.common.ConsistentHashRouter;
import com.aizuda.easy.retry.server.common.allocate.common.Node;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -1,6 +1,6 @@
package com.aizuda.easy.retry.server.support.allocate.client;
package com.aizuda.easy.retry.server.common.allocate.client;
import com.aizuda.easy.retry.server.support.ClientLoadBalance;
import com.aizuda.easy.retry.server.common.ClientLoadBalance;
import java.util.LinkedHashMap;
import java.util.Map;

View File

@ -1,6 +1,6 @@
package com.aizuda.easy.retry.server.support.allocate.client;
package com.aizuda.easy.retry.server.common.allocate.client;
import com.aizuda.easy.retry.server.support.ClientLoadBalance;
import com.aizuda.easy.retry.server.common.ClientLoadBalance;
import lombok.Getter;
import org.springframework.stereotype.Component;

View File

@ -1,7 +1,7 @@
package com.aizuda.easy.retry.server.support.allocate.client;
package com.aizuda.easy.retry.server.common.allocate.client;
import com.aizuda.easy.retry.server.enums.AllocationAlgorithmEnum;
import com.aizuda.easy.retry.server.support.ClientLoadBalance;
import com.aizuda.easy.retry.server.common.ClientLoadBalance;
import com.aizuda.easy.retry.server.common.enums.AllocationAlgorithmEnum;
import org.springframework.stereotype.Component;
import java.util.Random;

View File

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aizuda.easy.retry.server.support.allocate.common;
package com.aizuda.easy.retry.server.common.allocate.common;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

View File

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aizuda.easy.retry.server.support.allocate.common;
package com.aizuda.easy.retry.server.common.allocate.common;
/**
* Hash String to long value

View File

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aizuda.easy.retry.server.support.allocate.common;
package com.aizuda.easy.retry.server.common.allocate.common;
/**
* Represent a node which should be mapped to a hash ring

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support.allocate.common;
package com.aizuda.easy.retry.server.common.allocate.common;
public class VirtualNode<T extends Node> implements Node {
final T physicalNode;

View File

@ -0,0 +1,61 @@
package com.aizuda.easy.retry.server.common.allocate.server;
import com.aizuda.easy.retry.server.common.ServerLoadBalance;
import java.util.ArrayList;
import java.util.List;
/**
* 通过平均算法分配bucketList
*
* @author www.byteblogs.com
* @date 2021-03-01
*/
@SuppressWarnings({"squid:S3358"})
public class AllocateMessageQueueAveragely implements ServerLoadBalance<Integer, String> {
@Override
public List<Integer> allocate(String currentCID, List<Integer> bucketList, List<String> serverList) {
List<Integer> consumerBucket = new ArrayList<>();
// 找到当前消费者在消费者队列里面的下标
int index = serverList.indexOf(currentCID);
// 此处取余是为了判断队列与总消费者数的是否是整数倍 mod=0则是整数倍否则不是
int mod = bucketList.size() % serverList.size();
/**
* 下面三目预算详解为
* 如果队列 <= 总消费者, 这种情况最简单就是平均每个消费者消费一个队列averageSize = 1
* 如果队列 > 总消费者,这里分为 mod是否等于0
* mod=0, 说明是队列与总消费者数是整数倍只需要平均分配就好eg:10/5=2
* mode>0, 说明队列与总消费者数不是整数倍这里肯定有的消费者消费的多eg: 10/8=1余2
* index < mod 这个意思是消费者的下标小于mod的 多消费一个eg: 队列10个 消费者8个 mod=2 ,那么下标0消费2个下标1消费2个其余消费1个
* index >= mod 其余消费者平均消费剩下的队列
*/
int averageSize =
bucketList.size() <= serverList.size() ? 1
: (mod > 0 && index < mod ? bucketList.size() / serverList.size()
+ 1 : bucketList.size() / serverList.size());
// 这里开始计算起始坐标
int startIndex = (mod > 0 && index < mod) ? index * averageSize : index * averageSize + mod;
/**
* 取最小值为消费队列的范围
* 这里需要说明如果队列 < 消费者下标 range是一个小于0的数字所以我们的消费者的数量应该是小于等队列数量否则会造成资源浪费
*/
int range = Math.min(averageSize, bucketList.size() - startIndex);
for (int i = 0; i < range; i++) {
consumerBucket.add(bucketList.get((startIndex + i) % bucketList.size()));
}
return consumerBucket;
}
@Override
public String getName() {
return "AVG";
}
}

View File

@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aizuda.easy.retry.server.support.allocate.server;
package com.aizuda.easy.retry.server.common.allocate.server;
import com.aizuda.easy.retry.server.support.allocate.common.ConsistentHashRouter;
import com.aizuda.easy.retry.server.support.allocate.common.HashFunction;
import com.aizuda.easy.retry.server.support.ServerLoadBalance;
import com.aizuda.easy.retry.server.support.allocate.common.Node;
import com.aizuda.easy.retry.server.common.ServerLoadBalance;
import com.aizuda.easy.retry.server.common.allocate.common.ConsistentHashRouter;
import com.aizuda.easy.retry.server.common.allocate.common.HashFunction;
import com.aizuda.easy.retry.server.common.allocate.common.Node;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
@ -27,9 +27,9 @@ import java.util.Collection;
import java.util.List;
/**
* Consistent Hashing queue algorithm
* 通过一致性hash分配
*/
public class AllocateMessageQueueConsistentHash implements ServerLoadBalance {
public class AllocateMessageQueueConsistentHash implements ServerLoadBalance<String, String> {
private final int virtualNodeCnt;
private final HashFunction customHashFunction;

View File

@ -0,0 +1,74 @@
package com.aizuda.easy.retry.server.common.cache;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.common.Lifecycle;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
/**
* 当前POD负责消费的组
*
* @author www.byteblogs.com
* @date 2021-10-30
* @since 1.6.0
*/
@Component
@Slf4j
public class CacheConsumerBucketGroup implements Lifecycle {
private volatile List<Integer> bucketList = new ArrayList<>();
/**
* 获取所有缓存
*
* @return 缓存对象
*/
public static Set<String> getAllConsumerGroupName() {
ConcurrentMap<String, String> concurrentMap = CACHE.asMap();
return new HashSet<>(concurrentMap.values());
}
/**
* 无缓存时添加
* 有缓存时更新
*
* @return 缓存对象
*/
public static synchronized void addOrUpdate(String groupName) {
LogUtils.info(log, "add consumer cache. groupName:[{}]", groupName);
CACHE.put(groupName, groupName);
}
public static void remove(String groupName) {
LogUtils.info(log, "Remove consumer cache. groupName:[{}]", groupName);
CACHE.invalidate(groupName);
}
public static void clear() {
CACHE.invalidateAll();
}
@Override
public void start() {
LogUtils.info(log, "CacheRegisterTable start");
CACHE = CacheBuilder.newBuilder()
// 设置并发级别为cpu核心数
.concurrencyLevel(Runtime.getRuntime().availableProcessors())
.build();
}
@Override
public void close() {
LogUtils.info(log, "CacheRegisterTable stop");
CACHE.invalidateAll();
}
}

View File

@ -1,7 +1,7 @@
package com.aizuda.easy.retry.server.support.cache;
package com.aizuda.easy.retry.server.common.cache;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.support.Lifecycle;
import com.aizuda.easy.retry.server.common.Lifecycle;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,7 +1,7 @@
package com.aizuda.easy.retry.server.support.cache;
package com.aizuda.easy.retry.server.common.cache;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.support.Lifecycle;
import com.aizuda.easy.retry.server.common.Lifecycle;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import lombok.extern.slf4j.Slf4j;
@ -9,7 +9,6 @@ import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentMap;

View File

@ -1,9 +1,9 @@
package com.aizuda.easy.retry.server.support.cache;
package com.aizuda.easy.retry.server.common.cache;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.service.convert.RegisterNodeInfoConverter;
import com.aizuda.easy.retry.server.support.Lifecycle;
import com.aizuda.easy.retry.server.common.Lifecycle;
import com.aizuda.easy.retry.server.common.RegisterNodeInfoConverter;
import com.aizuda.easy.retry.server.common.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
@ -11,10 +11,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;

View File

@ -1,8 +1,7 @@
package com.aizuda.easy.retry.server.client;
package com.aizuda.easy.retry.server.common.client;
import cn.hutool.core.lang.Assert;
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import java.lang.reflect.Proxy;
import java.util.Objects;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.client;
package com.aizuda.easy.retry.server.common.client;
/**
* 请求类型

View File

@ -1,13 +1,13 @@
package com.aizuda.easy.retry.server.client;
package com.aizuda.easy.retry.server.common.client;
import com.aizuda.easy.retry.client.model.DispatchRetryDTO;
import com.aizuda.easy.retry.client.model.DispatchRetryResultDTO;
import com.aizuda.easy.retry.client.model.RetryCallbackDTO;
import com.aizuda.easy.retry.common.core.model.EasyRetryHeaders;
import com.aizuda.easy.retry.common.core.model.Result;
import com.aizuda.easy.retry.server.client.annotation.Body;
import com.aizuda.easy.retry.server.client.annotation.Header;
import com.aizuda.easy.retry.server.client.annotation.Mapping;
import com.aizuda.easy.retry.server.common.client.annotation.Body;
import com.aizuda.easy.retry.server.common.client.annotation.Header;
import com.aizuda.easy.retry.server.common.client.annotation.Mapping;
/**
* 调用客户端接口

View File

@ -1,24 +1,22 @@
package com.aizuda.easy.retry.server.client;
package com.aizuda.easy.retry.server.common.client;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Tuple;
import cn.hutool.core.util.URLUtil;
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
import com.aizuda.easy.retry.common.core.context.SpringContext;
import com.aizuda.easy.retry.common.core.model.Result;
import com.aizuda.easy.retry.common.core.util.HostUtils;
import com.aizuda.easy.retry.common.core.util.JsonUtil;
import com.aizuda.easy.retry.server.client.annotation.Body;
import com.aizuda.easy.retry.server.client.annotation.Header;
import com.aizuda.easy.retry.server.client.annotation.Mapping;
import com.aizuda.easy.retry.server.client.annotation.Param;
import com.aizuda.easy.retry.server.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.support.cache.CacheRegisterTable;
import com.aizuda.easy.retry.server.support.handler.ClientNodeAllocateHandler;
import com.aizuda.easy.retry.server.common.cache.CacheRegisterTable;
import com.aizuda.easy.retry.server.common.client.annotation.Body;
import com.aizuda.easy.retry.server.common.client.annotation.Header;
import com.aizuda.easy.retry.server.common.client.annotation.Mapping;
import com.aizuda.easy.retry.server.common.client.annotation.Param;
import com.aizuda.easy.retry.server.common.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.common.handler.ClientNodeAllocateHandler;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@ -148,7 +146,6 @@ public class RpcClientInvokeHandler implements InvocationHandler {
return null;
}
@NotNull
private StringBuilder getUrl(Mapping mapping, Map<String, Object> paramMap) {
StringBuilder url = new StringBuilder(MessageFormat.format(URL, hostIp, hostPort.toString(), contextPath));
url.append(mapping.path());
@ -160,7 +157,6 @@ public class RpcClientInvokeHandler implements InvocationHandler {
return url;
}
@NotNull
private ParseParasResult doParseParams(Method method, Object[] args) {
Object body = null;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.client.annotation;
package com.aizuda.easy.retry.server.common.client.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.client.annotation;
package com.aizuda.easy.retry.server.common.client.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@ -1,6 +1,6 @@
package com.aizuda.easy.retry.server.client.annotation;
package com.aizuda.easy.retry.server.common.client.annotation;
import com.aizuda.easy.retry.server.client.RequestMethod;
import com.aizuda.easy.retry.server.common.client.RequestMethod;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.client.annotation;
package com.aizuda.easy.retry.server.common.client.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@ -0,0 +1,16 @@
package com.aizuda.easy.retry.server.common.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* web访问模块
*
* @author: www.byteblogs.com
* @date : 2023-09-19 09:21
*/
@Configuration
@ComponentScan("com.aizuda.easy.retry.server.common.*")
public class EasyRetryServerCommonAutoConfiguration {
}

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.config;
package com.aizuda.easy.retry.server.common.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.aizuda.easy.retry.common.core.util.JsonUtil;
@ -19,4 +19,4 @@ public class JacksonConfig {
return JsonUtil.JsonMapper.jacksonObjectMapper();
}
}
}

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.config;
package com.aizuda.easy.retry.server.common.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.config;
package com.aizuda.easy.retry.server.common.config;
import com.aizuda.easy.retry.template.datasource.enums.DbTypeEnum;
import lombok.Data;
@ -61,6 +61,11 @@ public class SystemProperties {
*/
private int loadBalanceCycleTime = 10;
/**
* 桶的总数量
*/
private int bucketTotal = 128;
/**
* 回调配置
*/

View File

@ -1,8 +1,7 @@
package com.aizuda.easy.retry.server.dto;
package com.aizuda.easy.retry.server.common.dto;
import cn.hutool.core.lang.Assert;
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
import lombok.Getter;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import java.time.Duration;
import java.time.LocalDateTime;

View File

@ -1,11 +1,10 @@
package com.aizuda.easy.retry.server.dto;
package com.aizuda.easy.retry.server.common.dto;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import lombok.Builder;
import lombok.Data;
import io.netty.handler.codec.http.HttpMethod;
/**
* netty客户端请求模型

View File

@ -1,7 +1,6 @@
package com.aizuda.easy.retry.server.dto;
package com.aizuda.easy.retry.server.common.dto;
import lombok.Data;
import org.jetbrains.annotations.NotNull;
import java.time.LocalDateTime;
@ -29,7 +28,7 @@ public class RegisterNodeInfo implements Comparable<RegisterNodeInfo> {
private String contextPath;
@Override
public int compareTo(@NotNull RegisterNodeInfo info) {
public int compareTo(RegisterNodeInfo info) {
return hostId.compareTo(info.hostId);
}
}

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.enums;
package com.aizuda.easy.retry.server.common.enums;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.enums;
package com.aizuda.easy.retry.server.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;

View File

@ -1,6 +1,6 @@
package com.aizuda.easy.retry.server.enums;
package com.aizuda.easy.retry.server.common.enums;
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import lombok.AllArgsConstructor;
import lombok.Getter;

View File

@ -1,7 +1,7 @@
package com.aizuda.easy.retry.server.enums;
package com.aizuda.easy.retry.server.common.enums;
import akka.actor.ActorRef;
import com.aizuda.easy.retry.server.akka.ActorGenerator;
import com.aizuda.easy.retry.server.common.akka.ActorGenerator;
import lombok.AllArgsConstructor;
import lombok.Getter;

View File

@ -1,4 +1,5 @@
package com.aizuda.easy.retry.server.exception;
package com.aizuda.easy.retry.server.common.exception;
import com.aizuda.easy.retry.common.core.exception.BaseEasyRetryException;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support.generator;
package com.aizuda.easy.retry.server.common.generator.id;
/**
* 分布式Id生成器

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support.generator.id;
package com.aizuda.easy.retry.server.common.generator.id;
import java.util.concurrent.atomic.AtomicLong;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support.generator.id;
package com.aizuda.easy.retry.server.common.generator.id;
import lombok.Data;

View File

@ -1,11 +1,10 @@
package com.aizuda.easy.retry.server.support.generator.id;
package com.aizuda.easy.retry.server.common.generator.id;
import com.aizuda.easy.retry.server.enums.IdGeneratorMode;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.common.Lifecycle;
import com.aizuda.easy.retry.server.common.enums.IdGeneratorMode;
import com.aizuda.easy.retry.template.datasource.persistence.mapper.SequenceAllocMapper;
import com.aizuda.easy.retry.template.datasource.persistence.po.SequenceAlloc;
import com.aizuda.easy.retry.server.support.Lifecycle;
import com.aizuda.easy.retry.server.support.generator.IdGenerator;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.perf4j.StopWatch;

View File

@ -1,9 +1,8 @@
package com.aizuda.easy.retry.server.support.generator.id;
package com.aizuda.easy.retry.server.common.generator.id;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.aizuda.easy.retry.server.enums.IdGeneratorMode;
import com.aizuda.easy.retry.server.support.generator.IdGenerator;
import com.aizuda.easy.retry.server.common.enums.IdGeneratorMode;
import org.springframework.stereotype.Component;
/**

View File

@ -1,10 +1,10 @@
package com.aizuda.easy.retry.server.support.handler;
package com.aizuda.easy.retry.server.common.handler;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.support.ClientLoadBalance;
import com.aizuda.easy.retry.server.support.allocate.client.ClientLoadBalanceManager;
import com.aizuda.easy.retry.server.support.cache.CacheRegisterTable;
import com.aizuda.easy.retry.server.common.ClientLoadBalance;
import com.aizuda.easy.retry.server.common.allocate.client.ClientLoadBalanceManager;
import com.aizuda.easy.retry.server.common.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.common.cache.CacheRegisterTable;
import com.aizuda.easy.retry.template.datasource.access.AccessTemplate;
import com.aizuda.easy.retry.template.datasource.persistence.po.GroupConfig;
import lombok.extern.slf4j.Slf4j;

View File

@ -0,0 +1,15 @@
package com.aizuda.easy.retry.server.common.handler;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* www.byteblogs.com
*
* @author: shuguang.zhang
* @date : 2023-09-21 09:26
*/
public class DistributeInstance {
private CopyOnWriteArraySet<Integer> CONSUMER_BUCKET = new CopyOnWriteArraySet<>();
}

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.server.handler;
package com.aizuda.easy.retry.server.common.handler;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.net.url.UrlQuery;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.server.handler;
package com.aizuda.easy.retry.server.common.handler;
import cn.hutool.core.net.url.UrlBuilder;
import io.netty.handler.codec.http.HttpHeaders;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.server.handler;
package com.aizuda.easy.retry.server.common.handler;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.net.url.UrlQuery;

View File

@ -1,20 +1,22 @@
package com.aizuda.easy.retry.server.support.handler;
package com.aizuda.easy.retry.server.common.handler;
import com.aizuda.easy.retry.common.core.enums.NodeTypeEnum;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.config.SystemProperties;
import com.aizuda.easy.retry.server.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.support.Lifecycle;
import com.aizuda.easy.retry.server.support.allocate.server.AllocateMessageQueueConsistentHash;
import com.aizuda.easy.retry.server.support.cache.CacheConsumerGroup;
import com.aizuda.easy.retry.server.support.cache.CacheGroup;
import com.aizuda.easy.retry.server.support.cache.CacheRegisterTable;
import com.aizuda.easy.retry.server.support.register.ServerRegister;
import com.aizuda.easy.retry.server.common.Lifecycle;
import com.aizuda.easy.retry.server.common.allocate.server.AllocateMessageQueueAveragely;
import com.aizuda.easy.retry.server.common.allocate.server.AllocateMessageQueueConsistentHash;
import com.aizuda.easy.retry.server.common.cache.CacheConsumerGroup;
import com.aizuda.easy.retry.server.common.cache.CacheGroup;
import com.aizuda.easy.retry.server.common.config.SystemProperties;
import com.aizuda.easy.retry.server.common.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.common.cache.CacheRegisterTable;
import com.aizuda.easy.retry.server.common.register.ServerRegister;
import com.aizuda.easy.retry.template.datasource.access.AccessTemplate;
import com.aizuda.easy.retry.template.datasource.persistence.mapper.ServerNodeMapper;
import com.aizuda.easy.retry.template.datasource.persistence.po.GroupConfig;
import com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -30,6 +32,7 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* 负责处理组或者节点变化时重新分配组在不同的节点上消费
@ -49,13 +52,15 @@ public class ServerNodeBalance implements Lifecycle, Runnable {
@Autowired
protected AccessTemplate accessTemplate;
private Thread THREAD = null;
private Thread thread = null;
@Autowired
protected ServerNodeMapper serverNodeMapper;
@Autowired
protected SystemProperties systemProperties;
private List<Integer> bucketList;
/**
* 控制rebalance状态
*/
@ -85,8 +90,8 @@ public class ServerNodeBalance implements Lifecycle, Runnable {
return;
}
List<String> allocate = new AllocateMessageQueueConsistentHash()
.allocate(ServerRegister.CURRENT_CID, new ArrayList<>(allGroup), new ArrayList<>(podIpSet));
List<Integer> allocate = new AllocateMessageQueueAveragely()
.allocate(ServerRegister.CURRENT_CID, bucketList, new ArrayList<>(podIpSet));
// 重新覆盖本地分配的组信息
for (String groupName : allocate) {
@ -104,9 +109,16 @@ public class ServerNodeBalance implements Lifecycle, Runnable {
@Override
public void start() {
int bucketTotal = systemProperties.getBucketTotal();
bucketList = new ArrayList<>(bucketTotal);
for (int i = 1; i <= bucketTotal; i++) {
bucketList.add(i);
}
LogUtils.info(log, "ServerNodeBalance start");
THREAD = new Thread(this, "server-node-balance");
THREAD.start();
thread = new Thread(this, "server-node-balance");
thread.start();
}
private void removeNode(ConcurrentMap<String, RegisterNodeInfo> concurrentMap, Set<String> remoteHostIds, Set<String> localHostIds) {
@ -160,7 +172,7 @@ public class ServerNodeBalance implements Lifecycle, Runnable {
public void close() {
// 停止定时任务
THREAD.interrupt();
thread.interrupt();
LogUtils.info(log, "ServerNodeBalance start. ");
int i = serverNodeMapper

View File

@ -1,9 +1,9 @@
package com.aizuda.easy.retry.server.support.register;
package com.aizuda.easy.retry.server.common.register;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.support.Lifecycle;
import com.aizuda.easy.retry.server.support.Register;
import com.aizuda.easy.retry.server.support.cache.CacheRegisterTable;
import com.aizuda.easy.retry.server.common.Lifecycle;
import com.aizuda.easy.retry.server.common.Register;
import com.aizuda.easy.retry.server.common.cache.CacheRegisterTable;
import com.aizuda.easy.retry.template.datasource.persistence.mapper.ServerNodeMapper;
import com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,9 +1,9 @@
package com.aizuda.easy.retry.server.support.register;
package com.aizuda.easy.retry.server.common.register;
import com.aizuda.easy.retry.common.core.enums.NodeTypeEnum;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.support.cache.CacheConsumerGroup;
import com.aizuda.easy.retry.server.support.cache.CacheRegisterTable;
import com.aizuda.easy.retry.server.common.cache.CacheConsumerGroup;
import com.aizuda.easy.retry.server.common.cache.CacheRegisterTable;
import com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support.register;
package com.aizuda.easy.retry.server.common.register;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support.register;
package com.aizuda.easy.retry.server.common.register;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
@ -7,10 +7,10 @@ import com.aizuda.easy.retry.common.core.enums.NodeTypeEnum;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.common.core.util.HostUtils;
import com.aizuda.easy.retry.common.core.util.JsonUtil;
import com.aizuda.easy.retry.server.config.SystemProperties;
import com.aizuda.easy.retry.server.dto.ServerNodeExtAttrs;
import com.aizuda.easy.retry.server.support.Register;
import com.aizuda.easy.retry.server.support.handler.ServerNodeBalance;
import com.aizuda.easy.retry.server.common.Register;
import com.aizuda.easy.retry.server.common.config.SystemProperties;
import com.aizuda.easy.retry.server.common.dto.ServerNodeExtAttrs;
import com.aizuda.easy.retry.server.common.handler.ServerNodeBalance;
import com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.aizuda.easy.retry.server.common.config.EasyRetryServerCommonAutoConfiguration

View File

@ -0,0 +1,18 @@
{
"groups": [
{
"name": "easy-retry",
"type": "com.aizuda.easy.retry.server.common.config.SystemProperties",
"sourceType": "com.aizuda.easy.retry.server.common.config.SystemProperties"
}
],
"properties": [
{
"name": "easy-retry.callback",
"type": "com.aizuda.easy.retry.server.common.config.SystemProperties$Callback",
"defaultValue": "30",
"description": "服务端的地址,若服务端集群部署则此处配置域名",
"sourceType": "com.aizuda.easy.retry.server.common.config.SystemProperties$Callback"
}
]
}

View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.aizuda</groupId>
<artifactId>easy-retry-server</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>easy-retry-server-job-task</artifactId>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>none</mainClass> <!-- 取消查找本项目下的Main方法为了解决Unable to find main class的问题 -->
<classifier>execute</classifier> <!-- 为了解决依赖模块找不到此模块中的类或属性 -->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.aizuda</groupId>
<artifactId>easy-retry-server</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>easy-retry-server-retry-task</artifactId>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.aizuda</groupId>
<artifactId>easy-retry-server-common</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.aizuda</groupId>
<artifactId>easy-retry-common-server-api</artifactId>
</dependency>
<dependency>
<groupId>com.aizuda</groupId>
<artifactId>easy-retry-datasource-template</artifactId>
</dependency>
<dependency>
<groupId>com.aizuda</groupId>
<artifactId>easy-retry-common-client-api</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
</dependency>
<dependency>
<groupId>com.github.rholder</groupId>
<artifactId>guava-retrying</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>none</mainClass> <!-- 取消查找本项目下的Main方法为了解决Unable to find main class的问题 -->
<classifier>execute</classifier> <!-- 为了解决依赖模块找不到此模块中的类或属性 -->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,16 @@
package com.aizuda.easy.retry.server.retry.task.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* web访问模块
*
* @author: www.byteblogs.com
* @date : 2023-09-19 09:21
*/
@Configuration
@ComponentScan("com.aizuda.easy.retry.server.retry.task.*")
public class EasyRetryServerRetryTaskAutoConfiguration {
}

View File

@ -1,22 +1,21 @@
package com.aizuda.easy.retry.server.support.generator.task;
package com.aizuda.easy.retry.server.retry.task.generator.task;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.StrUtil;
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
import com.aizuda.easy.retry.common.core.enums.StatusEnum;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.common.core.util.JsonUtil;
import com.aizuda.easy.retry.server.enums.DelayLevelEnum;
import com.aizuda.easy.retry.server.enums.TaskTypeEnum;
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.service.convert.RetryTaskConverter;
import com.aizuda.easy.retry.server.service.convert.RetryTaskLogConverter;
import com.aizuda.easy.retry.server.support.generator.IdGenerator;
import com.aizuda.easy.retry.server.support.generator.TaskGenerator;
import com.aizuda.easy.retry.server.support.strategy.WaitStrategies;
import com.aizuda.easy.retry.server.common.enums.DelayLevelEnum;
import com.aizuda.easy.retry.server.common.enums.TaskTypeEnum;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.common.generator.id.IdGenerator;
import com.aizuda.easy.retry.server.retry.task.support.RetryTaskConverter;
import com.aizuda.easy.retry.server.retry.task.support.RetryTaskLogConverter;
import com.aizuda.easy.retry.server.retry.task.support.strategy.WaitStrategies;
import com.aizuda.easy.retry.template.datasource.access.AccessTemplate;
import com.aizuda.easy.retry.template.datasource.access.TaskAccess;
import com.aizuda.easy.retry.common.core.enums.StatusEnum;
import com.aizuda.easy.retry.template.datasource.persistence.mapper.RetryTaskLogMapper;
import com.aizuda.easy.retry.template.datasource.persistence.po.GroupConfig;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTask;
@ -25,7 +24,6 @@ import com.aizuda.easy.retry.template.datasource.persistence.po.SceneConfig;
import com.aizuda.easy.retry.template.datasource.utils.RequestDataHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -125,8 +123,8 @@ public abstract class AbstractGenerator implements TaskGenerator {
retryTask.setCreateDt(now);
retryTask.setUpdateDt(now);
if (StringUtils.isBlank(retryTask.getExtAttrs())) {
retryTask.setExtAttrs(StringUtils.EMPTY);
if (StrUtil.isBlank(retryTask.getExtAttrs())) {
retryTask.setExtAttrs(StrUtil.EMPTY);
}
retryTask.setNextTriggerAt(WaitStrategies.randomWait(1, TimeUnit.SECONDS, 60, TimeUnit.SECONDS).computeRetryTime(null));

View File

@ -1,7 +1,7 @@
package com.aizuda.easy.retry.server.support.generator.task;
package com.aizuda.easy.retry.server.retry.task.generator.task;
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
import com.aizuda.easy.retry.server.enums.TaskGeneratorScene;
import com.aizuda.easy.retry.server.common.enums.TaskGeneratorScene;
import org.springframework.stereotype.Component;
/**

View File

@ -1,7 +1,7 @@
package com.aizuda.easy.retry.server.support.generator.task;
package com.aizuda.easy.retry.server.retry.task.generator.task;
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
import com.aizuda.easy.retry.server.enums.TaskGeneratorScene;
import com.aizuda.easy.retry.server.common.enums.TaskGeneratorScene;
import org.springframework.stereotype.Component;
import java.util.Optional;

View File

@ -1,7 +1,7 @@
package com.aizuda.easy.retry.server.support.generator.task;
package com.aizuda.easy.retry.server.retry.task.generator.task;
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
import com.aizuda.easy.retry.server.enums.TaskGeneratorScene;
import com.aizuda.easy.retry.server.common.enums.TaskGeneratorScene;
import org.springframework.stereotype.Component;
import java.util.Optional;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support.generator.task;
package com.aizuda.easy.retry.server.retry.task.generator.task;
import lombok.Data;

View File

@ -1,6 +1,7 @@
package com.aizuda.easy.retry.server.support.generator;
package com.aizuda.easy.retry.server.retry.task.generator.task;
import com.aizuda.easy.retry.server.support.generator.task.TaskContext;
import com.aizuda.easy.retry.server.retry.task.generator.task.TaskContext;
/**
* 任务生成器

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.service.convert;
package com.aizuda.easy.retry.server.retry.task.service;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryDeadLetter;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTask;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.service;
package com.aizuda.easy.retry.server.retry.task.service;
import com.aizuda.easy.retry.server.model.dto.RetryTaskDTO;

View File

@ -0,0 +1,20 @@
package com.aizuda.easy.retry.server.retry.task.service;
import com.aizuda.easy.retry.server.model.dto.RetryTaskDTO;
import com.aizuda.easy.retry.server.retry.task.generator.task.TaskContext;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* @author www.byteblogs.com
* @date 2023-07-16 22:09:40
* @since 2.1.0
*/
@Mapper
public interface TaskContextConverter {
TaskContextConverter INSTANCE = Mappers.getMapper(TaskContextConverter.class);
List<TaskContext.TaskInfo> toTaskContextInfo(List<RetryTaskDTO> retryTasks);
}

View File

@ -1,32 +1,30 @@
package com.aizuda.easy.retry.server.service.impl;
package com.aizuda.easy.retry.server.retry.task.service.impl;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
import com.aizuda.easy.retry.common.core.enums.StatusEnum;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.common.core.util.JsonUtil;
import com.aizuda.easy.retry.server.enums.DelayLevelEnum;
import com.aizuda.easy.retry.server.enums.TaskTypeEnum;
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.common.enums.DelayLevelEnum;
import com.aizuda.easy.retry.server.common.enums.TaskTypeEnum;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.common.generator.id.IdGenerator;
import com.aizuda.easy.retry.server.model.dto.RetryTaskDTO;
import com.aizuda.easy.retry.server.service.RetryService;
import com.aizuda.easy.retry.server.service.convert.RetryDeadLetterConverter;
import com.aizuda.easy.retry.server.service.convert.RetryTaskConverter;
import com.aizuda.easy.retry.server.service.convert.RetryTaskLogConverter;
import com.aizuda.easy.retry.server.support.generator.IdGenerator;
import com.aizuda.easy.retry.server.support.strategy.WaitStrategies;
import com.aizuda.easy.retry.server.support.strategy.WaitStrategies.WaitStrategyEnum;
import com.aizuda.easy.retry.server.retry.task.service.RetryDeadLetterConverter;
import com.aizuda.easy.retry.server.retry.task.service.RetryService;
import com.aizuda.easy.retry.server.retry.task.support.RetryTaskConverter;
import com.aizuda.easy.retry.server.retry.task.support.RetryTaskLogConverter;
import com.aizuda.easy.retry.server.retry.task.support.strategy.WaitStrategies;
import com.aizuda.easy.retry.template.datasource.access.AccessTemplate;
import com.aizuda.easy.retry.template.datasource.access.ConfigAccess;
import com.aizuda.easy.retry.template.datasource.access.TaskAccess;
import com.aizuda.easy.retry.common.core.enums.StatusEnum;
import com.aizuda.easy.retry.template.datasource.persistence.mapper.RetryTaskLogMapper;
import com.aizuda.easy.retry.template.datasource.persistence.po.*;
import com.aizuda.easy.retry.template.datasource.utils.RequestDataHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -100,8 +98,8 @@ public class RetryServiceImpl implements RetryService {
retryTask.setCreateDt(now);
retryTask.setUpdateDt(now);
if (StringUtils.isBlank(retryTask.getExtAttrs())) {
retryTask.setExtAttrs(StringUtils.EMPTY);
if (StrUtil.isBlank(retryTask.getExtAttrs())) {
retryTask.setExtAttrs(StrUtil.EMPTY);
}
retryTask.setNextTriggerAt(
@ -132,7 +130,7 @@ public class RetryServiceImpl implements RetryService {
sceneConfig.setGroupName(retryTaskDTO.getGroupName());
sceneConfig.setSceneName(retryTaskDTO.getSceneName());
sceneConfig.setSceneStatus(StatusEnum.YES.getStatus());
sceneConfig.setBackOff(WaitStrategyEnum.DELAY_LEVEL.getBackOff());
sceneConfig.setBackOff(WaitStrategies.WaitStrategyEnum.DELAY_LEVEL.getBackOff());
sceneConfig.setMaxRetryCount(DelayLevelEnum._21.getLevel());
sceneConfig.setDescription("自动初始化场景");

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support;
package com.aizuda.easy.retry.server.retry.task.support;
import cn.hutool.core.lang.Pair;

View File

@ -1,8 +1,7 @@
package com.aizuda.easy.retry.server.support;
package com.aizuda.easy.retry.server.retry.task.support;
import com.aizuda.easy.retry.server.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.common.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTask;
import com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode;
import java.util.Set;

View File

@ -1,10 +1,9 @@
package com.aizuda.easy.retry.server.service.convert;
package com.aizuda.easy.retry.server.retry.task.support;
import com.aizuda.easy.retry.server.model.dto.RetryTaskDTO;
import com.aizuda.easy.retry.server.retry.task.generator.task.TaskContext;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryDeadLetter;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTask;
import com.aizuda.easy.retry.server.support.generator.task.TaskContext;
import com.aizuda.easy.retry.server.web.model.request.RetryTaskSaveRequestVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
@ -30,7 +29,7 @@ public interface RetryTaskConverter {
})
RetryTask toRetryTask(RetryDeadLetter retryDeadLetter);
RetryTask toRetryTask(RetryTaskSaveRequestVO retryTaskSaveRequestVO);
// RetryTask toRetryTask(RetryTaskSaveRequestVO retryTaskSaveRequestVO);
List<RetryTask> toRetryTaskList(List<RetryTaskDTO> retryTaskDTOList);

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.service.convert;
package com.aizuda.easy.retry.server.retry.task.support;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTask;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTaskLog;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support;
package com.aizuda.easy.retry.server.retry.task.support;
/**
* @author: www.byteblogs.com

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support;
package com.aizuda.easy.retry.server.retry.task.support;
/**
* 重试停止策略

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support;
package com.aizuda.easy.retry.server.retry.task.support;
import java.time.LocalDateTime;

View File

@ -1,10 +1,10 @@
package com.aizuda.easy.retry.server.support.cache;
package com.aizuda.easy.retry.server.retry.task.support.cache;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.common.Lifecycle;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.util.concurrent.RateLimiter;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.support.Lifecycle;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

View File

@ -1,11 +1,11 @@
package com.aizuda.easy.retry.server.support.cache;
package com.aizuda.easy.retry.server.retry.task.support.cache;
import akka.actor.ActorRef;
import com.aizuda.easy.retry.server.enums.TaskTypeEnum;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.common.Lifecycle;
import com.aizuda.easy.retry.server.common.enums.TaskTypeEnum;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.aizuda.easy.retry.server.support.Lifecycle;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

View File

@ -1,7 +1,7 @@
package com.aizuda.easy.retry.server.support.cache;
package com.aizuda.easy.retry.server.retry.task.support.cache;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.support.Lifecycle;
import com.aizuda.easy.retry.server.common.Lifecycle;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,12 +1,10 @@
package com.aizuda.easy.retry.server.support.context;
package com.aizuda.easy.retry.server.retry.task.support.context;
import com.aizuda.easy.retry.server.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.common.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.retry.task.support.RetryContext;
import com.aizuda.easy.retry.server.retry.task.support.WaitStrategy;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTask;
import com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode;
import com.aizuda.easy.retry.server.support.RetryContext;
import com.aizuda.easy.retry.server.support.WaitStrategy;
import lombok.Data;
import lombok.Getter;
import java.util.Objects;
import java.util.Set;

View File

@ -1,10 +1,9 @@
package com.aizuda.easy.retry.server.support.context;
package com.aizuda.easy.retry.server.retry.task.support.context;
import com.aizuda.easy.retry.server.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.common.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.retry.task.support.RetryContext;
import com.aizuda.easy.retry.server.retry.task.support.WaitStrategy;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTask;
import com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode;
import com.aizuda.easy.retry.server.support.RetryContext;
import com.aizuda.easy.retry.server.support.WaitStrategy;
import lombok.Data;
import lombok.Getter;

View File

@ -1,17 +1,17 @@
package com.aizuda.easy.retry.server.support.dispatch;
package com.aizuda.easy.retry.server.retry.task.support.dispatch;
import akka.actor.ActorRef;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.config.SystemProperties;
import com.aizuda.easy.retry.server.enums.TaskTypeEnum;
import com.aizuda.easy.retry.server.common.Lifecycle;
import com.aizuda.easy.retry.server.common.config.SystemProperties;
import com.aizuda.easy.retry.server.common.enums.TaskTypeEnum;
import com.aizuda.easy.retry.server.common.cache.CacheConsumerGroup;
import com.aizuda.easy.retry.server.retry.task.support.cache.CacheGroupRateLimiter;
import com.aizuda.easy.retry.server.retry.task.support.cache.CacheGroupScanActor;
import com.aizuda.easy.retry.server.common.handler.ServerNodeBalance;
import com.aizuda.easy.retry.template.datasource.persistence.mapper.ServerNodeMapper;
import com.aizuda.easy.retry.template.datasource.persistence.po.GroupConfig;
import com.aizuda.easy.retry.template.datasource.persistence.po.ServerNode;
import com.aizuda.easy.retry.server.support.Lifecycle;
import com.aizuda.easy.retry.server.support.cache.CacheConsumerGroup;
import com.aizuda.easy.retry.server.support.cache.CacheGroupRateLimiter;
import com.aizuda.easy.retry.server.support.cache.CacheGroupScanActor;
import com.aizuda.easy.retry.server.support.handler.ServerNodeBalance;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.cache.Cache;
import com.google.common.util.concurrent.RateLimiter;

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support.dispatch;
package com.aizuda.easy.retry.server.retry.task.support.dispatch;
import lombok.Data;

View File

@ -1,29 +1,30 @@
package com.aizuda.easy.retry.server.support.dispatch.actor.exec;
package com.aizuda.easy.retry.server.retry.task.support.dispatch.actor.exec;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.aizuda.easy.retry.client.model.RetryCallbackDTO;
import com.aizuda.easy.retry.server.akka.ActorGenerator;
import com.aizuda.easy.retry.server.client.RequestBuilder;
import com.aizuda.easy.retry.server.client.RpcClient;
import com.aizuda.easy.retry.template.datasource.access.AccessTemplate;
import com.aizuda.easy.retry.template.datasource.access.TaskAccess;
import com.aizuda.easy.retry.server.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.common.core.enums.StatusEnum;
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.util.JsonUtil;
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.common.akka.ActorGenerator;
import com.aizuda.easy.retry.server.common.client.RequestBuilder;
import com.aizuda.easy.retry.server.common.client.RpcClient;
import com.aizuda.easy.retry.server.common.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.retry.task.support.IdempotentStrategy;
import com.aizuda.easy.retry.server.retry.task.support.context.CallbackRetryContext;
import com.aizuda.easy.retry.server.retry.task.support.dispatch.actor.log.RetryTaskLogDTO;
import com.aizuda.easy.retry.server.retry.task.support.handler.CallbackRetryTaskHandler;
import com.aizuda.easy.retry.server.retry.task.support.retry.RetryExecutor;
import com.aizuda.easy.retry.template.datasource.access.AccessTemplate;
import com.aizuda.easy.retry.template.datasource.access.TaskAccess;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTask;
import com.aizuda.easy.retry.server.support.IdempotentStrategy;
import com.aizuda.easy.retry.server.support.context.CallbackRetryContext;
import com.aizuda.easy.retry.server.support.dispatch.actor.log.RetryTaskLogDTO;
import com.aizuda.easy.retry.server.support.handler.CallbackRetryTaskHandler;
import com.aizuda.easy.retry.server.support.retry.RetryExecutor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -40,13 +41,11 @@ import java.util.concurrent.Callable;
* @date 2021-10-30
* @since 1.5.0
*/
@Component(ExecCallbackUnitActor.BEAN_NAME)
@Component(ActorGenerator.EXEC_CALLBACK_UNIT_ACTOR)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Slf4j
public class ExecCallbackUnitActor extends AbstractActor {
public static final String BEAN_NAME = "ExecCallbackUnitActor";
@Autowired
@Qualifier("bitSetIdempotentStrategyHandler")
private IdempotentStrategy<String, Integer> idempotentStrategy;
@ -75,7 +74,7 @@ public class ExecCallbackUnitActor extends AbstractActor {
String message = "回调客户端成功";
if (StatusEnum.YES.getStatus() != result.getStatus()) {
if (StringUtils.isNotBlank(result.getMessage())) {
if (StrUtil.isNotBlank(result.getMessage())) {
message = result.getMessage();
} else {
message = "回调客户端失败: 异常信息为空";
@ -93,7 +92,7 @@ public class ExecCallbackUnitActor extends AbstractActor {
}catch (Exception e) {
LogUtils.error(log, "callback client error. retryTask:[{}]", JsonUtil.toJsonString(retryTask), e);
retryTaskLog.setMessage(StringUtils.isBlank(e.getMessage()) ? StringUtils.EMPTY : e.getMessage());
retryTaskLog.setMessage(StringUtils.isBlank(e.getMessage()) ? StrUtil.EMPTY : e.getMessage());
} finally {
// 清除幂等标识位

View File

@ -1,27 +1,27 @@
package com.aizuda.easy.retry.server.support.dispatch.actor.exec;
package com.aizuda.easy.retry.server.retry.task.support.dispatch.actor.exec;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import cn.hutool.core.util.StrUtil;
import com.aizuda.easy.retry.client.model.DispatchRetryDTO;
import com.aizuda.easy.retry.client.model.DispatchRetryResultDTO;
import com.aizuda.easy.retry.common.core.constant.SystemConstants;
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.log.LogUtils;
import com.aizuda.easy.retry.common.core.model.EasyRetryHeaders;
import com.aizuda.easy.retry.common.core.model.Result;
import com.aizuda.easy.retry.common.core.util.JsonUtil;
import com.aizuda.easy.retry.server.akka.ActorGenerator;
import com.aizuda.easy.retry.server.client.RequestBuilder;
import com.aizuda.easy.retry.server.client.RpcClient;
import com.aizuda.easy.retry.server.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.common.core.enums.StatusEnum;
import com.aizuda.easy.retry.server.common.akka.ActorGenerator;
import com.aizuda.easy.retry.server.common.client.RequestBuilder;
import com.aizuda.easy.retry.server.common.client.RpcClient;
import com.aizuda.easy.retry.server.common.dto.RegisterNodeInfo;
import com.aizuda.easy.retry.server.retry.task.support.IdempotentStrategy;
import com.aizuda.easy.retry.server.retry.task.support.context.MaxAttemptsPersistenceRetryContext;
import com.aizuda.easy.retry.server.retry.task.support.dispatch.actor.log.RetryTaskLogDTO;
import com.aizuda.easy.retry.server.retry.task.support.retry.RetryExecutor;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTask;
import com.aizuda.easy.retry.server.support.IdempotentStrategy;
import com.aizuda.easy.retry.server.support.context.MaxAttemptsPersistenceRetryContext;
import com.aizuda.easy.retry.server.support.dispatch.actor.log.RetryTaskLogDTO;
import com.aizuda.easy.retry.server.support.retry.RetryExecutor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -39,14 +39,11 @@ import java.util.concurrent.Callable;
* @date 2021-10-30
* @since 2.0
*/
@Component("ExecUnitActor")
@Component(ActorGenerator.EXEC_UNIT_ACTOR)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Slf4j
public class ExecUnitActor extends AbstractActor {
public static final String BEAN_NAME = "ExecUnitActor";
public static final String URL = "http://{0}:{1}/{2}/retry/dispatch/v1";
@Autowired
@Qualifier("bitSetIdempotentStrategyHandler")
private IdempotentStrategy<String, Integer> idempotentStrategy;
@ -74,7 +71,7 @@ public class ExecUnitActor extends AbstractActor {
// 回调接口请求成功处理返回值
if (StatusEnum.YES.getStatus() != result.getStatus()) {
if (StringUtils.isNotBlank(result.getMessage())) {
if (StrUtil.isNotBlank(result.getMessage())) {
retryTaskLog.setMessage(result.getMessage());
} else {
retryTaskLog.setMessage("客户端执行失败: 异常信息为空");
@ -84,7 +81,7 @@ public class ExecUnitActor extends AbstractActor {
result.setData(data);
if (Objects.nonNull(data)) {
if (RetryResultStatusEnum.FAILURE.getStatus().equals(data.getStatusCode())) {
if (StringUtils.isNotBlank(data.getExceptionMsg())) {
if (StrUtil.isNotBlank(data.getExceptionMsg())) {
retryTaskLog.setMessage(data.getExceptionMsg());
} else {
retryTaskLog.setMessage("客户端重试失败: 异常信息为空");

View File

@ -1,14 +1,15 @@
package com.aizuda.easy.retry.server.support.dispatch.actor.log;
package com.aizuda.easy.retry.server.retry.task.support.dispatch.actor.log;
import akka.actor.AbstractActor;
import cn.hutool.core.util.StrUtil;
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
import com.aizuda.easy.retry.server.common.akka.ActorGenerator;
import com.aizuda.easy.retry.template.datasource.persistence.mapper.RetryTaskLogMapper;
import com.aizuda.easy.retry.template.datasource.persistence.mapper.RetryTaskLogMessageMapper;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTaskLog;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTaskLogMessage;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
@ -23,13 +24,11 @@ import java.time.LocalDateTime;
* @date : 2023-06-16 11:33
* @since 2.0.0
*/
@Component(LogActor.BEAN_NAME)
@Component(ActorGenerator.LOG_ACTOR)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Slf4j
public class LogActor extends AbstractActor {
public static final String BEAN_NAME = "LogActor";
@Autowired
private RetryTaskLogMessageMapper retryTaskLogMessageMapper;
@Autowired
@ -69,7 +68,7 @@ public class LogActor extends AbstractActor {
retryTaskLogMessage.setGroupName(retryTaskLogDTO.getGroupName());
String errorMessage = retryTaskLogDTO.getMessage();
retryTaskLogMessage.setMessage(
StringUtils.isBlank(errorMessage) ? StringUtils.EMPTY : errorMessage);
StrUtil.isBlank(errorMessage) ? StrUtil.EMPTY : errorMessage);
retryTaskLogMessage.setCreateDt(LocalDateTime.now());
retryTaskLogMessageMapper.insert(retryTaskLogMessage);

View File

@ -1,4 +1,4 @@
package com.aizuda.easy.retry.server.support.dispatch.actor.log;
package com.aizuda.easy.retry.server.retry.task.support.dispatch.actor.log;
import lombok.Data;

View File

@ -1,16 +1,16 @@
package com.aizuda.easy.retry.server.support.dispatch.actor.result;
package com.aizuda.easy.retry.server.retry.task.support.dispatch.actor.result;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import cn.hutool.core.lang.Assert;
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.akka.ActorGenerator;
import com.aizuda.easy.retry.server.config.SystemProperties;
import com.aizuda.easy.retry.server.enums.TaskTypeEnum;
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.support.dispatch.actor.log.RetryTaskLogDTO;
import com.aizuda.easy.retry.server.support.handler.CallbackRetryTaskHandler;
import com.aizuda.easy.retry.server.common.akka.ActorGenerator;
import com.aizuda.easy.retry.server.common.config.SystemProperties;
import com.aizuda.easy.retry.server.common.enums.TaskTypeEnum;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.retry.task.support.dispatch.actor.log.RetryTaskLogDTO;
import com.aizuda.easy.retry.server.retry.task.support.handler.CallbackRetryTaskHandler;
import com.aizuda.easy.retry.template.datasource.access.AccessTemplate;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTask;
import com.aizuda.easy.retry.template.datasource.persistence.po.SceneConfig;
@ -32,13 +32,11 @@ import java.time.LocalDateTime;
* @date 2021-10-30
* @since 2.0
*/
@Component("FailureActor")
@Component(ActorGenerator.FAILURE_ACTOR)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Slf4j
public class FailureActor extends AbstractActor {
public static final String BEAN_NAME = "FailureActor";
@Autowired
private AccessTemplate accessTemplate;
@Autowired

View File

@ -1,14 +1,14 @@
package com.aizuda.easy.retry.server.support.dispatch.actor.result;
package com.aizuda.easy.retry.server.retry.task.support.dispatch.actor.result;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import cn.hutool.core.lang.Assert;
import com.aizuda.easy.retry.common.core.enums.RetryStatusEnum;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.server.akka.ActorGenerator;
import com.aizuda.easy.retry.server.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.support.dispatch.actor.log.RetryTaskLogDTO;
import com.aizuda.easy.retry.server.support.handler.CallbackRetryTaskHandler;
import com.aizuda.easy.retry.server.common.akka.ActorGenerator;
import com.aizuda.easy.retry.server.common.exception.EasyRetryServerException;
import com.aizuda.easy.retry.server.retry.task.support.dispatch.actor.log.RetryTaskLogDTO;
import com.aizuda.easy.retry.server.retry.task.support.handler.CallbackRetryTaskHandler;
import com.aizuda.easy.retry.template.datasource.access.AccessTemplate;
import com.aizuda.easy.retry.template.datasource.persistence.po.RetryTask;
import lombok.extern.slf4j.Slf4j;
@ -31,7 +31,7 @@ import java.time.LocalDateTime;
* @date 2021-10-30
* @since 2.0
*/
@Component("FinishActor")
@Component(ActorGenerator.FINISH_ACTOR)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Slf4j
public class FinishActor extends AbstractActor {

Some files were not shown because too many files have changed in this diff Show More