diff --git a/iot-common/iot-message-bus/iot-message-notify/messageCenter.md b/iot-common/iot-message-bus/iot-message-notify/messageCenter.md new file mode 100644 index 00000000..3f229d65 --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/messageCenter.md @@ -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 '渠道'; +~~~ \ No newline at end of file diff --git a/iot-common/iot-message-bus/iot-message-notify/pom.xml b/iot-common/iot-message-bus/iot-message-notify/pom.xml new file mode 100644 index 00000000..19603181 --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/pom.xml @@ -0,0 +1,33 @@ + + + + iot-message-bus + cc.iotkit + ${revision} + + 4.0.0 + + iot-message-notify + + + + + org.springframework.boot + spring-boot-autoconfigure + + + + cc.iotkit + iot-model + + + + cc.iotkit + iot-message-core + + + + + \ No newline at end of file diff --git a/iot-common/iot-message-bus/iot-message-notify/readme.md b/iot-common/iot-message-bus/iot-message-notify/readme.md new file mode 100644 index 00000000..8af19e71 --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/readme.md @@ -0,0 +1,11 @@ +### 支持rocketMq作为消息总线 + +版本:0.4.2 + +rocketMq版本:4.9.4 + +####开启方式: + +1、application.yml中打开注释支持rocketMq作为消息总线 + +2、pom.xml中打开注释使用rocketmq消息总线 diff --git a/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java new file mode 100644 index 00000000..2c139438 --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/DingTalkMessage.java @@ -0,0 +1,9 @@ +package cc.iotkit.message.model; + +/** + * author: 石恒 + * date: 2023-05-08 15:58 + * description: + **/ +public class DingTalkMessage extends Message{ +} diff --git a/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailMessage.java b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailMessage.java new file mode 100644 index 00000000..77e99824 --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/EmailMessage.java @@ -0,0 +1,9 @@ +package cc.iotkit.message.model; + +/** + * author: 石恒 + * date: 2023-05-08 15:58 + * description: + **/ +public class EmailMessage extends Message { +} diff --git a/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java new file mode 100644 index 00000000..f352d3da --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/Message.java @@ -0,0 +1,10 @@ +package cc.iotkit.message.model; + +/** + * author: 石恒 + * date: 2023-05-08 15:15 + * description: + **/ +public abstract class Message { + private String content; +} diff --git a/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java new file mode 100644 index 00000000..394e37cb --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/model/QyWechatMessage.java @@ -0,0 +1,9 @@ +package cc.iotkit.message.model; + +/** + * author: 石恒 + * date: 2023-05-08 15:58 + * description: + **/ +public class QyWechatMessage extends Message{ +} diff --git a/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/DingTalkEventListener.java b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/DingTalkEventListener.java new file mode 100644 index 00000000..83fe2f0d --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/DingTalkEventListener.java @@ -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) { + + } +} diff --git a/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventListener.java b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventListener.java new file mode 100644 index 00000000..bd88e859 --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventListener.java @@ -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); +} diff --git a/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventManager.java b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventManager.java new file mode 100644 index 00000000..5071af15 --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventManager.java @@ -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, List> listeners = new HashMap<>(); + + public void subscribe(Enum eventType, EventListener listener) { + List users = listeners.get(eventType); + users.add(listener); + } + + public void unsubscribe(Enum eventType, EventListener listener) { + List users = listeners.get(eventType); + users.remove(listener); + } + + public void notify(Enum eventType, Message result) { + List users = listeners.get(eventType); + for (EventListener listener : users) { + listener.doEvent(result); + } + } + +} diff --git a/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventType.java b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventType.java new file mode 100644 index 00000000..2cdfa823 --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/EventType.java @@ -0,0 +1,10 @@ +package cc.iotkit.message.notify; + +/** + * author: 石恒 + * date: 2023-05-08 15:21 + * description: + **/ +public enum EventType { + MQ, Message +} diff --git a/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/MessageEventListener.java b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/MessageEventListener.java new file mode 100644 index 00000000..3aaaeea9 --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/MessageEventListener.java @@ -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) { + + } +} diff --git a/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/QyWechatEventListener.java b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/QyWechatEventListener.java new file mode 100644 index 00000000..b1cb6294 --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/notify/QyWechatEventListener.java @@ -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) { + + } +} diff --git a/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java new file mode 100644 index 00000000..1334eee1 --- /dev/null +++ b/iot-common/iot-message-bus/iot-message-notify/src/main/java/cc/iotkit/message/service/MessageService.java @@ -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(); + } +} diff --git a/iot-common/iot-message-bus/pom.xml b/iot-common/iot-message-bus/pom.xml index 791b1e84..c7ff60e5 100644 --- a/iot-common/iot-message-bus/pom.xml +++ b/iot-common/iot-message-bus/pom.xml @@ -19,6 +19,7 @@ iot-message-core iot-vertx-event-bus iot-message-rocketmq + iot-message-notify @@ -44,4 +45,4 @@ - \ No newline at end of file +