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());
}
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);
}
}
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));
}
}
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);
}
Aggregations