Search in sources :

Example 1 with MqttPubAckMessage

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

the class MqttPubackMessageHandler method handleMessage.

/**
 * handle the PUBACK message from the client
 * <ol>
 *     <li>remove the message from the published in-flight messages</li>
 *     <li>ack the message in the MessageStore</li>
 * </ol>
 * @param
 * @return
 */
@Override
public void handleMessage(Message message) {
    MqttPubAckMessage pubAckMessage = (MqttPubAckMessage) message.getPayload();
    // TODO: remove the message from the published in-flight message
    messageStore.ack(message, (List<MqttClient>) message.getClient());
}
Also used : MqttClient(org.apache.rocketmq.iot.protocol.mqtt.data.MqttClient) MqttPubAckMessage(io.netty.handler.codec.mqtt.MqttPubAckMessage)

Example 2 with MqttPubAckMessage

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

the class MqttPublishMessageHandler method handleMessage.

@Override
public void handleMessage(Message message) {
    Client client = message.getClient();
    MqttPublishMessage publishMessage = (MqttPublishMessage) message.getPayload();
    messageStore.put(message);
    int qos = MessageUtil.actualQos(publishMessage.fixedHeader().qosLevel().value());
    if (qos == MqttQoS.AT_LEAST_ONCE.value()) {
        MqttPubAckMessage pubAckMessage = MessageUtil.getMqttPubackMessage(publishMessage);
        client.getCtx().writeAndFlush(pubAckMessage);
    } else if (qos == MqttQoS.EXACTLY_ONCE.value()) {
        MqttMessage pubrecMessage = MessageUtil.getMqttPubrecMessage(publishMessage);
        client.getCtx().writeAndFlush(pubrecMessage);
    }
}
Also used : MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) MqttPubAckMessage(io.netty.handler.codec.mqtt.MqttPubAckMessage) MqttPublishMessage(io.netty.handler.codec.mqtt.MqttPublishMessage) Client(org.apache.rocketmq.iot.connection.client.Client)

Example 3 with MqttPubAckMessage

use of io.netty.handler.codec.mqtt.MqttPubAckMessage in project hono by eclipse.

the class CommandAndControlMqttIT method injectMqttClientPubAckBlocker.

private Future<Void> injectMqttClientPubAckBlocker(final AtomicBoolean outboundPubAckBlocked) {
    // Therefore the underlying NetSocket pipeline is used here to filter out the outbound PubAck messages.
    try {
        final Method connectionMethod = MqttClientImpl.class.getDeclaredMethod("connection");
        connectionMethod.setAccessible(true);
        final NetSocketInternal connection = (NetSocketInternal) connectionMethod.invoke(mqttClient);
        connection.channelHandlerContext().pipeline().addBefore("handler", "OutboundPubAckBlocker", new ChannelOutboundHandlerAdapter() {

            @Override
            public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) throws Exception {
                if (outboundPubAckBlocked.get() && msg instanceof io.netty.handler.codec.mqtt.MqttPubAckMessage) {
                    LOGGER.debug("suppressing PubAck, message id: {}", ((MqttPubAckMessage) msg).variableHeader().messageId());
                } else {
                    super.write(ctx, msg, promise);
                }
            }
        });
        return Future.succeededFuture();
    } catch (final Exception e) {
        LOGGER.error("failed to inject PubAck blocking handler");
        return Future.failedFuture(new Exception("failed to inject PubAck blocking handler", e));
    }
}
Also used : MqttPubAckMessage(io.netty.handler.codec.mqtt.MqttPubAckMessage) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise) Method(java.lang.reflect.Method) IllegalStateException(javax.jms.IllegalStateException) ClientErrorException(org.eclipse.hono.client.ClientErrorException) ServerErrorException(org.eclipse.hono.client.ServerErrorException) SendMessageTimeoutException(org.eclipse.hono.client.SendMessageTimeoutException) NetSocketInternal(io.vertx.core.net.impl.NetSocketInternal)

Example 4 with MqttPubAckMessage

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

the class MQTTProtocolHandler method sendPublishProtocolControlMessage.

void sendPublishProtocolControlMessage(int messageId, MqttMessageType messageType) {
    MqttQoS qos = (messageType == MqttMessageType.PUBREL) ? MqttQoS.AT_LEAST_ONCE : MqttQoS.AT_MOST_ONCE;
    MqttFixedHeader fixedHeader = new // Spec requires 01 in header for rel
    MqttFixedHeader(// Spec requires 01 in header for rel
    messageType, // Spec requires 01 in header for rel
    false, // Spec requires 01 in header for rel
    qos, false, 0);
    MqttPubAckMessage rel = new MqttPubAckMessage(fixedHeader, MqttMessageIdVariableHeader.from(messageId));
    sendToClient(rel);
}
Also used : MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader) MqttPubAckMessage(io.netty.handler.codec.mqtt.MqttPubAckMessage) MqttQoS(io.netty.handler.codec.mqtt.MqttQoS)

Aggregations

MqttPubAckMessage (io.netty.handler.codec.mqtt.MqttPubAckMessage)4 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)1 ChannelPromise (io.netty.channel.ChannelPromise)1 MqttFixedHeader (io.netty.handler.codec.mqtt.MqttFixedHeader)1 MqttMessage (io.netty.handler.codec.mqtt.MqttMessage)1 MqttPublishMessage (io.netty.handler.codec.mqtt.MqttPublishMessage)1 MqttQoS (io.netty.handler.codec.mqtt.MqttQoS)1 NetSocketInternal (io.vertx.core.net.impl.NetSocketInternal)1 Method (java.lang.reflect.Method)1 IllegalStateException (javax.jms.IllegalStateException)1 Client (org.apache.rocketmq.iot.connection.client.Client)1 MqttClient (org.apache.rocketmq.iot.protocol.mqtt.data.MqttClient)1 ClientErrorException (org.eclipse.hono.client.ClientErrorException)1 SendMessageTimeoutException (org.eclipse.hono.client.SendMessageTimeoutException)1 ServerErrorException (org.eclipse.hono.client.ServerErrorException)1