Skip to content

Commit

Permalink
夜间屏蔽 功能 完成
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongFuCheng3y committed Mar 23, 2022
1 parent 43bb7f8 commit d6f7589
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
8 changes: 7 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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信息:
Expand Down Expand Up @@ -214,6 +214,7 @@ dir /data
appendonly yes
appendfsync everysec
requirepass austin
```

`docker-compose.yaml`的文件内容如下:
Expand Down Expand Up @@ -244,6 +245,11 @@ docker-compose up -d
docker ps
docker exec -it redis redis-cli
-- 进入到redis后访问的密码
auth austin
```

## 05、安装APOLLO
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`所依赖的版本

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "白名单过滤"),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +14,8 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Arrays;


/**
* 夜间屏蔽的延迟处理类
Expand Down Expand Up @@ -43,7 +48,7 @@ public void execute() {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

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;
Expand All @@ -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) {
Expand All @@ -32,32 +38,27 @@ public void shield(TaskInfo taskInfo) {
* 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;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ private void realTimeData(AnchorInfo info) {
*/
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;
});

Expand Down
2 changes: 1 addition & 1 deletion austin-web/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sql/austin.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit d6f7589

Please sign in to comment.