From b2e24428bae9dd172f21372554960451abf4826e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= <1101766085@qq.com> Date: Thu, 26 Aug 2021 18:54:14 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E8=80=83=E8=99=91=E5=86=85?= =?UTF-8?q?=E7=BD=AE=20http=20api=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/mqtt/http/MqttWebServerConfig.java | 86 +++++++++++++++++++ .../iot/mqtt/http/MqttWebServerStater.java | 30 +++++++ .../client/MqttClientConfiguration.java | 16 ++-- 3 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/http/MqttWebServerConfig.java create mode 100644 mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/http/MqttWebServerStater.java diff --git a/mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/http/MqttWebServerConfig.java b/mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/http/MqttWebServerConfig.java new file mode 100644 index 0000000..009e64d --- /dev/null +++ b/mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/http/MqttWebServerConfig.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & dreamlu.net). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.dreamlu.iot.mqtt.http; + +/** + * mqtt http、websocket 启动配置 + * + * @author L.cm + */ +public class MqttWebServerConfig { + + /** + * http、websocket 端口,默认:8083 + */ + private int port = 8083; + /** + * 开启 websocket 服务,默认:true + */ + private boolean websocketEnable = true; + /** + * 开启 http 服务,默认:true + */ + private boolean httpEnable = true; + /** + * Basic 认证账号 + */ + private String username; + /** + * Basic 认证密码 + */ + private String password; + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public boolean isWebsocketEnable() { + return websocketEnable; + } + + public void setWebsocketEnable(boolean websocketEnable) { + this.websocketEnable = websocketEnable; + } + + public boolean isHttpEnable() { + return httpEnable; + } + + public void setHttpEnable(boolean httpEnable) { + this.httpEnable = httpEnable; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/http/MqttWebServerStater.java b/mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/http/MqttWebServerStater.java new file mode 100644 index 0000000..86b7b8f --- /dev/null +++ b/mica-mqtt-example/src/main/java/net/dreamlu/iot/mqtt/http/MqttWebServerStater.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & dreamlu.net). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.dreamlu.iot.mqtt.http; + +/** + * mqtt http、websocket 启动器 + * + * @author L.cm + */ +public class MqttWebServerStater { + + public static void star() { + + } + +} diff --git a/mica-mqtt-spring-boot-starter/src/main/java/net/dreamlu/iot/mqtt/spring/client/MqttClientConfiguration.java b/mica-mqtt-spring-boot-starter/src/main/java/net/dreamlu/iot/mqtt/spring/client/MqttClientConfiguration.java index 90ad4d4..50f7a26 100644 --- a/mica-mqtt-spring-boot-starter/src/main/java/net/dreamlu/iot/mqtt/spring/client/MqttClientConfiguration.java +++ b/mica-mqtt-spring-boot-starter/src/main/java/net/dreamlu/iot/mqtt/spring/client/MqttClientConfiguration.java @@ -73,14 +73,14 @@ public class MqttClientConfiguration { // 构造遗嘱消息 MqttClientProperties.WillMessage willMessage = properties.getWillMessage(); if (willMessage != null && StringUtils.hasText(willMessage.getTopic())) { - MqttWillMessage.Builder builder = MqttWillMessage.builder(); - builder.topic(willMessage.getTopic()) - .qos(willMessage.getQos()) - .retain(willMessage.isRetain()); - if (StringUtils.hasText(willMessage.getMessage())) { - builder.message(willMessage.getMessage().getBytes(StandardCharsets.UTF_8)); - } - clientCreator.willMessage(builder.build()); + clientCreator.willMessage(builder -> { + builder.topic(willMessage.getTopic()) + .qos(willMessage.getQos()) + .retain(willMessage.isRetain()); + if (StringUtils.hasText(willMessage.getMessage())) { + builder.message(willMessage.getMessage().getBytes(StandardCharsets.UTF_8)); + } + }); } // 配置客户端链接监听器 clientConnectListenerObjectProvider.ifAvailable(clientCreator::connectListener); -- GitLab