Search in sources :

Example 31 with MqttFixedHeader

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

the class MQTTProtocolHandler method handleUnsubscribe.

void handleUnsubscribe(MqttUnsubscribeMessage message) throws Exception {
    session.getSubscriptionManager().removeSubscriptions(message.payload().topics());
    MqttFixedHeader header = new MqttFixedHeader(MqttMessageType.UNSUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttUnsubAckMessage m = new MqttUnsubAckMessage(header, message.variableHeader());
    sendToClient(m);
}
Also used : MqttUnsubAckMessage(io.netty.handler.codec.mqtt.MqttUnsubAckMessage) MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader)

Example 32 with MqttFixedHeader

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

the class PubSubIntegrationTest method getMqttPublishMessage.

private MqttPublishMessage getMqttPublishMessage() {
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttPublishVariableHeader variableHeader = new MqttPublishVariableHeader(topicName, producerPublishId);
    return new MqttPublishMessage(fixedHeader, variableHeader, Unpooled.buffer().writeBytes("hello world".getBytes()));
}
Also used : MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader) MqttPublishMessage(io.netty.handler.codec.mqtt.MqttPublishMessage) MqttPublishVariableHeader(io.netty.handler.codec.mqtt.MqttPublishVariableHeader)

Example 33 with MqttFixedHeader

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

the class ProduceMessageIntegrationTest method getMqttPublishMessage.

private MqttPublishMessage getMqttPublishMessage() {
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttPublishVariableHeader variableHeader = new MqttPublishVariableHeader(topicName, packetId);
    return new MqttPublishMessage(fixedHeader, variableHeader, Unpooled.buffer().writeBytes("hello world".getBytes()));
}
Also used : MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader) MqttPublishMessage(io.netty.handler.codec.mqtt.MqttPublishMessage) MqttPublishVariableHeader(io.netty.handler.codec.mqtt.MqttPublishVariableHeader)

Example 34 with MqttFixedHeader

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

the class MqttMessageForwarder method handleMessage.

/**
 * handle PUBLISH message from client
 *
 * @param message
 * @return whether the message is handled successfully
 */
@Override
public void handleMessage(Message message) {
    MqttPublishMessage publishMessage = (MqttPublishMessage) message.getPayload();
    String topic = publishMessage.variableHeader().topicName();
    if (!subscriptionStore.hasTopic(topic)) {
        subscriptionStore.addTopic(topic);
    }
    for (Subscription subscription : subscriptionStore.get(publishMessage.variableHeader().topicName())) {
        ByteBuf buf = Unpooled.buffer();
        byte[] bytes = new byte[publishMessage.payload().readableBytes()];
        publishMessage.payload().getBytes(0, bytes);
        buf.writeBytes(bytes);
        MqttPublishMessage msg = new MqttPublishMessage(new MqttFixedHeader(MqttMessageType.PUBLISH, publishMessage.fixedHeader().isDup(), MqttQoS.valueOf(MessageUtil.actualQos(publishMessage.fixedHeader().qosLevel().value())), publishMessage.fixedHeader().isRetain(), publishMessage.fixedHeader().remainingLength()), new MqttPublishVariableHeader(publishMessage.variableHeader().topicName(), publishMessage.variableHeader().packetId()), buf);
        subscription.getClient().getCtx().writeAndFlush(msg);
    }
}
Also used : MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader) MqttPublishMessage(io.netty.handler.codec.mqtt.MqttPublishMessage) MqttPublishVariableHeader(io.netty.handler.codec.mqtt.MqttPublishVariableHeader) Subscription(org.apache.rocketmq.iot.protocol.mqtt.data.Subscription) ByteBuf(io.netty.buffer.ByteBuf)

Example 35 with MqttFixedHeader

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

the class MqttHeartBeatBrokerHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    MqttMessage mqttMessage = (MqttMessage) msg;
    System.out.println("Received MQTT message: " + mqttMessage);
    switch(mqttMessage.fixedHeader().messageType()) {
        case CONNECT:
            MqttFixedHeader connackFixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
            MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(MqttConnectReturnCode.CONNECTION_ACCEPTED, false);
            MqttConnAckMessage connack = new MqttConnAckMessage(connackFixedHeader, mqttConnAckVariableHeader);
            ctx.writeAndFlush(connack);
            break;
        case PINGREQ:
            MqttFixedHeader pingreqFixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0);
            MqttMessage pingResp = new MqttMessage(pingreqFixedHeader);
            ctx.writeAndFlush(pingResp);
            break;
        case DISCONNECT:
            ctx.close();
            break;
        default:
            System.out.println("Unexpected message type: " + mqttMessage.fixedHeader().messageType());
            ReferenceCountUtil.release(msg);
            ctx.close();
    }
}
Also used : MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader) MqttConnAckVariableHeader(io.netty.handler.codec.mqtt.MqttConnAckVariableHeader) MqttConnAckMessage(io.netty.handler.codec.mqtt.MqttConnAckMessage)

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