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


Java MqttQoS.AT_MOST_ONCE属性代码示例

本文整理汇总了Java中io.netty.handler.codec.mqtt.MqttQoS.AT_MOST_ONCE属性的典型用法代码示例。如果您正苦于以下问题:Java MqttQoS.AT_MOST_ONCE属性的具体用法?Java MqttQoS.AT_MOST_ONCE怎么用?Java MqttQoS.AT_MOST_ONCE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在io.netty.handler.codec.mqtt.MqttQoS的用法示例。


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

示例1: connect

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,代码行数:16,代码来源:MqttMessageFactory.java

示例2: executeNormalChannelRead0

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,代码行数:19,代码来源:ConnectReceiverTest.java

示例3: put

public static void put(String topic, String payload, MqttQoS qoS) {
    if (qoS == MqttQoS.AT_MOST_ONCE) {
        // TODO: 2017/9/19 查找是否存在此主题,并从消息列表删除

    }

    Message message = new Message();
    message.setTopic(topic);
    message.setPayload(payload);
    message.setQoS(qoS);

    container.put(topic, message);
}
 
开发者ID:airballcz,项目名称:iot-platform,代码行数:13,代码来源:PublishContainer.java

示例4: doMessage

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,代码行数:12,代码来源:PingReqHandler.java

示例5: puback

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,代码行数:7,代码来源:MqttMessageFactory.java

示例6: pubrec

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,代码行数:7,代码来源:MqttMessageFactory.java

示例7: pubcomp

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,代码行数:7,代码来源:MqttMessageFactory.java

示例8: publishHandler

/**
 * Handler for incoming AMQP_PUBLISH message
 *
 * @param amqpPublishData   object with the AMQP_PUBLISH message
 */
private void publishHandler(AmqpPublishData amqpPublishData) {

    AmqpPublishMessage publish = amqpPublishData.amqpPublishMessage();

    // defensive ... check that current bridge has information about subscriptions and related granted QoS
    // see https://github.com/EnMasseProject/subserv/issues/8

    // try to get subscribed topic (that could have wildcards) that matches the publish topic
    String topic = (this.grantedQoSLevels.size() == 0) ? null :
            TopicMatcher.match(this.grantedQoSLevels.keySet().stream().collect(Collectors.toList()), publish.topic());

    if (topic != null) {

        // MQTT 3.1.1 spec :  The QoS of Payload Messages sent in response to a Subscription MUST be
        // the minimum of the QoS of the originally published message and the maximum QoS granted by the Server
        MqttQoS qos = (publish.qos().value() < this.grantedQoSLevels.get(topic).value()) ?
                publish.qos() :
                this.grantedQoSLevels.get(topic);

        this.mqttEndpoint.publish(publish.topic(), publish.payload(), qos, publish.isDup(), publish.isRetain());
        // the the message identifier assigned to the published message
        amqpPublishData.setMessageId(this.mqttEndpoint.lastMessageId());

        LOG.info("PUBLISH [{}] to MQTT client {}", this.mqttEndpoint.lastMessageId(), this.mqttEndpoint.clientIdentifier());

        // for QoS 0, message settled immediately
        if (qos == MqttQoS.AT_MOST_ONCE) {
            this.rcvEndpoint.settle(amqpPublishData.messageId());
        }

    } else {

        LOG.error("Published message : MQTT client {} is not subscribed to {} !!", this.mqttEndpoint.clientIdentifier(), publish.topic());
    }
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:40,代码来源:AmqpBridge.java

示例9: createConnectPacket

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,代码行数:29,代码来源:MqttServerBadClientTest.java

示例10: from

/**
 * Return an AMQP_WILL message from the raw AMQP one
 *
 * @param message   raw AMQP message
 * @return  AMQP_WILL message
 */
public static AmqpWillMessage from(Message message) {

    if (!message.getSubject().equals(AMQP_SUBJECT)) {
        throw new IllegalArgumentException(String.format("AMQP message subject is no s%", AMQP_SUBJECT));
    }

    MessageAnnotations messageAnnotations = message.getMessageAnnotations();
    if (messageAnnotations == null) {
        throw new IllegalArgumentException("AMQP message has no annotations");
    } else {

        boolean isRetain = false;
        if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_RETAIN_ANNOTATION))) {
            isRetain = (boolean) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_RETAIN_ANNOTATION));
        }

        MqttQoS qos;
        if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_QOS_ANNOTATION))) {
            int value = (int) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_QOS_ANNOTATION));
            qos = MqttQoS.valueOf(value);
        } else {

            if (message.getHeader() != null) {
                // if qos annotation isn't present, fallback to "durable" header field
                qos = ((message.getHeader().getDurable() == null) || !message.getHeader().getDurable())
                        ? MqttQoS.AT_MOST_ONCE : MqttQoS.AT_LEAST_ONCE;
            } else {
                qos = MqttQoS.AT_MOST_ONCE;
            }
        }

        String topic = message.getAddress();

        Section section = message.getBody();
        if ((section != null) && (section instanceof Data)) {

            Buffer payload = Buffer.buffer(((Data) section).getValue().getArray());
            return new AmqpWillMessage(isRetain, topic, qos, payload);

        } else {
            throw new IllegalArgumentException("AMQP message wrong body type");
        }
    }
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:50,代码来源:AmqpWillMessage.java

示例11: pingresp

public static MqttMessage pingresp() {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false,
			0);

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

示例12: from

/**
 * Return an AMQP_PUBLISH message from the raw AMQP one
 *
 * @param message   raw AMQP message
 * @return  AMQP_PUBLISH message
 */
