Skip to content

Commit

Permalink
feat: dinger 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AnswerAIL committed Dec 24, 2020
1 parent 1255652 commit c4e556f
Show file tree
Hide file tree
Showing 132 changed files with 850 additions and 1,310 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<scope>provided</scope>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
Expand Down
145 changes: 8 additions & 137 deletions src/main/java/com/github/jaemon/dinger/DingerSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
*/
package com.github.jaemon.dinger;

import com.github.jaemon.dinger.core.entity.MsgType;
import com.github.jaemon.dinger.core.entity.DingerRequest;
import com.github.jaemon.dinger.core.entity.enums.DingerType;
import com.github.jaemon.dinger.core.entity.enums.MessageSubType;
import com.github.jaemon.dinger.entity.DingerResult;

import java.util.List;
import com.github.jaemon.dinger.core.entity.DingerResponse;

/**
* DingTalk Sender
Expand All @@ -36,16 +34,12 @@ public interface DingerSender {
*
* @param messageSubType
* 消息类型{@link MessageSubType}
* @param keyword
* 关键词(方便定位日志)
* @param title
* 标题(dingtalk-markdown)
* @param content
* 消息内容
* @param request
* 请求体 {@link DingerRequest}
* @return
* 响应报文
* */
DingerResult send(MessageSubType messageSubType, String keyword, String title, String content);
DingerResponse send(MessageSubType messageSubType, DingerRequest request);

/**
* 发送预警消息到钉钉
Expand All @@ -54,134 +48,11 @@ public interface DingerSender {
* Dinger类型 {@link DingerType}
* @param messageSubType
* 消息类型{@link MessageSubType}
* @param keyword
* 关键词(方便定位日志)
* @param title
* 标题(dingtalk-markdown)
* @param content
* 消息内容
* @param request
* 请求体 {@link DingerRequest}
* @return
* 响应报文
* */
DingerResult send(DingerType dingerType, MessageSubType messageSubType, String keyword, String title, String content);

DingerResponse send(DingerType dingerType, MessageSubType messageSubType, DingerRequest request);

/**
* 发送预警消息到钉钉-消息指定艾特人电话信息
*
* @param messageSubType
* 消息类型{@link MessageSubType}
* @param keyword
* 关键词(方便定位日志)
* @param title
* 副标题(dingtalk-markdown)
* @param content
* 消息内容
* @param phones
* 艾特人电话集
* @return
* 响应报文
* */
DingerResult send(MessageSubType messageSubType, String keyword, String title, String content, List<String> phones);

/**
* 发送预警消息到钉钉-消息指定艾特人电话信息
*
* @param dingerType
* Dinger类型 {@link DingerType}
* @param messageSubType
* 消息类型{@link MessageSubType}
* @param keyword
* 关键词(方便定位日志)
* @param title
* 副标题(dingtalk-markdown)
* @param content
* 消息内容
* @param phones
* 艾特人电话集
* @return
* 响应报文
* */
DingerResult send(DingerType dingerType, MessageSubType messageSubType, String keyword, String title, String content, List<String> phones);


/**
* 发送预警消息到钉钉-艾特所有人(仅限{@link MessageSubType#TEXT})
*
* <pre>
* markdown不支持艾特全部
* </pre>
*
* @param keyword
* 关键词(方便定位日志)
* @param title
* 副标题(dingtalk-markdown)
* @param content
* 消息内容
* @return
* 响应报文
* */
DingerResult sendAll(String keyword, String title, String content);

/**
* 发送预警消息到钉钉-艾特所有人(仅限{@link MessageSubType#TEXT})
*
* <pre>
* markdown不支持艾特全部
* </pre>
*
* @param dingerType
* Dinger类型 {@link DingerType}
* @param keyword
* 关键词(方便定位日志)
* @param title
* 副标题(dingtalk-markdown)
* @param content
* 消息内容
* @return
* 响应报文
* */
DingerResult sendAll(DingerType dingerType, String keyword, String title, String content);

/**
* 发送完全自定义消息-对象方式
*
* <blockquote>
* 具体报文体格式参见: <a>https://ding-doc.dingtalk.com/doc#/serverapi3/iydd5h/e9d991e2</a>
* </blockquote>
*
* @param keyword
* 关键词(方便定位日志)
* @param message
* 消息内容
* @param <T>
* T extends {@link MsgType}
* @return
* 响应报文
*/
<T extends MsgType> DingerResult send(String keyword, T message);

