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


Java MqttQoS.EXACTLY_ONCE属性代码示例

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


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

示例1: testMatches

@Test
public void testMatches() throws Exception {
	String testTopic = "testTopic/test";
	Session session = new Session("1", "1", 1, 50, true, null);

	TopicSubscription ts0 = new TopicSubscription(session.clientId(), "testTopic/#", MqttQoS.AT_MOST_ONCE);
	TopicSubscription ts1 = new TopicSubscription(session.clientId(), "testTopic/+", MqttQoS.AT_LEAST_ONCE);
	TopicSubscription ts2 = new TopicSubscription(session.clientId(), testTopic, MqttQoS.EXACTLY_ONCE);

	TopicSubscription.NEXUS.put(ts0);
	TopicSubscription.NEXUS.put(ts1);
	TopicSubscription.NEXUS.put(ts2);

	Assert.assertEquals(3, TopicSubscription.NEXUS.topicFiltersOf(session.clientId()).size());

	TopicSubscription target = session.matches(testTopic);

	Assert.assertTrue(target.topicFilter().equals(testTopic));
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:19,代码来源:SessionTest.java

示例2: channelRead0

@Override
protected void channelRead0(ChannelHandlerContext ctx, MqttMessage msg) throws Exception {
	switch (msg.fixedHeader().messageType()) {
	case PUBLISH:
		if (receiver != null) {
			receiver.messageReceived(Message.newMessage(client.clientId(), (MqttPublishMessage) msg));
		}

		int messageId = ((MqttPublishMessage) msg).variableHeader().messageId();
		if (((MqttPublishMessage) msg).fixedHeader().qosLevel() == MqttQoS.AT_LEAST_ONCE) {
			client.send(MqttMessageFactory.puback(messageId));
		}
		else if (((MqttPublishMessage) msg).fixedHeader().qosLevel() == MqttQoS.EXACTLY_ONCE) {
			client.send(MqttMessageFactory.pubrec(messageId));
		}
		break;

	case CONNACK:
		sharedObject.receivedMessage(msg);

		synchronized (sharedObject.locker()) {
			sharedObject.locker().notify();
		}
		break;

	case PUBREC:
		client.send(MqttMessageFactory.pubrel(((MqttMessageIdVariableHeader) msg.variableHeader()).messageId()));
		break;

	case SUBACK:
	case PUBACK:
	case PUBCOMP:
	default:
		break;
	}
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:36,代码来源:MqttPacketReceiver.java

示例3: 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

    LOG.info("Will ready for publishing on topic [{}]", amqpPublishMessage.topic());

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

        ProtonSender sender = this.connection.createSender(amqpPublishMessage.topic());

        sender.setQoS(ProtonQoS.AT_LEAST_ONCE)
              .open();

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

            sender.send(amqpPublishMessage.toAmqp());
            sender.close();
            LOG.info("AMQP published on {}", amqpPublishMessage.topic());

            handler.handle(Future.succeededFuture(null));

        } else {

            sender.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())));
                }

                sender.close();
            });
        }

    // use sender for QoS 2 messages
    } else {

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

示例4: 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


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