public static AmqpPublishMessage from(Message message) {

    boolean isRetain = false;
    MqttQoS qos = MqttQoS.AT_MOST_ONCE;

    // raw AMQP messages published from native AMQP clients could not have annotations
    MessageAnnotations messageAnnotations = message.getMessageAnnotations();
    if (messageAnnotations == null) {

        if (message.getHeader() != null) {
            // if qos annotation isn't present, fallback to "durable" header field
            qos = ((message.getHeader().getDurable() == null) || !message.getHeader().getDurable())
                    ? MqttQoS.AT_MOST_ONCE : MqttQoS.AT_LEAST_ONCE;
        }

    } else {

        if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_RETAIN_ANNOTATION))) {
            isRetain = (boolean) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_RETAIN_ANNOTATION));
        }

        if (messageAnnotations.getValue().containsKey(Symbol.valueOf(AMQP_QOS_ANNOTATION))) {
            int value = (int) messageAnnotations.getValue().get(Symbol.valueOf(AMQP_QOS_ANNOTATION));
            qos = MqttQoS.valueOf(value);
        } else {

            if (message.getHeader() != null) {
                // if qos annotation isn't present, fallback to "durable" header field
                qos = ((message.getHeader().getDurable() == null) || !message.getHeader().getDurable())
                        ? MqttQoS.AT_MOST_ONCE : MqttQoS.AT_LEAST_ONCE;
            }
        }
    }

    boolean isDup = (message.getDeliveryCount() > 0);

    String topic = message.getAddress();

    // TODO: to remove
    // workaround for the Artemis broker which change the original "To" property
    // in the AMQP message when message-id is null
    ApplicationProperties applicationProperties = message.getApplicationProperties();
    if (applicationProperties != null) {

        Object amqOrigAddress = applicationProperties.getValue().get("_AMQ_ORIG_ADDRESS");
        topic = (amqOrigAddress != null) ? amqOrigAddress.toString() : topic;
    }

    Section section = message.getBody();
    if ((section != null) && (section instanceof Data)) {

        Buffer payload = Buffer.buffer(((Data) section).getValue().getArray());
        return new AmqpPublishMessage(message.getMessageId(), qos, isDup, isRetain, topic, payload);

    } else {
        throw new IllegalArgumentException("AMQP message wrong body type");
    }
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:64,代码来源:AmqpPublishMessage.java

示例13: publish

/**
 * Send the AMQP_PUBLISH to the attached topic/address
 *
 * @param amqpPublishMessage    AMQP_PUBLISH message
 */
public void publish(AmqpPublishMessage amqpPublishMessage, Handler<AsyncResult<ProtonDelivery>> handler) {

    // send AMQP_PUBLISH message

    AmqpPublisher publisher = this.publishers.get(amqpPublishMessage.topic());

    // use sender for QoS 0/1 messages
    if (amqpPublishMessage.qos() != MqttQoS.EXACTLY_ONCE) {

        // attach sender link on "topic" (if doesn't exist yet)
        if (!publisher.senderQoS01().isOpen()) {

            publisher.senderQoS01()
                    .setQoS(ProtonQoS.AT_LEAST_ONCE)
                    .open();

            // TODO: think about starting a timer for inactivity on this link for detaching ?
        }

        if (amqpPublishMessage.qos() == MqttQoS.AT_MOST_ONCE) {

            publisher.senderQoS01().send(amqpPublishMessage.toAmqp());
            handler.handle(Future.succeededFuture(null));

        } else {

            publisher.senderQoS01().send(amqpPublishMessage.toAmqp(), delivery -> {

                if (delivery.getRemoteState() == Accepted.getInstance()) {
                    LOG.info("AMQP publish delivery {}", delivery.getRemoteState());
                    handler.handle(Future.succeededFuture(delivery));
                } else {
                    handler.handle(Future.failedFuture(String.format("AMQP publish delivery %s", delivery.getRemoteState())));
                }
            });

        }

    // use sender for QoS 2 messages
    } else {

        // attach sender link on "topic" (if doesn't exist yet)
        if (!publisher.senderQoS2().isOpen()) {

            publisher.senderQoS2()
                    // TODO: Vert.x Proton doesn't support EXACTLY_ONCE
                    .open();

            // TODO: think about starting a timer for inactivity on this link for detaching ?
        }

        publisher.senderQoS2().send(amqpPublishMessage.toAmqp(), delivery -> {

            if (delivery.getRemoteState() == Accepted.getInstance()) {
                LOG.info("AMQP publish delivery {}", delivery.getRemoteState());

                // received disposition not settled, store for future settlement
                if (!delivery.remotelySettled()) {
                    this.deliveries.put(amqpPublishMessage.messageId(), delivery);
                }

                handler.handle(Future.succeededFuture(delivery));
            } else {
                handler.handle(Future.failedFuture(String.format("AMQP publish delivery %s", delivery.getRemoteState())));
            }
        });
    }

}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:74,代码来源:AmqpPublishEndpoint.java

示例14: disconnect

public static MqttMessage disconnect() {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.DISCONNECT, false, MqttQoS.AT_MOST_ONCE,
			false, 2);

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

示例15: subscribeAcknowledge

public MqttEndpointImpl subscribeAcknowledge(int subscribeMessageId, List<MqttQoS> grantedQoSLevels) {

    this.checkConnected();

    MqttFixedHeader fixedHeader =
      new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
    MqttMessageIdVariableHeader variableHeader =
      MqttMessageIdVariableHeader.from(subscribeMessageId);

    MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels.stream().mapToInt(MqttQoS::value).toArray());

    io.netty.handler.codec.mqtt.MqttMessage suback = MqttMessageFactory.newMessage(fixedHeader, variableHeader, payload);

    this.write(suback);

    return this;
  }
 
开发者ID:vert-x3,项目名称:vertx-mqtt,代码行数:17,代码来源:MqttEndpointImpl.java


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