Search in sources :

Example 1 with MqttUnsubscribePayload

use of io.netty.handler.codec.mqtt.MqttUnsubscribePayload in project rocketmq-externals by apache.

the class MqttUnsubscribeMessageHandlerTest method getMqttUnsubscribeMessage.

private MqttUnsubscribeMessage getMqttUnsubscribeMessage() {
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.UNSUBSCRIBE, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(1);
    List<String> topicFilters = new ArrayList<>();
    MqttUnsubscribePayload payload = new MqttUnsubscribePayload(topicFilters);
    return new MqttUnsubscribeMessage(fixedHeader, variableHeader, payload);
}
Also used : MqttMessageIdVariableHeader(io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader) MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader) MqttUnsubscribeMessage(io.netty.handler.codec.mqtt.MqttUnsubscribeMessage) ArrayList(java.util.ArrayList) MqttUnsubscribePayload(io.netty.handler.codec.mqtt.MqttUnsubscribePayload)

Example 2 with MqttUnsubscribePayload

use of io.netty.handler.codec.mqtt.MqttUnsubscribePayload 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)

Aggregations

MqttFixedHeader (io.netty.handler.codec.mqtt.MqttFixedHeader)2 MqttMessageIdVariableHeader (io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader)2 MqttUnsubscribeMessage (io.netty.handler.codec.mqtt.MqttUnsubscribeMessage)2 MqttUnsubscribePayload (io.netty.handler.codec.mqtt.MqttUnsubscribePayload)2 ArrayList (java.util.ArrayList)1