• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java MqttConnectPayload类的典型用法和代码示例

java 1次浏览

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

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

示例1: connect

点赞 3

import io.netty.handler.codec.mqtt.MqttConnectPayload; //导入依赖的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

点赞 3

import io.netty.handler.codec.mqtt.MqttConnectPayload; //导入依赖的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: channelRead

点赞 2

import io.netty.handler.codec.mqtt.MqttConnectPayload; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof MqttMessage) {
        MqttMessage mqtt = (MqttMessage) msg;
        if (StringUtils.isBlank(this.clientId) && mqtt.fixedHeader().messageType() == MqttMessageType.CONNECT) {
            this.clientId = ((MqttConnectPayload) mqtt.payload()).clientId();
        }
        if (StringUtils.isNotBlank(this.clientId)) {
            this.metrics.measurement(this.clientId, this.brokerId, MessageDirection.IN, mqtt.fixedHeader().messageType());
        }
        this.metrics.measurement(this.brokerId, MessageDirection.IN, mqtt.fixedHeader().messageType());
    }
    ctx.fireChannelRead(msg);
}
 

开发者ID:12315jack,
项目名称:j1st-mqtt,
代码行数:15,
代码来源:MessageMetricsHandler.java

示例4: createConnectPacket

点赞 2

import io.netty.handler.codec.mqtt.MqttConnectPayload; //导入依赖的package包/类
private MqttMessage createConnectPacket(MqttClientOptions options) {
  MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT,
    false,
    MqttQoS.AT_MOST_ONCE,
    false,
    0);

  MqttConnectVariableHeader variableHeader = new MqttConnectVariableHeader(
    PROTOCOL_NAME,
    PROTOCOL_VERSION,
    options.hasUsername(),
    options.hasPassword(),
    options.isWillRetain(),
    options.getWillQoS(),
    options.isWillFlag(),
    options.isCleanSession(),
    options.getKeepAliveTimeSeconds()
  );

  MqttConnectPayload payload = new MqttConnectPayload(
    options.getClientId() == null ? "" : options.getClientId(),
    options.getWillTopic(),
    options.getWillMessage() != null ? options.getWillMessage().getBytes(StandardCharsets.UTF_8) : null,
    options.hasUsername() ? options.getUsername() : null,
    options.hasPassword() ? options.getPassword().getBytes(StandardCharsets.UTF_8) : null
  );

  return MqttMessageFactory.newMessage(fixedHeader, variableHeader, payload);
}
 

开发者ID:vert-x3,
项目名称:vertx-mqtt,
代码行数:30,
代码来源:MqttServerBadClientTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)