diff --git a/INSTALL.md b/INSTALL.md index d4e6039..540bc97 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -193,8 +193,10 @@ docker exec -it kafka sh $KAFKA_HOME/bin/kafka-topics.sh --create --topic austinBusiness --partitions 1 --zookeeper zookeeper:2181 --replication-factor 1 +$KAFKA_HOME/bin/kafka-topics.sh --create --topic austinLog --partitions 1 --zookeeper zookeeper:2181 --replication-factor 1 -$KAFKA_HOME/bin/kafka-topics.sh --create --topic austinLog --partitions 1 --zookeeper zookeeper:2181 --replication-factor 1 +$KAFKA_HOME/bin/kafka-topics.sh --create --topic austinRecall --partitions 1 --zookeeper zookeeper:2181 --replication-factor 1 + ``` 查看刚创建的topic信息: @@ -284,8 +286,13 @@ PS:我的namespace是`boss.austin` ![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/4c4636a5620a454b931aea8b248e2890~tplv-k3u1fbpfcp-watermark.image?) +apollo配置样例可看example/apollo.properties文件的内容 + `dynamic-tp-apollo-dtp`它是一个apollo的namespace,存放着动态线程池的配置 +动态线程池样例配置可看 dynamic-tp-apollo-dtp.yml 文件的内容 + + ## 06、安装PROMETHEUS和GRAFANA(可选) 存放`docker-compose.yml`的信息: diff --git a/README.md b/README.md index 5de0918..ed7cdf9 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ austin项目**核心流程**:`austin-api`接收到发送消息请求,直接 ## 使用姿势 -目前引用的中间件教程的安装姿势均基于`Centos 7.6`(**完全部署所有的服务,大概8G内存**),austin项目**强依赖**`MySQL`/`Redis`/`Kafka`/`apollo`,**弱依赖**`prometheus`/`graylog`/`flink`/`xxl-job`。如果缺少相关的组件可戳:[安装相关组件教程](INSTALL.md)。 +目前引用的中间件教程的安装姿势均基于`Centos 7.6`,austin项目**强依赖**`MySQL`/`Redis`/`Kafka`(**大概需要4G内存**),**弱依赖**`prometheus`/`graylog`/`flink`/`xxl-job`/`apollo`(**完全部署所有的服务,大概8G+内存**)。如果缺少相关的组件可戳:[安装相关组件教程](INSTALL.md)。 @@ -78,15 +78,13 @@ austin项目**核心流程**:`austin-api`接收到发送消息请求,直接 **5**、填写`application.properties`中`austin-redis`对应的`ip`/`port`信息 -**6**、检查`apollo`的`app.id`/`apollo.bootstrap.namespaces`,检查创建的消息队列topic:`austin.business.topic.name` +**6**、检查消息队列topic:`austin.business.topic.name`(我的topicName为:austinBusiness) -**7**、以上配置信息都在`application.properties`文件中修改。 +**7**、以上配置信息都在`application.properties`文件中修改。(`prometheus`/`graylog`/`flink`/`xxl-job`/`apollo`可选) -**8**、由于使用了Apollo且我是在云服务器上安装的,我这边会直接跳过`metaserver`服务发现,在`AustinApplication`需要配置对应的apollo地址(注意端口!) +**8**、发送渠道**账号的信息**都配置在**local.properties**,配置的示例参照`com.java3y.austin.support.utils#getAccount`中的注释 -**9**、发送渠道**账号的信息**都配置在**apollo**,配置的示例参照`com.java3y.austin.support.utils#getAccount`中的注释 - -**10**、调用http接口`com.java3y.austin.web.controller#send`给自己发一条短信或者邮件感受 +**10**、调用http接口`com.java3y.austin.web.controller#send`给自己发一条邮件或短信感受(**邮件门槛相对较低,建议配置邮件**) ```shell curl -XPOST "127.0.0.1:8080/send" -H 'Content-Type: application/json' -d '{"code":"send","messageParam":{"extra":null,"receiver":"13719333899"},"messageTemplateId":1}' @@ -110,6 +108,8 @@ curl -XPOST "127.0.0.1:8080/send" -H 'Content-Type: application/json' -d '{"co **14**、正常使用**系统监控**需要部署`promethus`和`grafana`,根据[部署文档](INSTALL.md)配置`grafana`图表 +**15**、正常使用**动态配置中心**需要部署`apollo`,根据[部署文档](INSTALL.md)启动`apollo`,通过docker-compose启动需要在AustinApplication注入对应的ip和port(可看注释) + ## 会员服务 收费课程是以**项目**为主,代码在Gitee和GitHub上都是开源的,项目没有商业版,后面也不会有。那么,付费跟我自己去拉Git仓库拉代码下来看有什么区别? @@ -171,7 +171,7 @@ curl -XPOST "127.0.0.1:8080/send" -H 'Content-Type: application/json' -d '{"co 欢迎扫描下方二维码添加我的**个人微信**备注:【**项目**】,我会空闲的时候拉进项目交流群(群里会解答相关的问题) - + ## 如何准备面试? diff --git a/austin-common/src/main/java/com/java3y/austin/common/dto/model/EnterpriseWeChatContentModel.java b/austin-common/src/main/java/com/java3y/austin/common/dto/model/EnterpriseWeChatContentModel.java index 2ff2209..a78cc86 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/dto/model/EnterpriseWeChatContentModel.java +++ b/austin-common/src/main/java/com/java3y/austin/common/dto/model/EnterpriseWeChatContentModel.java @@ -5,6 +5,8 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import java.util.Map; + /** * @author 3y * 企业微信 应用消息 @@ -21,7 +23,7 @@ public class EnterpriseWeChatContentModel extends ContentModel { private String sendType; /** - * 文本消息 - 文案 + * 文案 */ private String content; @@ -30,9 +32,54 @@ public class EnterpriseWeChatContentModel extends ContentModel { */ private String mediaId; + /** + * 标题 + */ + private String title; + + /** + * 描述 + */ + private String description; + + /** + * 链接 + */ + private String url; + + /** + * 按钮文案 + */ + private String btnTxt; + + /** + * 图文消息 + * [{"title":"中秋节礼品领取","description":"今年中秋节公司有豪礼相送","url":"URL","picurl":"http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png","appid":"wx123123123123123","pagepath":"pages/index?userid=zhangsan&orderid=123123123"}] + */ + private String articles; + + /** + * 图文消息(mpnews) + * [{"title":"Title","thumb_media_id":"MEDIA_ID","author":"Author","content_source_url":"URL","content":"Content","digest":"Digest description"}] + */ + private String mpNewsArticle; + + + /** + * 小程序 + */ + private String appId; + private String page; + private Boolean emphasisFirstItem; + private String contentItems; + + + /** * 其他消息类型: https://developer.work.weixin.qq.com/document/path/90372#%E6%96%87%E6%9C%AC%E6%B6%88%E6%81%AF */ + + } diff --git a/austin-common/src/main/java/com/java3y/austin/common/enums/SendMessageType.java b/austin-common/src/main/java/com/java3y/austin/common/enums/SendMessageType.java index 791bbda..47c939f 100644 --- a/austin-common/src/main/java/com/java3y/austin/common/enums/SendMessageType.java +++ b/austin-common/src/main/java/com/java3y/austin/common/enums/SendMessageType.java @@ -27,6 +27,8 @@ public enum SendMessageType { LINK("110", "链接消息", "link", "link"), ACTION_CARD("120", "跳转卡片消息", "actionCard", "action_card"), OA("130", "OA消息", null, "oa"), + MP_NEWS("140", "图文消息(mpnews)", null, null), + ; private String code; diff --git a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/config/XxlJobConfig.java b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/config/XxlJobConfig.java index 9176ffd..981abf9 100644 --- a/austin-cron/src/main/java/com/java3y/austin/cron/xxl/config/XxlJobConfig.java +++ b/austin-cron/src/main/java/com/java3y/austin/cron/xxl/config/XxlJobConfig.java @@ -3,6 +3,7 @@ package com.java3y.austin.cron.xxl.config; import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -12,6 +13,7 @@ import org.springframework.context.annotation.Configuration; */ @Slf4j @Configuration +@ConditionalOnProperty(name = "xxl-job.enabled",havingValue = "true") public class XxlJobConfig { @Value("${xxl.job.admin.addresses}") diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/DeduplicationRuleService.java b/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/DeduplicationRuleService.java index 24cb518..1fbb90b 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/DeduplicationRuleService.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/deduplication/DeduplicationRuleService.java @@ -1,10 +1,9 @@ package com.java3y.austin.handler.deduplication; -import com.ctrip.framework.apollo.Config; -import com.ctrip.framework.apollo.spring.annotation.ApolloConfig; import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.enums.DeduplicationType; +import com.java3y.austin.support.service.ConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -18,10 +17,10 @@ import java.util.List; @Service public class DeduplicationRuleService { - public static final String DEDUPLICATION_RULE_KEY = "deduplication"; + public static final String DEDUPLICATION_RULE_KEY = "deduplicationRule"; - @ApolloConfig("boss.austin") - private Config config; + @Autowired + private ConfigService config; @Autowired private DeduplicationHolder deduplicationHolder; diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/discard/DiscardMessageService.java b/austin-handler/src/main/java/com/java3y/austin/handler/discard/DiscardMessageService.java index 776afed..49850b2 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/discard/DiscardMessageService.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/discard/DiscardMessageService.java @@ -2,12 +2,11 @@ package com.java3y.austin.handler.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.common.constant.AustinConstant; 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.support.service.ConfigService; import com.java3y.austin.support.utils.LogUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -18,10 +17,10 @@ import org.springframework.stereotype.Service; */ @Service public class DiscardMessageService { - private static final String DISCARD_MESSAGE_KEY = "discard"; + private static final String DISCARD_MESSAGE_KEY = "discardMsgIds"; - @ApolloConfig("boss.austin") - private Config config; + @Autowired + private ConfigService config; @Autowired private LogUtils logUtils; diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/flowcontrol/impl/FlowControlServiceImpl.java b/austin-handler/src/main/java/com/java3y/austin/handler/flowcontrol/impl/FlowControlServiceImpl.java index 5713a2c..7c2e5c9 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/flowcontrol/impl/FlowControlServiceImpl.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/flowcontrol/impl/FlowControlServiceImpl.java @@ -2,8 +2,6 @@ package com.java3y.austin.handler.flowcontrol.impl; 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.google.common.util.concurrent.RateLimiter; import com.java3y.austin.common.constant.AustinConstant; import com.java3y.austin.common.domain.TaskInfo; @@ -11,7 +9,9 @@ import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.handler.enums.RateLimitStrategy; import com.java3y.austin.handler.flowcontrol.FlowControlParam; import com.java3y.austin.handler.flowcontrol.FlowControlService; +import com.java3y.austin.support.service.ConfigService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -22,12 +22,11 @@ import org.springframework.stereotype.Service; @Slf4j public class FlowControlServiceImpl implements FlowControlService { - private static final String FLOW_CONTROL_KEY = "flowControl"; - + private static final String FLOW_CONTROL_KEY = "flowControlRule"; private static final String FLOW_CONTROL_PREFIX = "flow_control_"; - @ApolloConfig("boss.austin") - private Config config; + @Autowired + private ConfigService config; @Override diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java index 71556cd..db2c7cf 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EmailHandler.java @@ -67,7 +67,7 @@ public class EmailHandler extends BaseHandler implements Handler { try { MailSSLSocketFactory sf = new MailSSLSocketFactory(); sf.setTrustAllHosts(true); - account.setAuth(true).setStarttlsEnable(true).setSslEnable(true).setCustomProperty("mail.smtp.ssl.socketFactory", sf); + account.setAuth(account.isAuth()).setStarttlsEnable(account.isStarttlsEnable()).setSslEnable(account.isSslEnable()).setCustomProperty("mail.smtp.ssl.socketFactory", sf); account.setTimeout(25000).setConnectionTimeout(25000); } catch (Exception e) { log.error("EmailHandler#getAccount fail!{}", Throwables.getStackTraceAsString(e)); diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatHandler.java index 395fa2e..15d34e6 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/EnterpriseWeChatHandler.java @@ -8,6 +8,7 @@ import com.java3y.austin.common.constant.SendAccountConstant; import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.dto.model.EnterpriseWeChatContentModel; import com.java3y.austin.common.enums.ChannelType; +import com.java3y.austin.common.enums.SendMessageType; import com.java3y.austin.handler.handler.BaseHandler; import com.java3y.austin.handler.handler.Handler; import com.java3y.austin.support.domain.MessageTemplate; @@ -17,6 +18,8 @@ import me.chanjar.weixin.common.error.WxMpErrorMsgEnum; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.impl.WxCpMessageServiceImpl; import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; +import me.chanjar.weixin.cp.bean.article.MpnewsArticle; +import me.chanjar.weixin.cp.bean.article.NewArticle; import me.chanjar.weixin.cp.bean.message.WxCpMessage; import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult; import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl; @@ -24,6 +27,9 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Map; + /** * @author 3y * 企业微信推送处理 @@ -63,7 +69,6 @@ public class EnterpriseWeChatHandler extends BaseHandler implements Handler { } - /** * 初始化 WxCpServiceImpl 服务接口 * @@ -90,14 +95,42 @@ public class EnterpriseWeChatHandler extends BaseHandler implements Handler { } else { userId = StringUtils.join(taskInfo.getReceiver(), DELIMITER); } - EnterpriseWeChatContentModel enterpriseWeChatContentModel = (EnterpriseWeChatContentModel) taskInfo.getContentModel(); - return WxCpMessage - .TEXT() - .agentId(agentId) - .toUser(userId) - .content(enterpriseWeChatContentModel.getContent()) - .build(); + EnterpriseWeChatContentModel contentModel = (EnterpriseWeChatContentModel) taskInfo.getContentModel(); + + // 通用配置 + WxCpMessage wxCpMessage = null; + + if (SendMessageType.TEXT.getCode().equals(contentModel.getSendType())) { + wxCpMessage = WxCpMessage.TEXT().content(contentModel.getContent()).build(); + } else if (SendMessageType.IMAGE.getCode().equals(contentModel.getSendType())) { + wxCpMessage = WxCpMessage.IMAGE().mediaId(contentModel.getMediaId()).build(); + } else if (SendMessageType.VOICE.getCode().equals(contentModel.getSendType())) { + wxCpMessage = WxCpMessage.VOICE().mediaId(contentModel.getMediaId()).build(); + } else if (SendMessageType.VIDEO.getCode().equals(contentModel.getSendType())) { + wxCpMessage = WxCpMessage.VIDEO().mediaId(contentModel.getMediaId()).description(contentModel.getDescription()).title(contentModel.getTitle()).build(); + } else if (SendMessageType.FILE.getCode().equals(contentModel.getSendType())) { + wxCpMessage = WxCpMessage.FILE().mediaId(contentModel.getMediaId()).build(); + } else if (SendMessageType.TEXT_CARD.getCode().equals(contentModel.getSendType())) { + wxCpMessage = WxCpMessage.TEXTCARD().url(contentModel.getUrl()).title(contentModel.getTitle()).description(contentModel.getDescription()).btnTxt(contentModel.getBtnTxt()).build(); + } else if (SendMessageType.NEWS.getCode().equals(contentModel.getSendType())) { + List newArticles = JSON.parseArray(contentModel.getArticles(), NewArticle.class); + wxCpMessage = WxCpMessage.NEWS().articles(newArticles).build(); + } else if (SendMessageType.MP_NEWS.getCode().equals(contentModel.getSendType())) { + List mpNewsArticles = JSON.parseArray(contentModel.getMpNewsArticle(), MpnewsArticle.class); + wxCpMessage = WxCpMessage.MPNEWS().articles(mpNewsArticles).build(); + } else if (SendMessageType.MARKDOWN.getCode().equals(contentModel.getSendType())) { + wxCpMessage = WxCpMessage.MARKDOWN().content(contentModel.getContent()).build(); + } else if (SendMessageType.MINI_PROGRAM_NOTICE.getCode().equals(contentModel.getSendType())) { + Map contentItems = JSON.parseObject(contentModel.getContentItems(), Map.class); + wxCpMessage = WxCpMessage.newMiniProgramNoticeBuilder().appId(contentModel.getAppId()).page(contentModel.getPage()).emphasisFirstItem(contentModel.getEmphasisFirstItem()).contentItems(contentItems).title(contentModel.getTitle()).description(contentModel.getDescription()).build(); + } else if (SendMessageType.TEMPLATE_CARD.getCode().equals(contentModel.getSendType())) { + // WxJava 未支持 + } + wxCpMessage.setAgentId(agentId); + wxCpMessage.setToUser(userId); + return wxCpMessage; } + @Override public void recall(MessageTemplate messageTemplate) { diff --git a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java index 7e8b336..d8cd98f 100644 --- a/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java +++ b/austin-handler/src/main/java/com/java3y/austin/handler/handler/impl/SmsHandler.java @@ -19,6 +19,7 @@ import com.java3y.austin.handler.script.SmsScriptHolder; import com.java3y.austin.support.dao.SmsRecordDao; import com.java3y.austin.support.domain.MessageTemplate; import com.java3y.austin.support.domain.SmsRecord; +import com.java3y.austin.support.service.ConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -45,8 +46,8 @@ public class SmsHandler extends BaseHandler implements Handler { @Autowired private SmsScriptHolder smsScriptHolder; - @ApolloConfig("boss.austin") - private Config config; + @Autowired + private ConfigService config; @Override @@ -116,7 +117,7 @@ public class SmsHandler extends BaseHandler implements Handler { * 每种类型都会有其下发渠道账号的配置(流量占比也会配置里面) *

