当前位置: 首页>>代码示例>>Java>>正文


Java MqttFixedHeader类代码示例

本文整理汇总了Java中io.netty.handler.codec.mqtt.MqttFixedHeader的典型用法代码示例。如果您正苦于以下问题:Java MqttFixedHeader类的具体用法?Java MqttFixedHeader怎么用?Java MqttFixedHeader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MqttFixedHeader类属于io.netty.handler.codec.mqtt包,在下文中一共展示了MqttFixedHeader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connect

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
public static MqttConnectMessage connect(ConnectOptions options) {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false,
			10);
	MqttConnectVariableHeader variableHeader = new MqttConnectVariableHeader(options.version().protocolName(),
			options.version().protocolLevel(), options.userName() != null, options.password() != null,
			options.will() == null ? false : options.will().isRetain(),
			options.will() == null ? 0 : options.will().qos().value(), options.will() != null,
			options.cleanSession(), options.keepAliveTimeSeconds());

	MqttConnectPayload payload = new MqttConnectPayload(Strings.nullToEmpty(options.clientId()),
			options.will() == null ? "" : options.will().topicName(),
			options.will() == null ? "" : new String(options.will().message(), CharsetUtil.UTF_8),
			Strings.nullToEmpty(options.userName()), Strings.nullToEmpty(options.password()));

	return new MqttConnectMessage(fixedHeader, variableHeader, payload);
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:17,代码来源:MqttMessageFactory.java

示例2: executeNormalChannelRead0

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
private MqttConnAckMessage executeNormalChannelRead0(String clientId, boolean cleanSession, ChannelId channelId)
		throws Exception {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false,
			10);
	MqttConnectVariableHeader variableHeader = new MqttConnectVariableHeader("MQTT", 4, true, true, true, 0, true,
			cleanSession, 60);
	MqttConnectPayload payload = new MqttConnectPayload(clientId, "willtopic", "willmessage", "username",
			"password");

	MqttConnectMessage msg = new MqttConnectMessage(fixedHeader, variableHeader, payload);

	ChannelId cid = channelId == null ? TestUtil.newChannelId(clientId, false) : channelId;

	EmbeddedChannel channel = new EmbeddedChannel(cid, new ConnectReceiver());

	channel.writeInbound(msg);

	return channel.readOutbound();
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:20,代码来源:ConnectReceiverTest.java

示例3: sendPubAck

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
private void sendPubAck(String clientId, int messageID) {
    LOG.trace("sendPubAck invoked");
    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBACK, false, AT_MOST_ONCE, false, 0);
    MqttPubAckMessage pubAckMessage = new MqttPubAckMessage(fixedHeader, from(messageID));

    try {
        if (connectionDescriptors == null) {
            throw new RuntimeException("Internal bad error, found connectionDescriptors to null while it should " +
                "be initialized, somewhere it's overwritten!!");
        }
        LOG.trace("connected clientIDs are {}", connectionDescriptors.getConnectedClientIds());
        if (!connectionDescriptors.isConnected(clientId)) {
            throw new RuntimeException(String.format("Can't find a ConnectionDescriptor for client %s in cache %s",
                clientId, connectionDescriptors));
        }
        connectionDescriptors.sendMessage(pubAckMessage, messageID, clientId);
    } catch (Throwable t) {
        LOG.error(null, t);
    }
}
 
开发者ID:andsel,项目名称:moquette,代码行数:21,代码来源:Qos1PublishHandler.java

示例4: channelRead

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
  log.info("[{}] Processing msg: {}", sessionId, msg);
  if (msg instanceof MqttMessage) {
    MqttMessage mqttMessage = (MqttMessage) msg;
    MqttFixedHeader fixedHeader = mqttMessage.fixedHeader();
    if (fixedHeader != null) {
      processMqttMsg(ctx, (MqttMessage) msg);
    } else {
      //xtx
    }
  }

}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:15,代码来源:MqttTransportHandler.java

示例5: processMqttMsg

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
private void processMqttMsg(ChannelHandlerContext ctx, MqttMessage msg) {
  // deviceSessionCtx.setChannel(ctx);
  // assetSessionCtx.setChannel(ctx);

  switch (msg.fixedHeader().messageType()) {
  case CONNECT:
    processConnect(ctx, (MqttConnectMessage) msg);
    break;
  case PUBLISH:
    processPublish(ctx, (MqttPublishMessage) msg);
    // System.out.println("write...");
    // ctx.write("just for test");
    break;
  case SUBSCRIBE:
    processSubscribe(ctx, (MqttSubscribeMessage) msg);
    break;
  case UNSUBSCRIBE:
    processUnsubscribe(ctx, (MqttUnsubscribeMessage) msg);
    break;
  case PINGREQ:
    if (checkConnected(ctx)) {
      ctx.writeAndFlush(new MqttMessage(new MqttFixedHeader(PINGRESP, false, AT_MOST_ONCE, false, 0)));
    }
    break;
  case DISCONNECT:
    if (checkConnected(ctx)) {
      processDisconnect(ctx);
    }
    break;
  }
}
 
