From d6f7589aec67c0bfd7a0c63d29404107ff2f0e19 Mon Sep 17 00:00:00 2001 From: 3y Date: Wed, 23 Mar 2022 21:25:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9C=E9=97=B4=E5=B1=8F=E8=94=BD=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- INSTALL.md | 8 ++++- README.md | 3 +- .../austin/common/enums/AnchorState.java | 2 ++ .../NightShieldLazyPendingHandler.java | 7 ++++- .../shield/impl/ShieldServiceImpl.java | 31 ++++++++++--------- .../java3y/austin/stream/sink/AustinSink.java | 4 ++- .../src/main/resources/application.properties | 2 +- sql/austin.sql | 2 +- 8 files changed, 38 insertions(+), 21 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 08038af..3599e17 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -186,7 +186,7 @@ docker exec -it kafka sh 创建一个topic(这里我的**topicName**就叫austinBusiness,你们可以改成自己的) ``` -$KAFKA_HOME/bin/kafka-topics.sh --create --topic austinBusiness --partitions 4 --zookeeper zookeeper:2181 --replication-factor 1 +$KAFKA_HOME/bin/kafka-topics.sh --create --topic austinBusiness --partitions 1 --zookeeper zookeeper:2181 --replication-factor 1 ``` 查看刚创建的topic信息: @@ -214,6 +214,7 @@ dir /data appendonly yes appendfsync everysec requirepass austin + ``` `docker-compose.yaml`的文件内容如下: @@ -244,6 +245,11 @@ docker-compose up -d docker ps docker exec -it redis redis-cli + +-- 进入到redis后访问的密码 + +auth austin + ``` ## 05、安装APOLLO diff --git a/README.md b/README.md index 19cd5d9..28a2e65 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,8 @@ austin项目**核心流程**:`austin-api`接收到发送消息请求,直接 ## 使用姿势 -目前引用的中间件教程的安装姿势均基于`Centos 7.6`,austin项目**强依赖**`MySQL`/`Redis`/`Kafka`/`apollo`,**弱依赖**`prometheus`/`graylog`/`flink`/`xxl-job`。如果缺少相关的组件可戳:[安装相关组件教程](INSTALL.md)。 +目前引用的中间件教程的安装姿势均基于`Centos 7.6`(**完全部署所有的服务,大概8G内存**),austin项目**强依赖**`MySQL`/`Redis`/`Kafka`/`apollo`,**弱依赖**`prometheus`/`graylog`/`flink`/`xxl-job`。如果缺少相关的组件可戳:[安装相关组件教程](INSTALL.md)。 + **1**、austin使用的MySQL版本**5.7x**。如果目前使用的MySQL版本8.0,注意改变`pom.xml`所依赖的版本 diff --git a/austin-common/src/main/java/com/java3y/austin/common/enums/AnchorState.java b/austin-common/src/main/java/com/java3y/austin/common/enums/AnchorState.java index 0ef1e3e..ca4d27e 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/enums/AnchorState.java +++ b/austin-common/src/main/java/com/java3y/austin/common/enums/AnchorState.java @@ -17,6 +17,8 @@ public enum AnchorState { RECEIVE(10, "消息接收成功"), DISCARD(20, "消费被丢弃"), + NIGHT_SHIELD(22, "夜间屏蔽"), + NIGHT_SHIELD_NEXT_SEND(24, "夜间屏蔽(次日早上9点发送)"), CONTENT_DEDUPLICATION(30, "消息被内容去重"), RULE_DEDUPLICATION(40, "消息被频次去重"), WHITE_LIST(50, "白名单过滤"), diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/handler/NightShieldLazyPendingHandler.java b/austin-cron/src/main/java/com/java3y/austin/cron/handler/NightShieldLazyPendingHandler.java index a52fa81..a65ced1 100644 --- a/austin-cron/src/main/java/com/java3y/austin/cron/handler/NightShieldLazyPendingHandler.java +++ b/austin-cron/src/main/java/com/java3y/austin/cron/handler/NightShieldLazyPendingHandler.java @@ -1,7 +1,10 @@ package com.java3y.austin.cron.handler; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializerFeature; import com.google.common.base.Throwables; +import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.support.config.SupportThreadPoolConfig; import com.java3y.austin.support.utils.KafkaUtils; import com.java3y.austin.support.utils.RedisUtils; @@ -11,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.util.Arrays; + /** * 夜间屏蔽的延迟处理类 @@ -43,7 +48,7 @@ public class NightShieldLazyPendingHandler { String taskInfo = redisUtils.lPop(NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY); if (StrUtil.isNotBlank(taskInfo)) { try { - kafkaUtils.send(topicName, taskInfo); + kafkaUtils.send(topicName, JSON.toJSONString(Arrays.asList(JSON.parseObject(taskInfo, TaskInfo.class)), new SerializerFeature[]{SerializerFeature.WriteClassName})); } catch (Exception e) { log.error("nightShieldLazyJob send kafka fail! e:{},params:{}", Throwables.getStackTraceAsString(e), taskInfo); } diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/shield/impl/ShieldServiceImpl.java b/austin-handler/src/main/java/com/java3y/austin/handler/shield/impl/ShieldServiceImpl.java index 665f945..be5263a 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/shield/impl/ShieldServiceImpl.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/shield/impl/ShieldServiceImpl.java @@ -2,9 +2,13 @@ package com.java3y.austin.handler.shield.impl; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.java3y.austin.common.domain.AnchorInfo; import com.java3y.austin.common.domain.TaskInfo; +import com.java3y.austin.common.enums.AnchorState; import com.java3y.austin.common.enums.ShieldType; import com.java3y.austin.handler.shield.ShieldService; +import com.java3y.austin.support.utils.LogUtils; import com.java3y.austin.support.utils.RedisUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.time.DateFormatUtils; @@ -24,6 +28,8 @@ public class ShieldServiceImpl implements ShieldService { private static final String NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY = "night_shield_send"; @Autowired private RedisUtils redisUtils; + @Autowired + private LogUtils logUtils; @Override public void shield(TaskInfo taskInfo) { @@ -32,32 +38,27 @@ public class ShieldServiceImpl implements ShieldService { * example:当消息下发至austin平台时,已经是凌晨1点,业务希望此类消息在次日的早上9点推送 * (配合 分布式任务定时任务框架搞掂) */ - if (isNight() && isNightShieldType(taskInfo.getShieldType())) { + if (isNight()) { + if (ShieldType.NIGHT_SHIELD.getCode().equals(taskInfo.getShieldType())) { + logUtils.print(AnchorInfo.builder().state(AnchorState.NIGHT_SHIELD.getCode()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build()); + } if (ShieldType.NIGHT_SHIELD_BUT_NEXT_DAY_SEND.getCode().equals(taskInfo.getShieldType())) { - redisUtils.lPush(NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY, JSON.toJSONString(taskInfo), (DateUtil.offsetDay(new Date(), 1).getTime()) / 1000); + redisUtils.lPush(NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY, JSON.toJSONString(taskInfo, new SerializerFeature[]{SerializerFeature.WriteClassName}), + (DateUtil.offsetDay(new Date(), 1).getTime() / 1000) - DateUtil.currentSeconds()); + logUtils.print(AnchorInfo.builder().state(AnchorState.NIGHT_SHIELD_NEXT_SEND.getCode()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build()); } taskInfo.setReceiver(new HashSet<>()); } } - - /** - * 根据code判断是否为夜间屏蔽类型 - */ - private boolean isNightShieldType(Integer code) { - if (ShieldType.NIGHT_SHIELD.getCode().equals(code) - || ShieldType.NIGHT_SHIELD_BUT_NEXT_DAY_SEND.getCode().equals(code)) { - return true; - } - return false; - } - /** * 小时 < 8 默认就认为是凌晨(夜晚) + * * @return */ private boolean isNight() { - return Integer.valueOf(DateFormatUtils.format(new Date(), "HH")) < 8; + return Integer.valueOf(DateFormatUtils.format(new Date(), "HH")) < 8; + } } diff --git a/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java b/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java index cd5bd8e..49c5687 100644 --- a/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java +++ b/austin-stream/src/main/java/com/java3y/austin/stream/sink/AustinSink.java @@ -56,7 +56,9 @@ public class AustinSink implements SinkFunction { */ redisFutures.add(redisAsyncCommands.hincrby(String.valueOf(info.getBusinessId()).getBytes(), String.valueOf(info.getState()).getBytes(), info.getIds().size())); - redisFutures.add(redisAsyncCommands.expire(String.valueOf(info.getBusinessId()).getBytes(), (DateUtil.offsetDay(new Date(), 30).getTime())/ 1000)); + redisFutures.add(redisAsyncCommands.expire(String.valueOf(info.getBusinessId()).getBytes(), + ((DateUtil.offsetDay(new Date(), 30).getTime()) / 1000) - DateUtil.currentSeconds())); + return redisFutures; }); diff --git a/austin-web/src/main/resources/application.properties b/austin-web/src/main/resources/application.properties index 9b5f564..20c1b3c 100644 --- a/austin-web/src/main/resources/application.properties +++ b/austin-web/src/main/resources/application.properties @@ -19,7 +19,7 @@ austin-redis-password= # todo [xxl-job] ip/port【optional】 austin-xxl-job-ip=127.0.0.1 -austin-xxl-job-port=6666 +austin-xxl-job-port=6767 # todo [grayLog] ip【optional】 austin-grayLog-ip=127.0.0.1 diff --git a/sql/austin.sql b/sql/austin.sql index ab18a58..fef403c 100644 --- a/sql/austin.sql +++ b/sql/austin.sql @@ -66,5 +66,5 @@ INSERT INTO austin.message_template (id, name, audit_status, flow_id, msg_status INSERT INTO austin.message_template (id, name, audit_status, flow_id, msg_status, cron_task_id, cron_crowd_path, expect_push_time, id_type, send_channel, template_type, msg_type, msg_content, send_account, creator, updator, auditor, team, proposer, is_deleted, created, updated) VALUES (2, '校招信息', 10, '', 10, null, '', '', 50, 40, 20, 10, '{"content":"你已成功获取到offer","url":"","title":"招聘通知"}', 10, 'Java3y', 'Java3y', '3y', '公众号Java3y', '鸡蛋', 0, 1646274195, 1646274195); -- 实时类型 短信(有占位符)占位符key 为 content -INSERT INTO austin.message_template (id, name, audit_status, flow_id, msg_status, cron_task_id, cron_crowd_path, expect_push_time, id_type, send_channel, template_type, msg_type, msg_content, send_account, creator, updator, auditor, team, proposer, is_deleted, created, updated) VALUES (4, '验证码通知', 10, '', 10, null, '', '', 30, 30, 20, 30, '{"content":"{$content}","url":"","title":""}', 10, 'Java3y', 'Java3y', '3y', '公众号Java3y', '孙悟空', 0, 1646275213, 1646275213); +INSERT INTO austin.message_template (id, name, audit_status, flow_id, msg_status, cron_task_id, cron_crowd_path, expect_push_time, id_type, send_channel, template_type, msg_type, msg_content, send_account, creator, updator, auditor, team, proposer, is_deleted, created, updated) VALUES (3, '验证码通知', 10, '', 10, null, '', '', 30, 30, 20, 30, '{"content":"{$content}","url":"","title":""}', 10, 'Java3y', 'Java3y', '3y', '公众号Java3y', '孙悟空', 0, 1646275213, 1646275213);