* 样例: - * key:msg_type_sms_config + * key:msgTypeSmsConfig * value:[{"message_type_10":[{"weights":80,"scriptName":"TencentSmsScript"},{"weights":20,"scriptName":"YunPianSmsScript"}]},{"message_type_20":[{"weights":20,"scriptName":"YunPianSmsScript"}]},{"message_type_30":[{"weights":20,"scriptName":"TencentSmsScript"}]},{"message_type_40":[{"weights":20,"scriptName":"TencentSmsScript"}]}] * 通知类短信有两个发送渠道 TencentSmsScript 占80%流量,YunPianSmsScript占20%流量 * 营销类短信只有一个发送渠道 YunPianSmsScript @@ -127,7 +128,7 @@ public class SmsHandler extends BaseHandler implements Handler { */ private List getMessageTypeSmsConfig(Integer msgType) { - String apolloKey = "msg_type_sms_config"; + String apolloKey = "msgTypeSmsConfig"; String messagePrefix = "message_type_"; String property = config.getProperty(apolloKey, AustinConstant.APOLLO_DEFAULT_VALUE_JSON_ARRAY); diff --git a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/config/PipelineConfig.java b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/config/PipelineConfig.java index 6dec68c..1c7d4d1 100644 --- a/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/config/PipelineConfig.java +++ b/austin-service-api-impl/src/main/java/com/java3y/austin/service/api/impl/config/PipelineConfig.java @@ -49,7 +49,7 @@ public class PipelineConfig { } /** - * 普通发送执行流程 + * 消息撤回执行流程 * 1.组装参数 * 2.发送MQ * @return @@ -63,9 +63,7 @@ public class PipelineConfig { /** * pipeline流程控制器 - * 目前暂定只有 普通发送的流程 * 后续扩展则加BusinessCode和ProcessTemplate - * * @return */ @Bean diff --git a/austin-support/src/main/java/com/java3y/austin/support/service/ConfigService.java b/austin-support/src/main/java/com/java3y/austin/support/service/ConfigService.java new file mode 100644 index 0000000..29b37f2 --- /dev/null +++ b/austin-support/src/main/java/com/java3y/austin/support/service/ConfigService.java @@ -0,0 +1,21 @@ +package com.java3y.austin.support.service; + + +/** + * 读取配置服务 + * + * @author 3y + */ +public interface ConfigService { + + /** + * 读取配置 + * 1、当启动使用了apollo,优先读取apollo + * 2、当没有启动apollo,读取本地 local.properties 配置文件的内容 + * @param key + * @param defaultValue + * @return + */ + String getProperty(String key, String defaultValue); + +} diff --git a/austin-support/src/main/java/com/java3y/austin/support/service/impl/ConfigServiceImpl.java b/austin-support/src/main/java/com/java3y/austin/support/service/impl/ConfigServiceImpl.java new file mode 100644 index 0000000..f163d72 --- /dev/null +++ b/austin-support/src/main/java/com/java3y/austin/support/service/impl/ConfigServiceImpl.java @@ -0,0 +1,41 @@ +package com.java3y.austin.support.service.impl; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.setting.dialect.Props; +import com.ctrip.framework.apollo.Config; +import com.java3y.austin.support.service.ConfigService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + + +/** + * @author 3y + * 读取配置实现类 + */ +@Service +public class ConfigServiceImpl implements ConfigService { + + /** + * 本地配置 + */ + private static final String PROPERTIES_PATH = "local.properties"; + private Props props = new Props(PROPERTIES_PATH); + + /** + * apollo配置 + */ + @Value("${apollo.bootstrap.enabled}") + private Boolean enableApollo; + @Value("${apollo.bootstrap.namespaces}") + private String namespaces; + + @Override + public String getProperty(String key, String defaultValue) { + if (enableApollo) { + Config config = com.ctrip.framework.apollo.ConfigService.getConfig(namespaces.split(StrUtil.COMMA)[0]); + return config.getProperty(key, defaultValue); + } else { + return props.getProperty(key, defaultValue); + } + } +} diff --git a/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java b/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java index b72b952..922c02b 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java +++ b/austin-support/src/main/java/com/java3y/austin/support/utils/AccountUtils.java @@ -6,6 +6,8 @@ import com.alibaba.fastjson.JSONObject; import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.spring.annotation.ApolloConfig; import com.java3y.austin.common.constant.AustinConstant; +import com.java3y.austin.support.service.ConfigService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -14,15 +16,14 @@ import org.springframework.stereotype.Component; * @author 3y */ @Component - public class AccountUtils { - @ApolloConfig("boss.austin") - private Config config; + @Autowired + private ConfigService config; /** * (key:smsAccount)短信参数示例:[{"sms_10":{"url":"sms.tencentcloudapi.com","region":"ap-guangzhou","secretId":"AKIDhDxxxxxxxx1WljQq","secretKey":"B4hwww39yxxxrrrrgxyi","smsSdkAppId":"1423123125","templateId":"1182097","signName":"Java3y公众号","supplierId":10,"supplierName":"腾讯云"}},{"sms_20":{"url":"https://sms.yunpian.com/v2/sms/tpl_batch_send.json","apikey":"caffff8234234231b5cd7","tpl_id":"523333332","supplierId":20,"supplierName":"云片"}}] - * (key:emailAccount)邮件参数示例:[{"email_10":{"host":"smtp.qq.com","port":465,"user":"4032222131@qq.com","pass":"","from":"4036333131@qq.com"}}] + * (key:emailAccount)邮件参数示例:[{"email_10":{"host":"smtp.qq.com","port":465,"user":"23423423@qq.com","pass":"23423432432423423","from":"234@qq.com","starttlsEnable":true,"auth":true,"sslEnable":true}},{"email_20":{"host":"smtp.163.com","port":465,"user":"22222@163.com","pass":"23432423","from":"234324324234@163.com","starttlsEnable":false,"auth":true,"sslEnable":true}}] * (key:enterpriseWechatAccount)企业微信参数示例:[{"enterprise_wechat_10":{"corpId":"wwf87603333e00069c","corpSecret":"-IFWxS2222QxzPIorNV11144D915DM","agentId":10044442,"token":"rXROB3333Kf6i","aesKey":"MKZtoFxHIM44444M7ieag3r9ZPUsl"}}] * (key:dingDingRobotAccount) 钉钉自定义机器人参数示例:[{"ding_ding_robot_10":{"secret":"SEC9222d4768aded74114faae92229de422222fedf","webhook":"https://oapi.dingtalk.com/robot/send?access_token=8d03b6442222203d87333367328b0c3003d164715d2c6c6e56"}}] * (key:dingDingWorkNoticeAccount) 钉钉工作消息参数示例:[{"ding_ding_work_notice_10":{"appKey":"dingh6yyyyyyycrlbx","appSecret":"tQpvmkR863333yyyyyHP3QHyyyymy9Ao1yoL1oQX5NsdfsWHvWKbTu","agentId":"1523123123183622"}}] diff --git a/austin-web/src/main/java/com/java3y/austin/AustinApplication.java b/austin-web/src/main/java/com/java3y/austin/AustinApplication.java index f562187..2f92a06 100644 --- a/austin-web/src/main/java/com/java3y/austin/AustinApplication.java +++ b/austin-web/src/main/java/com/java3y/austin/AustinApplication.java @@ -10,7 +10,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class AustinApplication { public static void main(String[] args) { - // TODO apollo的ip/port【must】 + + // TODO 如果你需要使用apollo,将application.properties配置文件的 apollo.enabled 改为true System.setProperty("apollo.config-service", "http://austin.apollo.config:5001"); SpringApplication.run(AustinApplication.class, args); } diff --git a/austin-web/src/main/java/com/java3y/austin/web/vo/UploadResponseVo.java b/austin-web/src/main/java/com/java3y/austin/web/vo/UploadResponseVo.java index 459e965..de7c0ef 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/vo/UploadResponseVo.java +++ b/austin-web/src/main/java/com/java3y/austin/web/vo/UploadResponseVo.java @@ -8,6 +8,7 @@ import lombok.NoArgsConstructor; /** * 上传后成功返回素材的Id + * @author 3y */ @Builder @Data diff --git a/austin-web/src/main/resources/application.properties b/austin-web/src/main/resources/application.properties index 9b8f82e..b3cdaa0 100644 --- a/austin-web/src/main/resources/application.properties +++ b/austin-web/src/main/resources/application.properties @@ -17,10 +17,14 @@ austin-redis-ip=austin.redis austin-redis-port=5003 austin-redis-password=austin -# todo [xxl-job] ip/port【optional】 +# todo [xxl-job] switch/ip/port/【optional】 +xxl-job.enabled=false austin-xxl-job-ip=127.0.0.1 austin-xxl-job-port=6767 +# todo [apollo] switch 【optional】 +apollo.enabled=false + # todo [grayLog] ip【optional】 austin-grayLog-ip=austin.graylog @@ -56,7 +60,7 @@ austin.business.recall.topic.name=austinRecall austin.business.recall.group.name=recallGroupId austin.business.log.topic.name=austinLog austin.business.graylog.ip=${austin-grayLog-ip} -# TODO if windows os ,replace path ! +# TODO if windows os and need upload file to send message ,replace path ! austin.business.upload.crowd.path=/Users/3y/temp ##################### xxl properties ##################### @@ -73,7 +77,7 @@ xxl.job.accessToken= ##################### apollo ##################### app.id=austin -apollo.bootstrap.enabled=true +apollo.bootstrap.enabled=${apollo.enabled} apollo.bootstrap.namespaces=boss.austin,dynamic-tp-apollo-dtp.yml ##################### httpUtils properties ##################### diff --git a/example/example.csv b/austin-web/src/main/resources/example.csv similarity index 100% rename from example/example.csv rename to austin-web/src/main/resources/example.csv diff --git a/austin-web/src/main/resources/local.properties b/austin-web/src/main/resources/local.properties new file mode 100644 index 0000000..aa759fa --- /dev/null +++ b/austin-web/src/main/resources/local.properties @@ -0,0 +1,10 @@ +discardMsgIds = [] +deduplicationRule = {"deduplication_10":{"num":1,"time":300},"deduplication_20":{"num":5}} +emailAccount =[{"email_10":{"host":"smtp.qq.com","port":465,"user":"23423423@qq.com","pass":"23423432432423423","from":"234@qq.com","starttlsEnable":true,"auth":true,"sslEnable":true}},{"email_20":{"host":"smtp.163.com","port":465,"user":"22222@163.com","pass":"23432423","from":"234324324234@163.com","starttlsEnable":false,"auth":true,"sslEnable":true}}] +smsAccount = [{"sms_10":{"url":"sms.tencentcloudapi.com","region":"ap-guangzhou","secretId":"234234","secretKey":"234324324","smsSdkAppId":"2343242","templateId":"234234","signName":"Java3y公众号","supplierId":10,"supplierName":"腾讯云"}},{"sms_20":{"url":"https://sms.yunpian.com/v2/sms/tpl_batch_send.json","apikey":"23423432","tpl_id":"23423432","supplierId":20,"supplierName":"云片"}}] +enterpriseWechatAccount = [{"enterprise_wechat_10":{"corpId":"23423423","corpSecret":"-234324234","agentId":1000002,"token":"234234","aesKey":"23423423"}}] +dingDingRobotAccount = [{"ding_ding_robot_10":{"secret":"234324324324","webhook":"https://oapi.dingtalk.com/robot/send?access_token=8d03b68d081f732343243242343247328b0c3003d164715d2c6c6e56"}}] +dingDingWorkNoticeAccount =[{"ding_ding_work_notice_10":{"appKey":"23423423","appSecret":"tQpvmkR863dYcuKDVfM23432432432423Nlx_fYLLLlpPJWHvWKbTu","agentId":"1523423423242"}}] +flowControlRule = {"flow_control_40":1} +geTuiAccount = [{"ge_tui_account_10":{"appId":"23423423","appKey":"234234234","masterSecret":"2342342342342"}}] +msgTypeSmsConfig = [{"message_type_10":[{"weights":99,"scriptName":"TencentSmsScript"},{"weights":1,"scriptName":"YunPianSmsScript"}]},{"message_type_20":[{"weights":20,"scriptName":"YunPianSmsScript"}]},{"message_type_30":[{"weights":20,"scriptName":"TencentSmsScript"}]},{"message_type_40":[{"weights":20,"scriptName":"TencentSmsScript"}]}] diff --git a/docker/redis/redis.conf b/docker/redis/redis.conf index 15a8946..9e2083b 100644 --- a/docker/redis/redis.conf +++ b/docker/redis/redis.conf @@ -1,7 +1,7 @@ protected-mode no port 6379 timeout 0 -save 900 1 # 900s内至少一次写操作则执行bgsave进行RDB持久化 +save 900 1 save 300 10 save 60 10000 rdbcompression yes diff --git a/pom.xml b/pom.xml index 2506f6e..49b1152 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ ${target.java.version} ${target.java.version} 2.17.1 - 4.1.0 + 4.3.0