io.netty.handler.codec.mqtt.MqttPubAckMessage Java Examples
The following examples show how to use
io.netty.handler.codec.mqtt.MqttPubAckMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommandAndControlMqttIT.java From hono with Eclipse Public License 2.0 | 6 votes |
private Future<Void> injectMqttClientPubAckBlocker(final AtomicBoolean outboundPubAckBlocked) { // The vert.x MqttClient automatically sends a PubAck after having received a Qos 1 Publish message, // as of now, there is no configuration option to prevent this (see https://github.com/vert-x3/vertx-mqtt/issues/120). // 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)); } }
Example #2
Source File: PubAck.java From WeEvent with Apache License 2.0 | 5 votes |
@Override public Optional<MqttMessage> process(MqttMessage req, String clientId, String remoteIp) { MqttPubAckMessage msg = (MqttPubAckMessage) req; int messageId = msg.variableHeader().messageId(); log.info("PUBACK, message Id: {}", messageId); this.messageIdStore.releaseMessageId(messageId); return Optional.empty(); }
Example #3
Source File: MqttProtocolHandler.java From joyqueue with Apache License 2.0 | 5 votes |
public void processPubAck(Channel client, MqttPubAckMessage pubAckMessage) { MqttMessageIdVariableHeader pubAckVariableMessage = pubAckMessage.variableHeader(); short packageId = (short) pubAckVariableMessage.messageId(); String clientId = NettyAttrManager.getAttrClientId(client); consumerManager.acknowledge(clientId, packageId); if (LOG.isDebugEnabled()) { LOG.debug("Received PubAck packageID: {}" + packageId); } }
Example #4
Source File: MqttMessageFactory.java From lannister with Apache License 2.0 | 5 votes |
public static MqttPubAckMessage puback(int messageId) { MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBACK, false, MqttQoS.AT_MOST_ONCE, false, 2); MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId); return new MqttPubAckMessage(fixedHeader, variableHeader); }
Example #5
Source File: PubAckReceiver.java From lannister with Apache License 2.0 | 5 votes |
@Override protected void channelRead0(ChannelHandlerContext ctx, MqttPubAckMessage msg) throws Exception { logger.debug("packet incoming [message={}]", msg.toString()); Session session = Session.NEXUS.get(ctx.channel().id()); if (session == null) { logger.error("None exist session message [message={}]", msg.toString()); ctx.channel().disconnect().addListener(ChannelFutureListener.CLOSE).addListener(fs -> // [MQTT-4.8.0-1] Plugins.INSTANCE.get(DisconnectEventListener.class).disconnected(new AbnormalDisconnectEventArgs())); return; } session.setLastIncomingTime(new Date()); String clientId = session.clientId(); int messageId = msg.variableHeader().messageId(); OutboundMessageStatus status = OutboundMessageStatus.NEXUS.removeByKey(messageId, clientId); if (status == null) { logger.error("PUBACK target does not exist [clientId={}, messageId={}]", clientId, messageId); session.dispose(true); // [MQTT-3.3.5-2] return; } ctx.channel().eventLoop() .execute(() -> Plugins.INSTANCE.get(DeliveredEventListener.class).delivered(new DeliveredEventArgs() { @Override public String clientId() { return clientId; } @Override public int messageId() { return messageId; } })); logger.debug("Outbound message status REMOVED [clientId={}, messageId={}]", clientId, messageId); }
Example #6
Source File: MQTTProtocolHandler.java From activemq-artemis with Apache License 2.0 | 5 votes |
void sendPublishProtocolControlMessage(int messageId, MqttMessageType messageType) { MqttQoS qos = (messageType == MqttMessageType.PUBREL) ? MqttQoS.AT_LEAST_ONCE : MqttQoS.AT_MOST_ONCE; MqttFixedHeader fixedHeader = new MqttFixedHeader(messageType, false, qos, // Spec requires 01 in header for rel false, 0); MqttPubAckMessage rel = new MqttPubAckMessage(fixedHeader, MqttMessageIdVariableHeader.from(messageId)); sendToClient(rel); }
Example #7
Source File: MqttProtocolUtil.java From ext-opensource-netty with Mozilla Public License 2.0 | 4 votes |
public static MqttPubAckMessage pubAckMessage(int messageId) { return (MqttPubAckMessage) MqttMessageFactory.newMessage( new MqttFixedHeader(MqttMessageType.PUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0), MqttMessageIdVariableHeader.from(messageId), null); }
Example #8
Source File: MessageUtil.java From iot-mqtt with Apache License 2.0 | 4 votes |
public static MqttPubAckMessage getPubAckMessage(int messageId){ MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBACK,false,MqttQoS.AT_MOST_ONCE,false,0); MqttMessageIdVariableHeader idVariableHeader = MqttMessageIdVariableHeader.from(messageId); return new MqttPubAckMessage(fixedHeader,idVariableHeader); }
Example #9
Source File: PublishProcessor.java From iot-mqtt with Apache License 2.0 | 4 votes |
private void processQos1(ChannelHandlerContext ctx,Message innerMsg){ processMessage(innerMsg); log.debug("[PubMessage] -> Process qos1 message,clientId={}",innerMsg.getClientId()); MqttPubAckMessage pubAckMessage = MessageUtil.getPubAckMessage(innerMsg.getMsgId()); ctx.writeAndFlush(pubAckMessage); }
Example #10
Source File: PublishAckHandler.java From joyqueue with Apache License 2.0 | 4 votes |
@Override public void handleRequest(Channel client, MqttMessage message) throws Exception { MqttPubAckMessage pubAckMessage = (MqttPubAckMessage) message; mqttProtocolHandler.processPubAck(client, pubAckMessage); }
Example #11
Source File: PublishProcessor.java From jmqtt with Apache License 2.0 | 4 votes |
private void processQos1(ChannelHandlerContext ctx,Message innerMsg){ processMessage(innerMsg); log.debug("[PubMessage] -> Process qos1 message,clientId={}",innerMsg.getClientId()); MqttPubAckMessage pubAckMessage = MessageUtil.getPubAckMessage(innerMsg.getMsgId()); ctx.writeAndFlush(pubAckMessage); }
Example #12
Source File: MqttTransportHandler.java From iotplatform with Apache License 2.0 | 4 votes |
public static MqttPubAckMessage createMqttPubAckMsg(int requestId) { MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(PUBACK, false, AT_LEAST_ONCE, false, 0); MqttMessageIdVariableHeader mqttMsgIdVariableHeader = MqttMessageIdVariableHeader.from(requestId); return new MqttPubAckMessage(mqttFixedHeader, mqttMsgIdVariableHeader); }
Example #13
Source File: JsonMqttAdaptor.java From iotplatform with Apache License 2.0 | 4 votes |
private static MqttPubAckMessage createMqttPubAckMsg(int requestId) { MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(PUBACK, false, AT_LEAST_ONCE, false, 0); MqttMessageIdVariableHeader mqttMsgIdVariableHeader = MqttMessageIdVariableHeader.from(requestId); return new MqttPubAckMessage(mqttFixedHeader, mqttMsgIdVariableHeader); }
Example #14
Source File: MQTTProtocolHandler.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { try { if (stopped) { disconnect(true); return; } MqttMessage message = (MqttMessage) msg; // Disconnect if Netty codec failed to decode the stream. if (message.decoderResult().isFailure()) { log.debug("Bad Message Disconnecting Client."); disconnect(true); return; } connection.dataReceived(); if (AuditLogger.isAnyLoggingEnabled()) { AuditLogger.setRemoteAddress(connection.getRemoteAddress()); } MQTTUtil.logMessage(session.getState(), message, true); if (this.protocolManager.invokeIncoming(message, this.connection) != null) { log.debugf("Interceptor rejected MQTT message: %s", message); disconnect(true); return; } switch (message.fixedHeader().messageType()) { case CONNECT: handleConnect((MqttConnectMessage) message, ctx); break; case PUBLISH: handlePublish((MqttPublishMessage) message); break; case PUBACK: handlePuback((MqttPubAckMessage) message); break; case PUBREC: handlePubrec(message); break; case PUBREL: handlePubrel(message); break; case PUBCOMP: handlePubcomp(message); break; case SUBSCRIBE: handleSubscribe((MqttSubscribeMessage) message); break; case UNSUBSCRIBE: handleUnsubscribe((MqttUnsubscribeMessage) message); break; case PINGREQ: handlePingreq(); break; case DISCONNECT: disconnect(false); break; case UNSUBACK: case SUBACK: case PINGRESP: case CONNACK: // The server does not instantiate connections therefore any CONNACK received over a connection is an invalid control message. default: disconnect(true); } } catch (Exception e) { log.debug("Error processing Control Packet, Disconnecting Client", e); disconnect(true); } finally { ReferenceCountUtil.release(msg); } }
Example #15
Source File: MQTTProtocolHandler.java From activemq-artemis with Apache License 2.0 | 4 votes |
void handlePuback(MqttPubAckMessage message) throws Exception { session.getMqttPublishManager().handlePubAck(getMessageId(message)); }