夜间屏蔽 功能 完成

pull/6/head
3y 3 years ago
parent 43bb7f8368
commit d6f7589aec

@ -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

@ -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`所依赖的版本

@ -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, "白名单过滤"),

@ -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);
}

@ -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:austin19
* ( )
*/
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;
}
}

@ -56,7 +56,9 @@ public class AustinSink implements SinkFunction<AnchorInfo> {
*/
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;
});

@ -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

@ -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);

Loading…
Cancel
Save