Java Code Examples for io.netty.handler.codec.mqtt.MqttMessage#toString()
The following examples show how to use
io.netty.handler.codec.mqtt.MqttMessage#toString() .
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: PubRelReceiver.java From lannister with Apache License 2.0 | 6 votes |
protected void handle(ChannelHandlerContext ctx, Session session, int messageId) { // TODO what if the PUBREL is resented one? Topic topic = Topic.NEXUS.get(session.clientId(), messageId, ClientType.PUBLISHER); if (topic == null) { logger.error("PUBREL target does not exist [clientId={}, messageId={}]", session.clientId(), messageId); session.dispose(true); // [MQTT-3.3.5-2] return; } MqttMessage toSend = MqttMessageFactory.pubcomp(messageId); final String log = toSend.toString(); session.send(toSend, f -> { if (!f.isSuccess()) { logger.error("packet outgoing failed [{}] {}", log, f.cause()); return; } InboundMessageStatus.NEXUS.removeByKey(messageId, session.clientId()); logger.debug("Inbound message status REMOVED [clientId={}, messageId={}]", session.clientId(), messageId); }); }
Example 2
Source File: MessageSender.java From lannister with Apache License 2.0 | 6 votes |
protected void send(MqttMessage message, GenericFutureListener<? extends Future<? super Void>> completeListener) { if (!session.isConnected(true)) { logger.error("Message is not sent - Channel is inactive or out of the node. [{}]", message); return; } ChannelHandlerContext ctx = Session.NEXUS.channelHandlerContext(session.clientId()); String log = message.toString(); ChannelFuture cf = ctx.writeAndFlush(message).addListener(f -> { if (f.isSuccess()) { logger.debug("packet outgoing [{}]", log); } else { logger.error("packet outgoing failed [{}] {}", log, f.cause()); } }); if (completeListener != null) { cf.addListener(completeListener); } }
Example 3
Source File: PublishReceiver.java From lannister with Apache License 2.0 | 4 votes |
@Override protected void channelRead0(ChannelHandlerContext ctx, MqttPublishMessage msg) throws Exception { logger.debug("packet incoming [message={}]", msg.toString()); Statistics.INSTANCE.add(Statistics.Criterion.MESSAGES_PUBLISH_RECEIVED, 1); 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()); if (!TopicMatcher.isValid(msg.variableHeader().topicName(), false)) { session.dispose(true); return; } Message message = Message.newMessage(session.clientId(), msg); if (!Plugins.INSTANCE.get(PublishEventListener.class).allowPublish(new PublishEventArgs() { @Override public IMessage message() { return message; } })) { session.dispose(true); return; } // TODO What to do when sender re-publish message corrensponds to // unacked status? // TODO Until it has received the corresponding PUBREL packet, the // Receiver MUST acknowledge any subsequent PUBLISH packet with the same // Packet Identifier by sending a PUBREC. It MUST NOT cause duplicate // messages to be delivered to any onward recipients in this // case.[MQTT-4.3.3-2]. final Topic topic = Topic.NEXUS.prepare(message); if (message.isRetain()) {// else do nothing [MQTT-3.3.1-12] topic.setRetainedMessage(message); // [MQTT-3.3.1-5] } message.setRetain(false); topic.publish(message); MqttMessage toSend; final String log; switch (msg.fixedHeader().qosLevel()) { case AT_MOST_ONCE: return; // QoS 0 do not send any acknowledge packet [MQTT-3.3.4-1] case AT_LEAST_ONCE: toSend = MqttMessageFactory.puback(msg.variableHeader().messageId()); log = toSend.toString(); session.send(toSend, f -> { if (!f.isSuccess()) { logger.error("packet outgoing failed [{}] {}", log, f.cause()); return; } InboundMessageStatus.NEXUS.removeByKey(msg.variableHeader().messageId(), session.clientId()); }); // [MQTT-3.3.4-1],[MQTT-2.3.1-6] logger.debug("Inbound message status REMOVED [clientId={}, messageId={}]", session.clientId(), msg.variableHeader().messageId()); return; case EXACTLY_ONCE: toSend = MqttMessageFactory.pubrec(msg.variableHeader().messageId()); log = toSend.toString(); session.send(MqttMessageFactory.pubrec(msg.variableHeader().messageId()), f -> { if (!f.isSuccess()) { logger.error("packet outgoing failed [{}] {}", log, f.cause()); return; } InboundMessageStatus.NEXUS.update(msg.variableHeader().messageId(), session.clientId(), InboundMessageStatus.Status.PUBRECED); }); // [MQTT-3.3.4-1],[MQTT-2.3.1-6] return; default: session.dispose(true); // [MQTT-3.3.1-4] return; } }