pull/4/head
3y 3 years ago
parent e88477ab85
commit c2aa2f19b2

@ -19,4 +19,13 @@ public class AustinConstant {
*/ */
public final static String YYYYMMDD = "yyyyMMdd"; public final static String YYYYMMDD = "yyyyMMdd";
/**
* apollo
*/
public final static String APOLLO_DEFAULT_VALUE_JSON_OBJECT = "{}";
public final static String APOLLO_DEFAULT_VALUE_JSON_ARRAY = "[]";
} }

@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
import com.java3y.austin.domain.TaskInfo; import com.java3y.austin.domain.TaskInfo;
import com.java3y.austin.handler.HandlerHolder; import com.java3y.austin.handler.HandlerHolder;
import com.java3y.austin.service.deduplication.DeduplicationRuleService; import com.java3y.austin.service.deduplication.DeduplicationRuleService;
import com.java3y.austin.service.discard.DiscardMessageService;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -29,16 +30,23 @@ public class Task implements Runnable {
@Autowired @Autowired
private DeduplicationRuleService deduplicationRuleService; private DeduplicationRuleService deduplicationRuleService;
@Autowired
private DiscardMessageService discardMessageService;
private TaskInfo taskInfo; private TaskInfo taskInfo;
@Override @Override
public void run() { public void run() {
// 0. TODO 丢弃消息
// 0. 丢弃消息
if (discardMessageService.isDiscard(taskInfo)) {
return;
}
// 1.平台通用去重 // 1.平台通用去重
deduplicationRuleService.duplication(taskInfo); deduplicationRuleService.duplication(taskInfo);
// 2. 真正发送消息 // 2. 真正发送消息
if (CollUtil.isNotEmpty(taskInfo.getReceiver())) { if (CollUtil.isNotEmpty(taskInfo.getReceiver())) {
handlerHolder.route(taskInfo.getSendChannel()) handlerHolder.route(taskInfo.getSendChannel())

@ -1,6 +1,11 @@
package com.java3y.austin.service.deduplication; package com.java3y.austin.service.deduplication;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import com.java3y.austin.constant.AustinConstant;
import com.java3y.austin.domain.DeduplicationParam; import com.java3y.austin.domain.DeduplicationParam;
import com.java3y.austin.domain.TaskInfo; import com.java3y.austin.domain.TaskInfo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -16,25 +21,42 @@ import java.util.Date;
@Service @Service
public class DeduplicationRuleService { public class DeduplicationRuleService {
/**
* {"contentDeduplication":{"num":1,"time":300},"frequencyDeduplication":{"num":5}}
*/
private static final String DEDUPLICATION_RULE_KEY = "deduplication";
private static final String CONTENT_DEDUPLICATION = "contentDeduplication";
private static final String FREQUENCY_DEDUPLICATION = "frequencyDeduplication";
private static final String TIME = "time";
private static final String NUM = "num";
@Autowired @Autowired
private ContentDeduplicationService contentDeduplicationService; private ContentDeduplicationService contentDeduplicationService;
@Autowired @Autowired
private FrequencyDeduplicationService frequencyDeduplicationService; private FrequencyDeduplicationService frequencyDeduplicationService;
@ApolloConfig("boss.austin")
private Config config;
public void duplication(TaskInfo taskInfo) { public void duplication(TaskInfo taskInfo) {
JSONObject property = JSON.parseObject(config.getProperty(DEDUPLICATION_RULE_KEY, AustinConstant.APOLLO_DEFAULT_VALUE_JSON_OBJECT));
JSONObject contentDeduplication = property.getJSONObject(CONTENT_DEDUPLICATION);
JSONObject frequencyDeduplication = property.getJSONObject(FREQUENCY_DEDUPLICATION);
// 文案去重 // 文案去重
DeduplicationParam contentParams = DeduplicationParam.builder() DeduplicationParam contentParams = DeduplicationParam.builder()
.deduplicationTime(300L).countNum(1).taskInfo(taskInfo) .deduplicationTime(contentDeduplication.getLong(TIME))
.countNum(contentDeduplication.getInteger(NUM)).taskInfo(taskInfo)
.build(); .build();
contentDeduplicationService.deduplication(contentParams); contentDeduplicationService.deduplication(contentParams);
// 运营总规则去重(一天内用户收到最多同一个渠道的消息次数) // 运营总规则去重(一天内用户收到最多同一个渠道的消息次数)
Long seconds = (DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000; Long seconds = (DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000;
DeduplicationParam businessParams = DeduplicationParam.builder() DeduplicationParam businessParams = DeduplicationParam.builder()
.deduplicationTime(seconds).countNum(5).taskInfo(taskInfo) .deduplicationTime(seconds)
.countNum(frequencyDeduplication.getInteger(NUM)).taskInfo(taskInfo)
.build(); .build();
frequencyDeduplicationService.deduplication(businessParams); frequencyDeduplicationService.deduplication(businessParams);
} }

@ -0,0 +1,36 @@
package com.java3y.austin.service.discard;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import com.java3y.austin.constant.AustinConstant;
import com.java3y.austin.domain.TaskInfo;
import org.springframework.stereotype.Service;
/**
*
* @author 3y
*/
@Service
public class DiscardMessageService {
private static final String DISCARD_MESSAGE_KEY = "discard";
@ApolloConfig("boss.austin")
private Config config;
/**
* apollo
* @param taskInfo
* @return
*/
public boolean isDiscard(TaskInfo taskInfo) {
JSONArray array = JSON.parseArray(config.getProperty(DISCARD_MESSAGE_KEY,
AustinConstant.APOLLO_DEFAULT_VALUE_JSON_ARRAY));
if (array.contains(String.valueOf(taskInfo.getMessageTemplateId()))) {
return true;
}
return false;
}
}

@ -63,6 +63,23 @@
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client-config-data</artifactId>
</dependency>
<!--监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -10,6 +10,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class AustinApplication { public class AustinApplication {
public static void main(String[] args) { public static void main(String[] args) {
// TODO apollo的地址
//System.setProperty("apollo.config-service", "http://ip:7000");
SpringApplication.run(AustinApplication.class, args); SpringApplication.run(AustinApplication.class, args);
} }
} }

@ -0,0 +1,18 @@
package com.java3y.austin.controller;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ApolloController {
@ApolloConfig("boss.austin")
private Config config;
@RequestMapping("/apollo")
public String testApollo() {
return config.getProperty("a", "b");
}
}

@ -44,9 +44,36 @@ spring:
port: port:
password: password:
# tomcat / HikariPool(数据库连接池 配置) TODO
# 消息topicName TODO # 消息topicName TODO
austin: austin:
topic: topic:
name: austin name: austin
# 监控配置 TODO
management:
endpoint:
health:
show-details: always
metrics:
enabled: true
prometheus:
enabled: true
endpoints:
web:
exposure:
include: '*'
metrics:
export:
prometheus:
enabled: true
# apollo TODO
app:
id: austin
apollo:
bootstrap:
enabled: true
namespaces: boss.austin
# tomcat / HikariPool(数据库连接池 配置) TODO

@ -74,6 +74,13 @@
<artifactId>tencentcloud-sdk-java</artifactId> <artifactId>tencentcloud-sdk-java</artifactId>
<version>3.1.390</version> <version>3.1.390</version>
</dependency> </dependency>
<!--apollo-->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client-config-data</artifactId>
<version>1.9.1</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

Loading…
Cancel
Save