Search in sources :

Example 41 with MqttFixedHeader

use of io.netty.handler.codec.mqtt.MqttFixedHeader in project thingsboard by thingsboard.

the class MqttClientImpl method checkSubscribtions.

private void checkSubscribtions(String topic, Promise<Void> promise) {
    if (!(this.subscriptions.containsKey(topic) && this.subscriptions.get(topic).size() != 0) && this.serverSubscriptions.contains(topic)) {
        MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.UNSUBSCRIBE, false, MqttQoS.AT_LEAST_ONCE, false, 0);
        MqttMessageIdVariableHeader variableHeader = getNewMessageId();
        MqttUnsubscribePayload payload = new MqttUnsubscribePayload(Collections.singletonList(topic));
        MqttUnsubscribeMessage message = new MqttUnsubscribeMessage(fixedHeader, variableHeader, payload);
        MqttPendingUnsubscription pendingUnsubscription = new MqttPendingUnsubscription(promise, topic, message, () -> !pendingServerUnsubscribes.containsKey(variableHeader.messageId()));
        this.pendingServerUnsubscribes.put(variableHeader.messageId(), pendingUnsubscription);
        pendingUnsubscription.startRetransmissionTimer(this.eventLoop.next(), this::sendAndFlushPacket);
        this.sendAndFlushPacket(message);
    } else {
        promise.setSuccess(null);
    }
}
Also used : MqttMessageIdVariableHeader(io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader) MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader) MqttUnsubscribeMessage(io.netty.handler.codec.mqtt.MqttUnsubscribeMessage) MqttUnsubscribePayload(io.netty.handler.codec.mqtt.MqttUnsubscribePayload)

Example 42 with MqttFixedHeader

use of io.netty.handler.codec.mqtt.MqttFixedHeader in project thingsboard by thingsboard.

the class MqttPingHandler method handlePingReq.

private void handlePingReq(Channel channel) {
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0);
    channel.writeAndFlush(new MqttMessage(fixedHeader));
}
Also used : MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader)

Example 43 with MqttFixedHeader

use of io.netty.handler.codec.mqtt.MqttFixedHeader in project thingsboard by thingsboard.

the class MqttClientImpl method disconnect.

@Override
public void disconnect() {
    disconnected = true;
    if (this.channel != null) {
        MqttMessage message = new MqttMessage(new MqttFixedHeader(MqttMessageType.DISCONNECT, false, MqttQoS.AT_MOST_ONCE, false, 0));
        this.sendAndFlushPacket(message).addListener(future1 -> channel.close());
    }
}
Also used : MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader)

Aggregations

MqttFixedHeader (io.netty.handler.codec.mqtt.MqttFixedHeader)43 MqttPublishMessage (io.netty.handler.codec.mqtt.MqttPublishMessage)13 MqttPublishVariableHeader (io.netty.handler.codec.mqtt.MqttPublishVariableHeader)12 MqttMessage (io.netty.handler.codec.mqtt.MqttMessage)11 MqttMessageIdVariableHeader (io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader)11 ByteBuf (io.netty.buffer.ByteBuf)6 MqttConnectMessage (io.netty.handler.codec.mqtt.MqttConnectMessage)6 MqttConnectPayload (io.netty.handler.codec.mqtt.MqttConnectPayload)6 MqttConnectVariableHeader (io.netty.handler.codec.mqtt.MqttConnectVariableHeader)6 MqttConnAckMessage (io.netty.handler.codec.mqtt.MqttConnAckMessage)4 MqttConnAckVariableHeader (io.netty.handler.codec.mqtt.MqttConnAckVariableHeader)4 MqttSubscribeMessage (io.netty.handler.codec.mqtt.MqttSubscribeMessage)4 MqttSubscribePayload (io.netty.handler.codec.mqtt.MqttSubscribePayload)4 MqttSubAckMessage (io.netty.handler.codec.mqtt.MqttSubAckMessage)3 MqttUnsubscribeMessage (io.netty.handler.codec.mqtt.MqttUnsubscribeMessage)3 MqttUnsubscribePayload (io.netty.handler.codec.mqtt.MqttUnsubscribePayload)3 ChannelFuture (io.netty.channel.ChannelFuture)2 MqttPubAckMessage (io.netty.handler.codec.mqtt.MqttPubAckMessage)2 MqttQoS (io.netty.handler.codec.mqtt.MqttQoS)2 MqttSubAckPayload (io.netty.handler.codec.mqtt.MqttSubAckPayload)2