/**
* 发送完全自定义消息-json字符串方式
*
* <blockquote>
* 具体报文体格式参见:
* <ul>
* <li>DingTalk: https://ding-doc.dingtalk.com/doc#/serverapi3/iydd5h/e9d991e2</li>
* <li>WeTalk: https://work.weixin.qq.com/api/doc/90000/90136/91770</li>
* </ul>
* </blockquote>
*
* @param keyword
* 关键词(方便定位日志)
* @param dingerType
* 机器人类型 {@link DingerType}
* @param message
* 消息内容
* @param <T>
* 消息类型
* @return
* 响应报文
*/
<T> DingerResult send(String keyword, DingerType dingerType, T message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package com.github.jaemon.dinger.config;

import com.github.jaemon.dinger.sign.DingTalkSignAlgorithm;
import com.github.jaemon.dinger.sign.DingerSignAlgorithm;
import com.dingerframework.support.*;
import com.github.jaemon.dinger.support.sign.DingTalkSignAlgorithm;
import com.github.jaemon.dinger.support.sign.DingerSignAlgorithm;
import com.github.jaemon.dinger.multi.MultiDingerAlgorithmInjectRegister;
import com.github.jaemon.dinger.support.*;
import com.github.jaemon.dinger.support.client.DingerHttpClient;
Expand Down Expand Up @@ -106,17 +105,6 @@ public DingerExceptionCallback dingerExceptionCallback() {
return new DefaultDingerExceptionCallback();
}

/**
* 自定义监控事件
*
* @return notification instance
*/
@Bean
@ConditionalOnMissingBean(MonitorEventNotification.class)
public MonitorEventNotification monitorEventNotification() {
return new DefaultApplicationEventNotification();
}

@Bean
public static MultiDingerAlgorithmInjectRegister multiDingerAlgorithmInjectRegister() {
return new MultiDingerAlgorithmInjectRegister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
*/
package com.github.jaemon.dinger.config;

import com.github.jaemon.dinger.DingerManagerBuilder;
import com.github.jaemon.dinger.DingerRobot;
import com.github.jaemon.dinger.core.DingerManagerBuilder;
import com.github.jaemon.dinger.core.DingerRobot;
import com.github.jaemon.dinger.core.DingerConfigurerAdapter;
import com.github.jaemon.dinger.core.entity.DingerProperties;
import com.github.jaemon.dinger.exception.ConfigurationException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -44,24 +43,24 @@ public class DingerConfiguration {

@Bean
@ConditionalOnMissingBean(DingerConfigurerAdapter.class)
public DingerConfigurerAdapter dingTalkConfigurerAdapter() {
public DingerConfigurerAdapter dingerConfigurerAdapter() {
return new DingerConfigurerAdapter();
}

@Bean
public DingerManagerBuilder dingTalkManagerBuilder() {
public DingerManagerBuilder dingerManagerBuilder() {
return new DingerManagerBuilder();
}


@Bean
public DingerRobot dingerSender(DingerConfigurerAdapter dingTalkConfigurerAdapter, DingerManagerBuilder dingTalkManagerBuilder, ObjectMapper objectMapper){
public DingerRobot dingerSender(DingerConfigurerAdapter dingerConfigurerAdapter, DingerManagerBuilder dingerManagerBuilder){
try {
dingTalkConfigurerAdapter.configure(dingTalkManagerBuilder);
dingerConfigurerAdapter.configure(dingerManagerBuilder);
} catch (Exception ex) {
throw new ConfigurationException(ex);
}
return new DingerRobot(dingerProperties, dingTalkManagerBuilder, objectMapper);
return new DingerRobot(dingerProperties, dingerManagerBuilder);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package com.github.jaemon.dinger.config;

import com.github.jaemon.dinger.DingerRobot;
import com.github.jaemon.dinger.core.DingerRobot;
import com.github.jaemon.dinger.constant.DingerConstant;
import com.github.jaemon.dinger.entity.DkThreadPoolProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand Down Expand Up @@ -45,23 +44,23 @@
@ConditionalOnBean(DingerRobot.class)
//@Conditional(AsyncCondition.class)
@ConditionalOnMissingBean(name = DingerConstant.DINGER_EXECUTOR)
@EnableConfigurationProperties({DkThreadPoolProperties.class})
@EnableConfigurationProperties({DingerThreadPoolProperties.class})
public class DingerThreadPoolConfig {


@Bean(name = DingerConstant.DINGER_EXECUTOR)
public Executor dingTalkExecutor(DkThreadPoolProperties threadPoolProperties) {
public Executor dingTalkExecutor(DingerThreadPoolProperties dingerThreadPoolProperties) {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// 核心线程数
executor.setCorePoolSize(threadPoolProperties.getCoreSize());
executor.setCorePoolSize(dingerThreadPoolProperties.getCoreSize());
// 最大线程数
executor.setMaxPoolSize(threadPoolProperties.getMaxSize());
executor.setMaxPoolSize(dingerThreadPoolProperties.getMaxSize());
// 线程最大空闲时间
executor.setKeepAliveSeconds(threadPoolProperties.getKeepAliveSeconds());
executor.setKeepAliveSeconds(dingerThreadPoolProperties.getKeepAliveSeconds());
// 队列大小
executor.setQueueCapacity(threadPoolProperties.getQueueCapacity());
executor.setQueueCapacity(dingerThreadPoolProperties.getQueueCapacity());
// 指定用于新创建的线程名称的前缀
executor.setThreadNamePrefix(threadPoolProperties.getThreadNamePrefix());
executor.setThreadNamePrefix(dingerThreadPoolProperties.getThreadNamePrefix());

// 使用自定义拒绝策略, 直接抛出异常
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jaemon.dinger.entity;
package com.github.jaemon.dinger.config;

import com.github.jaemon.dinger.constant.DingerConstant;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand All @@ -25,7 +25,7 @@
* @since 1.0
*/
@ConfigurationProperties(prefix = DingerConstant.DINGER_PROPERTIES_PREFIX + "executor-pool")
public class DkThreadPoolProperties {
public class DingerThreadPoolProperties {
private static final int DEFAULT_CORE_SIZE = Runtime.getRuntime().availableProcessors() + 1;
/**
* 线程池维护线程的最小数量
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public interface DingerConstant {
/** 自定义restTemplate名称 */
String DINGER_REST_TEMPLATE = "dingerRestTemplate";

String SUCCESS_KEYWORD = "_SUCCESS";
String FAILED_KEYWORD = "_FAILED";
String EXIT_KEYWORD = "_EXIT";

String NEW_LINE = "\r\n";
String SPOT_SEPERATOR = ".";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
import com.github.jaemon.dinger.core.annatations.DingerScan;
import com.github.jaemon.dinger.core.entity.enums.DingerDefinitionType;
import com.github.jaemon.dinger.core.entity.enums.DingerType;
import com.github.jaemon.dinger.entity.enums.ExceptionEnum;
import com.github.jaemon.dinger.core.entity.enums.ExceptionEnum;
import com.github.jaemon.dinger.exception.DingerException;
import com.github.jaemon.dinger.listeners.ApplicationEventTimeTable;
import com.github.jaemon.dinger.listeners.DingerListenersProperty;
import com.github.jaemon.dinger.utils.PackageUtils;
import com.github.jaemon.dinger.exception.DingerConfigRepeatedException;
import com.github.jaemon.dinger.exception.DingerScanRepeatedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
Expand All @@ -36,12 +33,14 @@
import java.util.List;

import static com.github.jaemon.dinger.core.AbstractDingerDefinitionResolver.Container.INSTANCE;
import static com.github.jaemon.dinger.core.entity.enums.ExceptionEnum.DINGER_REPEATED_EXCEPTION;
import static com.github.jaemon.dinger.core.entity.enums.ExceptionEnum.MULTI_DINGER_SCAN_ERROR;

/**
* AbstractDingerDefinitionResolver
*
* @author Jaemon
* @since 2.0
* @since 1.0
*/
public abstract class AbstractDingerDefinitionResolver
extends DingerListenersProperty {
Expand Down Expand Up @@ -129,7 +128,7 @@ protected List<Class<?>> dingerAnnotationResolver() throws Exception {
DingerScan dingerScan = null;
List<Class<?>> dingerClasses = new ArrayList<>();
// 获取启动类下所有Dinger标注的类信息
for (Class<?> primarySource : ApplicationEventTimeTable.primarySources()) {
for (Class<?> primarySource : DingerListenersProperty.primarySources()) {
if (debugEnabled) {
log.debug("ready to analysis primarySource[{}].", primarySource.getName());
}
Expand All @@ -139,7 +138,7 @@ protected List<Class<?>> dingerAnnotationResolver() throws Exception {
if (dingerScan == null) {
dingerScan = primarySource.getAnnotation(DingerScan.class);
} else {
throw new DingerScanRepeatedException();
throw new DingerException(MULTI_DINGER_SCAN_ERROR);
}
}
}
Expand Down Expand Up @@ -201,7 +200,7 @@ void registerDingerDefinition(
Class<? extends DingerDefinitionGenerator> dingerDefinitionGeneratorClass =
dingerDefinitionGeneratorMap.get(key);
if (dingerDefinitionGeneratorClass == null) {
throw new DingerException(key + "无效.", ExceptionEnum.REGISTER_DINGERDEFINITION_ERROR);
throw new DingerException(ExceptionEnum.DINGERDEFINITIONTYPE_UNDEFINED_KEY, key);
}

DingerDefinitionGenerator dingerDefinitionGenerator = DingerDefinitionGeneratorFactory.get(
Expand All @@ -218,7 +217,7 @@ void registerDingerDefinition(
continue;
}
if (INSTANCE.contains(keyName)) {
throw new DingerConfigRepeatedException("Dinger[" + keyName + "]消息对象重复定义了.");
throw new DingerException(DINGER_REPEATED_EXCEPTION, keyName);
}

// DingerConfig Priority: `@DingerText | @DingerMarkdown | XML` > `@DingerConfiguration` > `***.yml | ***.properties`
Expand Down
Loading

0 comments on commit c4e556f

Please sign in to comment.