开发者ID:osswangxining,项目名称:iothub,代码行数:32,代码来源:MqttTransportHandler.java

示例6: doMessage

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
public MqttMessage doMessage(Channel channel, MqttMessage msg) {
    String channelId = channel.id().asLongText();
    logger.debug("MQTT PINGREQ " + channelId);

    // 更新最新连接时间
    ApplicationContext.updateChannelConTime(channelId);

    MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttMessage message = new MqttMessage(fixedHeader);

    return message;
}
 
开发者ID:airballcz,项目名称:iot-platform,代码行数:13,代码来源:PingReqHandler.java

示例7: onMsg

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
@Override
public void onMsg(SessionCtrlMsg msg) throws SessionException {
  if (msg instanceof SessionCloseMsg) {
    pushToNetwork(
        new MqttMessage(new MqttFixedHeader(MqttMessageType.DISCONNECT, false, MqttQoS.AT_MOST_ONCE, false, 0)));
    channel.close();
  }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:9,代码来源:DeviceSessionCtx.java

示例8: createMqttPublishMsg

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
private MqttPublishMessage createMqttPublishMsg(DeviceSessionCtx ctx, String topic, JsonElement json) {
  MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, MqttQoS.AT_LEAST_ONCE, false,
      0);
  MqttPublishVariableHeader header = new MqttPublishVariableHeader(topic, ctx.nextMsgId());
  ByteBuf payload = ALLOCATOR.buffer();
  payload.writeBytes(GSON.toJson(json).getBytes(UTF8));
  return new MqttPublishMessage(mqttFixedHeader, header, payload);
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:9,代码来源:JsonMqttAdaptor.java

示例9: connack

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
public static MqttConnAckMessage connack(MqttConnectReturnCode returnCode, boolean sessionPresent) {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE, false,
			2);
	MqttConnAckVariableHeader variableHeader = new MqttConnAckVariableHeader(returnCode, sessionPresent);

	return new MqttConnAckMessage(fixedHeader, variableHeader);
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:8,代码来源:MqttMessageFactory.java

示例10: puback

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
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);
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:8,代码来源:MqttMessageFactory.java

示例11: pubrec

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
public static MqttMessage pubrec(int messageId) {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBREC, false, MqttQoS.AT_MOST_ONCE, false,
			2);
	MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);

	return new MqttMessage(fixedHeader, variableHeader);
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:8,代码来源:MqttMessageFactory.java

示例12: pubrel

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
public static MqttMessage pubrel(int messageId) {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBREL, false, MqttQoS.AT_LEAST_ONCE, false,
			2);
	MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);

	return new MqttMessage(fixedHeader, variableHeader);
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:8,代码来源:MqttMessageFactory.java

示例13: pubcomp

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
public static MqttMessage pubcomp(int messageId) {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBCOMP, false, MqttQoS.AT_MOST_ONCE, false,
			2);
	MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);

	return new MqttMessage(fixedHeader, variableHeader);
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:8,代码来源:MqttMessageFactory.java

示例14: subscribe

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
public static MqttSubscribeMessage subscribe(int messageId, MqttTopicSubscription... topicSubscriptions) {
	int topicNameSize = 0;
	int topicCount = topicSubscriptions.length;

	for (MqttTopicSubscription item : topicSubscriptions) {
		topicNameSize += item.topicName().getBytes(CharsetUtil.UTF_8).length;
	}

	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBSCRIBE, false, MqttQoS.AT_LEAST_ONCE,
			false, 2 + topicNameSize + topicCount);
	MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);
	MqttSubscribePayload payload = new MqttSubscribePayload(Lists.newArrayList(topicSubscriptions));

	return new MqttSubscribeMessage(fixedHeader, variableHeader, payload);
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:16,代码来源:MqttMessageFactory.java

示例15: suback

import io.netty.handler.codec.mqtt.MqttFixedHeader; //导入依赖的package包/类
public static MqttSubAckMessage suback(int messageId, List<Integer> grantedQoSLevels) {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false,
			2 + grantedQoSLevels.size());
	MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);
	MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels);

	return new MqttSubAckMessage(fixedHeader, variableHeader, payload);
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:9,代码来源:MqttMessageFactory.java


注:本文中的io.netty.handler.codec.mqtt.MqttFixedHeader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。