提交 c0bcdc53 编写于 作者: 浅梦2013's avatar 浅梦2013

开始 2.1.1-SNAPSHOT

上级 bd1d374c
package net.dreamlu.iot.mqtt.client.listener;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.codec.MqttPublishMessage;
import net.dreamlu.iot.mqtt.core.client.IMqttClientMessageListener;
import net.dreamlu.iot.mqtt.spring.client.MqttClientSubscribe;
......@@ -8,6 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.tio.core.ChannelContext;
import org.tio.utils.buffer.ByteBufferUtil;
import java.nio.ByteBuffer;
......
package net.dreamlu.iot.mqtt.client.listener;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.codec.MqttQoS;
import net.dreamlu.iot.mqtt.spring.client.MqttClientSubscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.tio.utils.buffer.ByteBufferUtil;
import java.nio.ByteBuffer;
......
package net.dreamlu.iot.mqtt.client.service;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.spring.client.MqttClientTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.tio.utils.buffer.ByteBufferUtil;
import java.nio.charset.StandardCharsets;
......
......@@ -16,8 +16,8 @@
package net.dreamlu.iot.mqtt.aliyun;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.core.client.MqttClient;
import org.tio.utils.buffer.ByteBufferUtil;
import java.nio.charset.StandardCharsets;
import java.util.Timer;
......
......@@ -16,10 +16,10 @@
package net.dreamlu.iot.mqtt.broker;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.core.client.MqttClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.utils.buffer.ByteBufferUtil;
/**
* 设备 A,这里默认 APP 应用端
......
......@@ -16,10 +16,10 @@
package net.dreamlu.iot.mqtt.broker;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.core.client.MqttClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.utils.buffer.ByteBufferUtil;
/**
* 设备 B,这里默认 web 端
......
......@@ -16,10 +16,10 @@
package net.dreamlu.iot.mqtt.client;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.core.client.MqttClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.utils.buffer.ByteBufferUtil;
import java.nio.charset.StandardCharsets;
......
......@@ -16,7 +16,6 @@
package net.dreamlu.iot.mqtt.client;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.codec.MqttPublishMessage;
import net.dreamlu.iot.mqtt.codec.MqttQoS;
import net.dreamlu.iot.mqtt.core.client.IMqttClientMessageListener;
......@@ -24,6 +23,7 @@ import net.dreamlu.iot.mqtt.core.client.MqttClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.ChannelContext;
import org.tio.utils.buffer.ByteBufferUtil;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
......
......@@ -16,8 +16,8 @@
package net.dreamlu.iot.mqtt.huawei;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.core.client.MqttClient;
import org.tio.utils.buffer.ByteBufferUtil;
import java.nio.charset.StandardCharsets;
import java.util.Timer;
......
......@@ -16,10 +16,10 @@
package net.dreamlu.iot.mqtt.server;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.core.server.MqttServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.utils.buffer.ByteBufferUtil;
import java.nio.charset.StandardCharsets;
import java.util.Timer;
......
package net.dreamlu.iot.mqtt.server.listener;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.core.server.model.Message;
import net.dreamlu.iot.mqtt.spring.server.MqttServerTemplate;
import org.slf4j.Logger;
......@@ -8,6 +7,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.tio.core.ChannelContext;
import org.tio.utils.buffer.ByteBufferUtil;
/**
* 监听器1,使用 Spring boot event 的方式
......
package net.dreamlu.iot.mqtt.server.listener;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.codec.MqttPublishMessage;
import net.dreamlu.iot.mqtt.codec.MqttQoS;
import net.dreamlu.iot.mqtt.core.server.event.IMqttMessageListener;
......@@ -12,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.tio.core.ChannelContext;
import org.tio.utils.buffer.ByteBufferUtil;
/**
* 消息监听器示例2,优点:性能损失小
......
package net.dreamlu.iot.mqtt.broker.listener;
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.codec.MqttPublishMessage;
import net.dreamlu.iot.mqtt.codec.MqttQoS;
import net.dreamlu.iot.mqtt.core.server.event.IMqttMessageListener;
......@@ -8,6 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.tio.core.ChannelContext;
import org.tio.utils.buffer.ByteBufferUtil;
/**
* 消息监听
......
......@@ -80,8 +80,14 @@ public final class MqttWillMessage {
public static final class Builder {
private String topic;
private byte[] message;
private boolean retain;
private MqttQoS qos;
/**
* 默认为不保存
*/
private boolean retain = false;
/**
* 默认为 qos 0
*/
private MqttQoS qos = MqttQoS.AT_MOST_ONCE;
private MqttProperties willProperties;
public Builder topic(String topic) {
......
/*
* 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.codec;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/**
* ByteBuffer 工具
*
* @author L.cm
*/
public class ByteBufferUtil {
/**
* 空 byte 数组
*/
public static final byte[] EMPTY_BYTES = new byte[0];
/**
* read byte
*
* @param buffer ByteBuffer
* @return byte
*/
public static byte readByte(ByteBuffer buffer) {
return buffer.get();
}
/**
* read unsigned byte
*
* @param buffer ByteBuffer
* @return short
*/
public static short readUnsignedByte(ByteBuffer buffer) {
return (short) (readByte(buffer) & 0xFF);
}
/**
* skip bytes
*
* @param buffer ByteBuffer
* @param skip skip bytes
* @return ByteBuffer
*/
public static ByteBuffer skipBytes(ByteBuffer buffer, int skip) {
buffer.position(buffer.position() + skip);
return buffer;
}
/**
* 转成 string
*
* @param buffer ByteBuffer
* @return 字符串
*/
public static String toString(ByteBuffer buffer) {
return new String(buffer.array(), StandardCharsets.UTF_8);
}
/**
* 转成 string
*
* @param buffer ByteBuffer
* @param charset Charset
* @return 字符串
*/
public static String toString(ByteBuffer buffer, Charset charset) {
return new String(buffer.array(), buffer.position(), buffer.limit(), charset);
}
/**
* ByteBuffer clone
*
* @param original ByteBuffer
* @return ByteBuffer
*/
public static ByteBuffer clone(ByteBuffer original) {
ByteBuffer clone = ByteBuffer.allocate(original.capacity());
// copy from the beginning
original.rewind();
clone.put(original);
original.rewind();
clone.flip();
return clone;
}
}
......@@ -18,6 +18,7 @@ package net.dreamlu.iot.mqtt.codec;
import org.tio.core.ChannelContext;
import org.tio.core.exception.TioDecodeException;
import org.tio.utils.buffer.ByteBufferUtil;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
......
......@@ -17,6 +17,7 @@
package net.dreamlu.iot.mqtt.codec;
import org.tio.core.ChannelContext;
import org.tio.utils.buffer.ByteBufferUtil;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
......
......@@ -17,6 +17,7 @@
package net.dreamlu.iot.mqtt.codec;
import net.dreamlu.iot.mqtt.codec.MqttProperties.MqttPropertyType;
import org.tio.utils.buffer.ByteBufferUtil;
import java.nio.ByteBuffer;
import java.util.ArrayList;
......
......@@ -13,7 +13,7 @@
<properties>
<!-- mica-mqtt version -->
<revision>2.1.0</revision>
<revision>2.1.1-SNAPSHOT</revision>
<!-- java version -->
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
......@@ -148,8 +148,9 @@ mica-mqtt client 支持**两种共享订阅**方式:
2. 分组订阅:订阅前缀 `$share/<group>/`,组客户端订阅了`$share/group1/topic``$share/group2/topic`..,发布者发布到topic,则消息会发布到每个group中,但是每个group中只有一个客户端会接收到消息。
### 2.8 MqttClientTemplate 使用示例
```java
import net.dreamlu.iot.mqtt.codec.ByteBufferUtil;
import net.dreamlu.iot.mqtt.spring.client.MqttClientTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
......@@ -244,7 +244,7 @@ public class MqttClientTemplate implements InitializingBean, DisposableBean, Ord
* @return MqttClientCreator
*/
public MqttClientCreator getClientCreator() {
return client.getClientCreator();
return mqttClientCreator;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册