com.feingto.iot.common.model.mqtt.SendMessage Maven / Gradle / Ivy
package com.feingto.iot.common.model.mqtt;
import com.feingto.iot.common.util.ParserKit;
import io.netty.handler.codec.mqtt.MqttMessageType;
import io.netty.handler.codec.mqtt.MqttPublishMessage;
import io.netty.handler.codec.mqtt.MqttQoS;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* Mqtt 消息
*
* @author longfei
*/
@Data
@Accessors(fluent = true)
public class SendMessage implements Serializable {
private static final long serialVersionUID = 3934400295613105846L;
/**
* 消息ID
*/
private Integer id;
/**
* 主题名称
*/
private String topic;
/**
* 是否第一次发送
* false: 表示当前为第一次发送
*/
private boolean dup;
/**
* QoS level
* 0: 发布到所有订阅者,不响应
* 1: 持久化,发布到所有订阅者,返回PUBACK
* 2: 持久化,不发布,返回PUBREC,需要彼此确认
* QoS level = 2 消息保障的网络I/O次数过多,如非必需,尽量少用
*/
private MqttQoS mqttQoS;
/**
* 是否持久化
* false: 仅仅为当前订阅者推送此消息; 1: 一直持久保存
*/
private boolean retain;
/**
* 消息内容
*/
private byte[] payload;
/**
* 消息类型
*/
private MqttMessageType type;
public static SendMessage newInstance(MqttPublishMessage msg) {
return new SendMessage()
.id(msg.variableHeader().packetId())
.topic(msg.variableHeader().topicName())
.dup(false)
.mqttQoS(msg.fixedHeader().qosLevel())
.retain(msg.fixedHeader().isRetain())
.payload(ParserKit.copyByteBuf(msg.payload()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy