Search in sources :

Example 1 with MqttFixedHeader

use of io.netty.handler.codec.mqtt.MqttFixedHeader in project activemq-artemis by apache.

the class MQTTProtocolHandler method handlePingreq.

void handlePingreq() {
    MqttMessage pingResp = new MqttMessage(new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0));
    sendToClient(pingResp);
}
Also used : MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader)

Example 2 with MqttFixedHeader

use of io.netty.handler.codec.mqtt.MqttFixedHeader in project activemq-artemis by apache.

the class MQTTProtocolHandler method handleSubscribe.

void handleSubscribe(MqttSubscribeMessage message) throws Exception {
    MQTTSubscriptionManager subscriptionManager = session.getSubscriptionManager();
    int[] qos = subscriptionManager.addSubscriptions(message.payload().topicSubscriptions());
    MqttFixedHeader header = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttSubAckMessage ack = new MqttSubAckMessage(header, message.variableHeader(), new MqttSubAckPayload(qos));
    sendToClient(ack);
}
Also used : MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader) MqttSubAckMessage(io.netty.handler.codec.mqtt.MqttSubAckMessage) MqttSubAckPayload(io.netty.handler.codec.mqtt.MqttSubAckPayload)

Example 3 with MqttFixedHeader

use of io.netty.handler.codec.mqtt.MqttFixedHeader in project activemq-artemis by apache.

the class MQTTInterceptorPropertiesTest method checkMessageProperties.

private boolean checkMessageProperties(MqttMessage message, Map<String, Object> expectedProperties) {
    System.out.println("Checking properties in interceptor");
    try {
        assertNotNull(message);
        assertNotNull(server.getNodeID());
        MqttFixedHeader header = message.fixedHeader();
        assertNotNull(header.messageType());
        assertEquals(header.qosLevel().value(), AT_MOST_ONCE);
        assertEquals(header.isRetain(), expectedProperties.get(RETAINED));
    } catch (Throwable t) {
        collector.addError(t);
    }
    return true;
}
Also used : MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader)

Example 4 with MqttFixedHeader

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

the class MqttHeartBeatClientHandler method channelActive.

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    MqttFixedHeader connectFixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttConnectVariableHeader connectVariableHeader = new MqttConnectVariableHeader(PROTOCOL_NAME_MQTT_3_1_1, PROTOCOL_VERSION_MQTT_3_1_1, true, true, false, 0, false, false, 20, MqttProperties.NO_PROPERTIES);
    MqttConnectPayload connectPayload = new MqttConnectPayload(clientId, MqttProperties.NO_PROPERTIES, null, null, userName, password);
    MqttConnectMessage connectMessage = new MqttConnectMessage(connectFixedHeader, connectVariableHeader, connectPayload);
    ctx.writeAndFlush(connectMessage);
    System.out.println("Sent CONNECT");
}
Also used : MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader) MqttConnectMessage(io.netty.handler.codec.mqtt.MqttConnectMessage) MqttConnectPayload(io.netty.handler.codec.mqtt.MqttConnectPayload) MqttConnectVariableHeader(io.netty.handler.codec.mqtt.MqttConnectVariableHeader)

Example 5 with MqttFixedHeader

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

the class MqttHeartBeatClientHandler method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        MqttFixedHeader pingreqFixedHeader = new MqttFixedHeader(MqttMessageType.PINGREQ, false, MqttQoS.AT_MOST_ONCE, false, 0);
        MqttMessage pingreqMessage = new MqttMessage(pingreqFixedHeader);
        ctx.writeAndFlush(pingreqMessage);
        System.out.println("Sent PINGREQ");
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader)

Aggregations

MqttFixedHeader (io.netty.handler.codec.mqtt.MqttFixedHeader)27 MqttPublishMessage (io.netty.handler.codec.mqtt.MqttPublishMessage)7 MqttPublishVariableHeader (io.netty.handler.codec.mqtt.MqttPublishVariableHeader)7 MqttMessageIdVariableHeader (io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader)6 MqttConnectMessage (io.netty.handler.codec.mqtt.MqttConnectMessage)5 MqttConnectPayload (io.netty.handler.codec.mqtt.MqttConnectPayload)5 MqttConnectVariableHeader (io.netty.handler.codec.mqtt.MqttConnectVariableHeader)5 MqttMessage (io.netty.handler.codec.mqtt.MqttMessage)4 MqttConnAckMessage (io.netty.handler.codec.mqtt.MqttConnAckMessage)3 MqttConnAckVariableHeader (io.netty.handler.codec.mqtt.MqttConnAckVariableHeader)3 MqttSubscribeMessage (io.netty.handler.codec.mqtt.MqttSubscribeMessage)3 MqttSubscribePayload (io.netty.handler.codec.mqtt.MqttSubscribePayload)3 ByteBuf (io.netty.buffer.ByteBuf)2 MqttSubAckMessage (io.netty.handler.codec.mqtt.MqttSubAckMessage)2 MqttUnsubAckMessage (io.netty.handler.codec.mqtt.MqttUnsubAckMessage)2 ArrayList (java.util.ArrayList)2 MqttPubAckMessage (io.netty.handler.codec.mqtt.MqttPubAckMessage)1 MqttQoS (io.netty.handler.codec.mqtt.MqttQoS)1 MqttSubAckPayload (io.netty.handler.codec.mqtt.MqttSubAckPayload)1 MqttTopicSubscription (io.netty.handler.codec.mqtt.MqttTopicSubscription)1