Merge branch 'dev-shiheng' of https://gitee.com/iotkit-open-source/iotkit-parent into dev-shiheng

V0.5.x
荭琪枫 2023-05-08 20:13:34 +08:00
commit 8a33c66254
15 changed files with 282 additions and 1 deletions

View File

@ -0,0 +1,78 @@
# 消息中心
## 数据库设计
### 通道类型配置
~~~mysql
CREATE TABLE channel_type
(
id bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID',
title varchar(128) NOT NULL COMMENT '标题',
createTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
updateTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间'
) COMMENT '通道类型';
INSERT INTO channel_type(title, createTime, updateTime)
VALUES ('邮箱', current_timestamp(), current_timestamp());
INSERT INTO channel_type(title, createTime, updateTime)
VALUES ('飞书', current_timestamp(), current_timestamp());
INSERT INTO channel_type(title, createTime, updateTime)
VALUES ('短信', current_timestamp(), current_timestamp());
INSERT INTO channel_type(title, createTime, updateTime)
VALUES ('钉钉', current_timestamp(), current_timestamp());
INSERT INTO channel_type(title, createTime, updateTime)
VALUES ('企业微信', current_timestamp(), current_timestamp());
CREATE TABLE channel
(
id bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID',
title varchar(128) COMMENT '标题',
channelType bigint NOT NULL COMMENT '渠道类型',
configParam text NOT NULL COMMENT '配置参数',
userId bigint COMMENT '配置归属',
createTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
updateTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间'
) COMMENT '通道';
CREATE TABLE message
(
id bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID',
mac varchar(128) COMMENT '设备MAC',
deviceId varchar(128) COMMENT '设备ID',
content text NOT NULL COMMENT '消息内容',
createTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
updateTime timestamp DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间'
) COMMENT '消息';
~~~
### 通道类型配置
~~~mysql
CREATE TABLE channel
(
id bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID',
title varchar(128) COMMENT '类型',
configParam text COMMENT '配置参数',
createTime datetime COMMENT '创建时间',
updateTime datetime COMMENT '修改时间'
) COMMENT '渠道';
~~~
### 通道订阅
~~~mysql
CREATE TABLE channel_subscribe
(
id bigint PRIMARY KEY AUTO_INCREMENT COMMENT 'ID',
channelId bigint COMMENT '通道',
userId bigint COMMENT '用户ID',
createTime datetime COMMENT '创建时间',
updateTime datetime COMMENT '修改时间'
) COMMENT '渠道';
~~~

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>iot-message-bus</artifactId>
<groupId>cc.iotkit</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>iot-message-notify</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-model</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-message-core</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,11 @@
### 支持rocketMq作为消息总线
版本0.4.2
rocketMq版本4.9.4
####开启方式:
1、application.yml中打开注释支持rocketMq作为消息总线
2、pom.xml中打开注释使用rocketmq消息总线

View File

@ -0,0 +1,9 @@
package cc.iotkit.message.model;
/**
* author:
* date: 2023-05-08 15:58
* description:
**/
public class DingTalkMessage extends Message{
}

View File

@ -0,0 +1,9 @@
package cc.iotkit.message.model;
/**
* author:
* date: 2023-05-08 15:58
* description:
**/
public class EmailMessage extends Message {
}

View File

@ -0,0 +1,10 @@
package cc.iotkit.message.model;
/**
* author:
* date: 2023-05-08 15:15
* description:
**/
public abstract class Message {
private String content;
}

View File

@ -0,0 +1,9 @@
package cc.iotkit.message.model;
/**
* author:
* date: 2023-05-08 15:58
* description:
**/
public class QyWechatMessage extends Message{
}

View File

@ -0,0 +1,16 @@
package cc.iotkit.message.notify;
import cc.iotkit.message.model.Message;
/**
* author:
* date: 2023-05-08 15:09
* description:
**/
public class DingTalkEventListener implements EventListener{
@Override
public void doEvent(Message message) {
}
}

View File

@ -0,0 +1,12 @@
package cc.iotkit.message.notify;
import cc.iotkit.message.model.Message;
/**
* author:
* date: 2023-05-08 15:08
* description:
**/
public interface EventListener {
void doEvent(Message message);
}

View File

@ -0,0 +1,35 @@
package cc.iotkit.message.notify;
import cc.iotkit.message.model.Message;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* author:
* date: 2023-05-08 15:17
* description:
**/
public class EventManager {
Map<Enum<EventType>, List<EventListener>> listeners = new HashMap<>();
public void subscribe(Enum<EventType> eventType, EventListener listener) {
List<EventListener> users = listeners.get(eventType);
users.add(listener);
}
public void unsubscribe(Enum<EventType> eventType, EventListener listener) {
List<EventListener> users = listeners.get(eventType);
users.remove(listener);
}
public void notify(Enum<EventType> eventType, Message result) {
List<EventListener> users = listeners.get(eventType);
for (EventListener listener : users) {
listener.doEvent(result);
}
}
}

View File

@ -0,0 +1,10 @@
package cc.iotkit.message.notify;
/**
* author:
* date: 2023-05-08 15:21
* description:
**/
public enum EventType {
MQ, Message
}

View File

@ -0,0 +1,16 @@
package cc.iotkit.message.notify;
import cc.iotkit.message.model.Message;
/**
* author:
* date: 2023-05-08 15:09
* description:
**/
public class MessageEventListener implements EventListener{
@Override
public void doEvent(Message message) {
}
}

View File

@ -0,0 +1,16 @@
package cc.iotkit.message.notify;
import cc.iotkit.message.model.Message;
/**
* author:
* date: 2023-05-08 15:09
* description:
**/
public class QyWechatEventListener implements EventListener{
@Override
public void doEvent(Message message) {
}
}

View File

@ -0,0 +1,16 @@
package cc.iotkit.message.service;
import cc.iotkit.message.notify.EventManager;
/**
* author:
* date: 2023-05-08 16:02
* description:
**/
public class MessageService {
public static void main(String[] args) {
EventManager em = new EventManager();
em.notify();
}
}

View File

@ -19,6 +19,7 @@
<module>iot-message-core</module> <module>iot-message-core</module>
<module>iot-vertx-event-bus</module> <module>iot-vertx-event-bus</module>
<module>iot-message-rocketmq</module> <module>iot-message-rocketmq</module>
<module>iot-message-notify</module>
</modules> </modules>
<dependencies> <dependencies>
@ -44,4 +45,4 @@
</dependencies> </dependencies>
</project> </project>