Skip to content

Commit ee75e84

Browse files
Time-wCharles7c
authored andcommitted
feat(messaging/mqtt): 新增 MQTT 消息模块
1 parent 730b39d commit ee75e84

File tree

24 files changed

+2513
-0
lines changed

24 files changed

+2513
-0
lines changed

continew-starter-bom/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@
190190
<version>${revision}</version>
191191
</dependency>
192192

193+
<!-- 消息模块 - MQTT -->
194+
<dependency>
195+
<groupId>top.continew.starter</groupId>
196+
<artifactId>continew-starter-messaging-mqtt</artifactId>
197+
<version>${revision}</version>
198+
</dependency>
199+
193200
<!-- 消息模块 - WebSocket -->
194201
<dependency>
195202
<groupId>top.continew.starter</groupId>

continew-starter-core/src/main/java/top/continew/starter/core/constant/PropertiesConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ public class PropertiesConstants {
124124
*/
125125
public static final String MESSAGING_WEBSOCKET = MESSAGING + StringConstants.DOT + "websocket";
126126

127+
/**
128+
* MQTT 配置
129+
*/
130+
public static final String MESSAGING_MQTT = MESSAGING + StringConstants.DOT + "mqtt";
131+
127132
/**
128133
* 日志配置
129134
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>top.continew.starter</groupId>
7+
<artifactId>continew-starter-messaging</artifactId>
8+
<version>${revision}</version>
9+
</parent>
10+
11+
12+
<artifactId>continew-starter-messaging-mqtt</artifactId>
13+
<packaging>jar</packaging>
14+
15+
<name>${project.artifactId}</name>
16+
<description>ContiNew Starter 消息模块 - MQTT</description>
17+
18+
<dependencies>
19+
<!--spring MQTT消息模块-->
20+
<dependency>
21+
<groupId>org.springframework.integration</groupId>
22+
<artifactId>spring-integration-mqtt</artifactId>
23+
</dependency>
24+
25+
</dependencies>
26+
27+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
3+
* <p>
4+
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.gnu.org/licenses/lgpl.html
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package top.continew.starter.messaging.mqtt.annotation;
18+
19+
import org.springframework.stereotype.Component;
20+
21+
import java.lang.annotation.*;
22+
23+
/**
24+
* mqtt topic 监听器
25+
*
26+
* @author echo
27+
* @since 2.15.0
28+
*/
29+
@Target({ElementType.TYPE})
30+
@Retention(RetentionPolicy.RUNTIME)
31+
@Documented
32+
@Inherited
33+
@Component
34+
public @interface MqttListener {
35+
36+
/**
37+
* 要监听的 MQTT 主题
38+
* <p>支持以下配置方式:
39+
* <pre>{@code
40+
* 方式1: 直接指定主题
41+
* @MqttListener(topic = "sensor/temperature")
42+
*
43+
* 方式2: 使用配置文件占位符
44+
*
45+
* @MqttListener(topic = "${mqtt.topic}")
46+
*
47+
* 方式3: 使用通配符
48+
* @MqttListener(topic = "sensor/+/temperature") // 单级通配符
49+
* @MqttListener(topic = "sensor/#") // 多级通配符
50+
* }</pre>
51+
*
52+
* <p><b>通配符说明:</b>
53+
* <ul>
54+
* <li>{@code +} - 单级通配符,匹配一个层级的任意内容</li>
55+
* <li>{@code #} - 多级通配符,匹配零个或多个层级,只能用在主题末尾</li>
56+
* </ul>
57+
*
58+
* @return MQTT 主题字符串或配置占位符表达式
59+
*/
60+
String topic();
61+
62+
/**
63+
* QoS - 消息传输可靠性等级
64+
* <p>支持以下配置方式:
65+
* <ul>
66+
* <li>直接指定: {@code qos = "0"}, {@code qos = "1"}, {@code qos = "2"}</li>
67+
* <li>使用占位符: {@code qos = "${mqtt.qos}"}</li>
68+
* </ul>
69+
* <p><b>QoS 等级说明:</b>
70+
* <ul>
71+
* <li>{@code 0} - 最多一次,消息可能丢失</li>
72+
* <li>{@code 1} - 至少一次,消息可能重复</li>
73+
* <li>{@code 2} - 恰好一次,消息不丢失且不重复</li>
74+
* </ul>
75+
*
76+
* @return QoS 等级字符串或配置占位符,默认为 "0"
77+
*/
78+
String qos() default "0";
79+
}

0 commit comments

Comments
 (0)