本文整理汇总了Java中io.netty.handler.codec.mqtt.MqttMessage.toString方法的典型用法代码示例。如果您正苦于以下问题:Java MqttMessage.toString方法的具体用法?Java MqttMessage.toString怎么用?Java MqttMessage.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.handler.codec.mqtt.MqttMessage
的用法示例。
在下文中一共展示了MqttMessage.toString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import io.netty.handler.codec.mqtt.MqttMessage; //导入方法依赖的package包/类
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);
});
}
示例2: send
import io.netty.handler.codec.mqtt.MqttMessage; //导入方法依赖的package包/类
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);
}
}