All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feingto.iot.server.handler.mqtt.PubrelHandler Maven / Gradle / Ivy

There is a newer version: 1.2.5.RELEASE
Show newest version
package com.feingto.iot.server.handler.mqtt;

import com.feingto.iot.common.Constants;
import com.feingto.iot.common.cache.MessageCache;
import com.feingto.iot.common.handler.BaseMessageHandler;
import com.feingto.iot.common.model.mqtt.SendMessage;
import com.feingto.iot.common.service.mqtt.MessageResponse;
import com.feingto.iot.server.service.PushService;
import io.netty.channel.Channel;
import io.netty.handler.codec.mqtt.MqttMessage;
import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader;
import io.netty.handler.codec.mqtt.MqttMessageType;
import io.netty.handler.codec.mqtt.MqttPublishMessage;

/**
 * Qos level = 2的协议流的第三个消息
 *
 * @author longfei
 */
public class PubrelHandler extends BaseMessageHandler {
    private final PushService pushService;

    public PubrelHandler(PushService pushService) {
        super(MqttMessageType.PUBREL);
        this.pushService = pushService;
    }

    @Override
    public void handle(Channel channel, Object object) {
        MqttMessage msg = (MqttMessage) object;
        MqttMessageIdVariableHeader variableHeader = (MqttMessageIdVariableHeader) msg.variableHeader();
        // 发布消息到所有订阅者
        pushService.internalSend(SendMessage.newInstance((MqttPublishMessage) msg));

        // 删除持久化消息
        MessageCache.getInstance(igniteMessage)
                .remove(channel.attr(Constants.KEY_CLIENT_ID).get(), variableHeader.messageId());

        // 返回pubcomp消息
        MessageResponse.pubcomp(channel, variableHeader.messageId());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy