diff --git a/austin-handler/pom.xml b/austin-handler/pom.xml index f059091..ef643cb 100644 --- a/austin-handler/pom.xml +++ b/austin-handler/pom.xml @@ -24,6 +24,11 @@ 0.0.1-SNAPSHOT + + org.springframework.boot + spring-boot-starter-data-redis + + com.tencentcloudapi tencentcloud-sdk-java diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/EmailHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/EmailHandler.java index fdf55a8..532f58c 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/EmailHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/EmailHandler.java @@ -1,6 +1,7 @@ package com.java3y.austin.handler; import com.java3y.austin.domain.TaskInfo; +import com.java3y.austin.enums.ChannelType; import org.springframework.stereotype.Component; /** @@ -11,6 +12,10 @@ import org.springframework.stereotype.Component; @Component public class EmailHandler extends Handler { + public EmailHandler() { + channelCode = ChannelType.EMAIL.getCode(); + } + @Override public void handler(TaskInfo taskInfoList) { } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/Handler.java b/austin-handler/src/main/java/com/java3y/austin/handler/Handler.java index 7e322b9..d45007e 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/Handler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/Handler.java @@ -1,7 +1,6 @@ package com.java3y.austin.handler; import com.java3y.austin.domain.TaskInfo; -import com.java3y.austin.enums.ChannelType; import org.springframework.beans.factory.annotation.Autowired; import javax.annotation.PostConstruct; @@ -12,6 +11,13 @@ import javax.annotation.PostConstruct; */ public abstract class Handler { + /** + * 标识渠道的Code + * 子类初始化的时候指定 + */ + protected Integer channelCode; + + @Autowired private HandlerHolder handlerHolder; @@ -20,9 +26,7 @@ public abstract class Handler { */ @PostConstruct private void init() { - for (ChannelType channelType : ChannelType.values()) { - handlerHolder.putHandler(channelType.getCode(), this); - } + handlerHolder.putHandler(channelCode, this); } public void doHandler(TaskInfo taskInfo) { diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/SmsHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/SmsHandler.java index 7ddcb3b..8d35524 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/SmsHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/SmsHandler.java @@ -7,6 +7,7 @@ import com.java3y.austin.domain.SmsParam; import com.java3y.austin.domain.SmsRecord; import com.java3y.austin.domain.TaskInfo; import com.java3y.austin.dto.SmsContentModel; +import com.java3y.austin.enums.ChannelType; import com.java3y.austin.script.SmsScript; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -21,6 +22,10 @@ import java.util.List; @Component public class SmsHandler extends Handler { + public SmsHandler() { + channelCode = ChannelType.SMS.getCode(); + } + @Autowired private SmsRecordDao smsRecordDao; diff --git a/austin-handler/src/main/java/com/java3y/austin/pending/Task.java b/austin-handler/src/main/java/com/java3y/austin/pending/Task.java index 42d4e6a..04812c1 100644 --- a/austin-handler/src/main/java/com/java3y/austin/pending/Task.java +++ b/austin-handler/src/main/java/com/java3y/austin/pending/Task.java @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; /** * Task 执行器 + * 0.丢弃消息 * 1.通用去重功能 * 2.发送消息 * @@ -28,10 +29,13 @@ public class Task implements Runnable { @Override public void run() { + // 0. TODO 丢弃消息 + // 1. TODO 通用去重 // 2. 真正发送消息 handlerHolder.route(taskInfo.getSendChannel()) .doHandler(taskInfo); + } } diff --git a/austin-handler/src/main/java/com/java3y/austin/pending/TaskPendingHolder.java b/austin-handler/src/main/java/com/java3y/austin/pending/TaskPendingHolder.java index 31b6b4c..bbd3174 100644 --- a/austin-handler/src/main/java/com/java3y/austin/pending/TaskPendingHolder.java +++ b/austin-handler/src/main/java/com/java3y/austin/pending/TaskPendingHolder.java @@ -17,23 +17,18 @@ import java.util.concurrent.ExecutorService; */ @Component public class TaskPendingHolder { - - private Map taskPendingHolder = new HashMap<>(32); - - /** - * 获取得到所有的groupId - */ - private static List groupIds = GroupIdMappingUtils.getAllGroupIds(); - - /** * 线程池的参数 */ private Integer coreSize = 3; private Integer maxSize = 3; private Integer queueSize = 100; + private Map taskPendingHolder = new HashMap<>(32); - + /** + * 获取得到所有的groupId + */ + private static List groupIds = GroupIdMappingUtils.getAllGroupIds(); /** * 给每个渠道,每种消息类型初始化一个线程池 * @@ -46,7 +41,6 @@ public class TaskPendingHolder { taskPendingHolder.put(groupId, ThreadPoolConfig.getThreadPool(coreSize, maxSize, queueSize)); } } - /** * 得到对应的线程池 * @param groupId diff --git a/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessController.java b/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessController.java index c63d045..b36dacd 100644 --- a/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessController.java +++ b/austin-support/src/main/java/com/java3y/austin/pipeline/ProcessController.java @@ -59,6 +59,7 @@ public class ProcessController { private Boolean preCheck(ProcessContext context) { // 上下文 if (context == null) { + context = new ProcessContext(); context.setResponse(BasicResultVO.fail(RespStatusEnum.CONTEXT_IS_NULL)); return false; } diff --git a/austin-web/src/main/java/com/java3y/austin/controller/RedisController.java b/austin-web/src/main/java/com/java3y/austin/controller/RedisController.java new file mode 100644 index 0000000..4e87038 --- /dev/null +++ b/austin-web/src/main/java/com/java3y/austin/controller/RedisController.java @@ -0,0 +1,25 @@ +package com.java3y.austin.controller; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author 3y + * @date 2021/12/9 + */ +@RestController +@Slf4j +public class RedisController { + + @Autowired + private RedisTemplate redisTemplate; + + + @RequestMapping("/redis") + public void testRedis() { + log.info(redisTemplate.opsForValue().get("1")); + } +} diff --git a/austin-web/src/main/resources/application.yml b/austin-web/src/main/resources/application.yml index f14aeff..f8b24cd 100644 --- a/austin-web/src/main/resources/application.yml +++ b/austin-web/src/main/resources/application.yml @@ -17,7 +17,6 @@ tencent: sms-sdk-app-id: template-id: - # 数据库相关的信息配置 TODO spring: datasource: @@ -27,7 +26,7 @@ spring: driver-class-name: # kafka相关的信息配置 TODO kafka: - bootstrap-servers: 119.91.205.248:9092 + bootstrap-servers: producer: key-serializer: org.apache.kafka.common.serialization.StringSerializer value-serializer: org.apache.kafka.common.serialization.StringSerializer @@ -39,9 +38,14 @@ spring: reset: earliest auto-commit-interval: 1000 enable-auto-commit: true - + # redis 相关配置 TODO + redis: + host: + port: + password: # tomcat / HikariPool(数据库连接池 配置) TODO + # 消息topicName TODO austin: topic: