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


Java QoS.AT_MOST_ONCE属性代码示例

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


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

示例1: getQoS

static QoS getQoS(String qualityOfService) {
    for (QoS q : QoS.values()) {
        if (q.name().equalsIgnoreCase(qualityOfService)) {
            return q;
        }
    }
    if (qualityOfService.equalsIgnoreCase("ATMOSTONCE")) {
        return QoS.AT_MOST_ONCE;
    }
    if (qualityOfService.equalsIgnoreCase("EXACTLYONCE")) {
        return QoS.EXACTLY_ONCE;
    }
    if (qualityOfService.equalsIgnoreCase("ATLEASTONCE")) {
        return QoS.AT_LEAST_ONCE;
    }
    throw new IllegalArgumentException("There is no QoS with name " + qualityOfService);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:MQTTConfiguration.java

示例2: testConsumeMultipleTopics

@Test
public void testConsumeMultipleTopics() throws Exception {
    MQTT mqtt = new MQTT();
    BlockingConnection publisherConnection = mqtt.blockingConnection();
    Topic topic1 = new Topic(TEST_TOPIC, QoS.AT_MOST_ONCE);
    Topic topic2 = new Topic(TEST_TOPIC_2, QoS.AT_MOST_ONCE);
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(numberOfMessages * 2);

    publisherConnection.connect();
    String payload;
    for (int i = 0; i < numberOfMessages; i++) {
        payload = "Topic 1, Message " + i;
        publisherConnection.publish(topic1.name().toString(), payload.getBytes(), QoS.AT_LEAST_ONCE, false);
        payload = "Topic 2, Message " + i;
        publisherConnection.publish(topic2.name().toString(), payload.getBytes(), QoS.AT_LEAST_ONCE, false);
    }

    mock.await(5, TimeUnit.SECONDS);
    mock.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:MQTTConsumerMultipleTopicsTest.java

示例3: testConsume

@Test
public void testConsume() throws Exception {
    MQTT mqtt = new MQTT();
    BlockingConnection publisherConnection = mqtt.blockingConnection();
    Topic topic = new Topic(TEST_TOPIC, QoS.AT_MOST_ONCE);
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(numberOfMessages);

    publisherConnection.connect();
    for (int i = 0; i < numberOfMessages; i++) {
        String payload = "Message " + i;
        publisherConnection.publish(topic.name().toString(), payload.getBytes(), QoS.AT_LEAST_ONCE, false);
    }

    mock.await(5, TimeUnit.SECONDS);
    mock.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:MQTTConsumerTest.java

示例4: run

@Override
public void run()
{
  try {
    int i = 0;
    Topic[] topics = new Topic[sendingData.size()];
    for (String key : sendingData.keySet()) {
      topics[i++] = new Topic(key, QoS.AT_MOST_ONCE);
    }
    connection.subscribe(topics);
    while (receivedData.size() < sendingData.size()) {
      Message msg = connection.receive();
      receivedData.put(msg.getTopic(), new String(msg.getPayload()));
    }
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:18,代码来源:MqttOutputOperatorTest.java

示例5: callBroker

private static void callBroker(String truststorePath, String truststorePass, String keystorePath, String keystorePass) throws Exception {
   BlockingConnection connection = null;

   try {
      connection = retrieveMQTTConnection("ssl://localhost:1883", truststorePath, truststorePass, keystorePath, keystorePass);
      // Subscribe to topics
      Topic[] topics = {new Topic("test/+/some/#", QoS.AT_MOST_ONCE)};
      connection.subscribe(topics);

      // Publish Messages
      String payload = "This is message 1";

      connection.publish("test/1/some/la", payload.getBytes(), QoS.AT_LEAST_ONCE, false);

      Message message = connection.receive(5, TimeUnit.SECONDS);
      System.out.println("Message received: " + new String(message.getPayload()));

   } catch (Exception e) {
      throw e;
   } finally {
      if (connection != null) {
         connection.disconnect();
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:25,代码来源:MqttCrlEnabledExample.java

示例6: subscribe

/** {@inheritDoc} */
@Override
public void subscribe(final String channel, final MessageListener callback) {
	if (this.connection != null) {
		if (this.channels.containsKey(channel)) {
			return;
		}
		final CountDownLatch l = new CountDownLatch(1);
		final Topic[] topic = { new Topic(channel, QoS.AT_MOST_ONCE) };
		this.connection.subscribe(topic, new Callback<byte[]>() {
			@Override
			public void onFailure(final Throwable throwable) {
				System.out.println("Impossible to SUBSCRIBE to channel \"" + channel + "\"");
				logTracker.log("Impossible to SUBSCRIBE to channel \"" + channel + "\"");
				l.countDown();
			}

			@Override
			public void onSuccess(final byte[] bytes) {
				KuraMQTTClient.this.channels.put(channel, callback);
				l.countDown();
				logTracker.log("Successfully subscribed to " + channel);
				System.out.println("Successfully subscribed to " + channel);
			}
		});
		try {
			l.await();
		} catch (final InterruptedException e) {
			System.out.println("Impossible to SUBSCRIBE to channel \"" + channel + "\"");
			logTracker.log("Impossible to SUBSCRIBE to channel \"" + channel + "\"");
		}
	}
}
 
开发者ID:amitjoy,项目名称:Kura-MQTT-Client-Utility,代码行数:33,代码来源:KuraMQTTClient.java

示例7: testProduce

@Test
public void testProduce() throws Exception {
    MQTT mqtt = new MQTT();
    final BlockingConnection subscribeConnection = mqtt.blockingConnection();
    subscribeConnection.connect();
    Topic topic = new Topic(TEST_TOPIC, QoS.AT_MOST_ONCE);
    Topic[] topics = {topic};
    subscribeConnection.subscribe(topics);
    final CountDownLatch latch = new CountDownLatch(numberOfMessages);

    Thread thread = new Thread(new Runnable() {
        public void run() {
            for (int i = 0; i < numberOfMessages; i++) {
                try {
                    Message message = subscribeConnection.receive();
                    message.ack();
                    latch.countDown();
                } catch (Exception e) {
                    e.printStackTrace();
                    break;
                }
            }
        }
    });
    thread.start();

    Producer producer = context.getEndpoint("direct:foo").createProducer();
    for (int i = 0; i < numberOfMessages; i++) {
        Exchange exchange = producer.createExchange();
        exchange.getIn().setBody("test message " + i);
        producer.process(exchange);
    }
    latch.await(20, TimeUnit.SECONDS);
    assertTrue("Messages not consumed = " + latch.getCount(), latch.getCount() == 0);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:35,代码来源:MQTTProducerTest.java

示例8: main

public static void main(final String[] args) throws Exception {
   // Create a new MQTT connection to the broker.  We are not setting the client ID.  The broker will pick one for us.
   System.out.println("Connecting to Artemis using MQTT");
   BlockingConnection connection1 = retrieveMQTTConnection("tcp://localhost:1883");
   System.out.println("Connected to Artemis 1");
   BlockingConnection connection2 = retrieveMQTTConnection("tcp://localhost:1884");
   System.out.println("Connected to Artemis 2");

   // Subscribe to topics
   Topic[] topics = {new Topic("test/+/some/#", QoS.AT_MOST_ONCE)};
   connection1.subscribe(topics);
   connection2.subscribe(topics);
   System.out.println("Subscribed to topics.");

   // Publish Messages
   String payload1 = "This is message 1";
   String payload2 = "This is message 2";
   String payload3 = "This is message 3";

   connection1.publish("test/1/some/la", payload1.getBytes(), QoS.AT_LEAST_ONCE, false);
   connection1.publish("test/1/some/la", payload2.getBytes(), QoS.AT_MOST_ONCE, false);
   connection1.publish("test/1/some/la", payload3.getBytes(), QoS.AT_MOST_ONCE, false);
   System.out.println("Sent messages.");

   Message message1 = connection1.receive(5, TimeUnit.SECONDS);
   Message message2 = connection1.receive(5, TimeUnit.SECONDS);
   Message message3 = connection1.receive(5, TimeUnit.SECONDS);
   Message message4 = connection2.receive(5, TimeUnit.SECONDS);
   Message message5 = connection2.receive(5, TimeUnit.SECONDS);
   Message message6 = connection2.receive(5, TimeUnit.SECONDS);
   System.out.println("Received messages.");

   System.out.println("Broker 1: " + new String(message1.getPayload()));
   System.out.println("Broker 1: " + new String(message2.getPayload()));
   System.out.println("Broker 1: " + new String(message3.getPayload()));
   System.out.println("Broker 2: " + new String(message4.getPayload()));
   System.out.println("Broker 2: " + new String(message5.getPayload()));
   System.out.println("Broker 2: " + new String(message6.getPayload()));
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:39,代码来源:ClusteredQueueMQTTExample.java

示例9: crlNotRevokedTest

@Test
public void crlNotRevokedTest() throws Exception {

   ActiveMQServer server1 = initServer();
   BlockingConnection connection1 = null;
   try {
      server1.start();

      while (!server1.isStarted()) {
         Thread.sleep(50);
      }

      connection1 = retrieveMQTTConnection("ssl://localhost:1883", "truststore.jks", "changeit", "client_not_revoked.jks", "changeit");

      // Subscribe to topics
      Topic[] topics = {new Topic("test/+/some/#", QoS.AT_MOST_ONCE)};
      connection1.subscribe(topics);

      // Publish Messages
      String payload1 = "This is message 1";

      connection1.publish("test/1/some/la", payload1.getBytes(), QoS.AT_LEAST_ONCE, false);

      Message message1 = connection1.receive(5, TimeUnit.SECONDS);

      assertEquals(payload1, new String(message1.getPayload()));

   } finally {
      if (connection1 != null) {
         connection1.disconnect();
      }
      if (server1.isStarted()) {
         server1.stop();
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:36,代码来源:MQTTSecurityCRLTest.java

示例10: testMQTTConsumer

@Test
public void testMQTTConsumer() throws Exception {

    String conUrl = TestUtils.getResourceValue(getClass(), "/tcp-connection");

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("mqtt:bar?subscribeTopicName=" + BrokerSetup.TEST_TOPIC + "&host=" + conUrl).
            transform(body().prepend("Hello ")).to("seda:end");
        }
    });

    camelctx.start();

    PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    consumer.start();

    try {
        MQTT mqtt = new MQTT();
        mqtt.setHost(conUrl);
        BlockingConnection connection = mqtt.blockingConnection();
        Topic topic = new Topic(BrokerSetup.TEST_TOPIC, QoS.AT_MOST_ONCE);

        connection.connect();
        try {
            connection.publish(topic.name().toString(), "Kermit".getBytes(), QoS.AT_LEAST_ONCE, false);
        } finally {
            connection.disconnect();
        }

        String result = consumer.receive(3000).getIn().getBody(String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:38,代码来源:MQTTIntegrationTest.java

示例11: testMQTTProducer

@Test
public void testMQTTProducer() throws Exception {

    String conUrl = TestUtils.getResourceValue(getClass(), "/tcp-connection");

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").
            transform(body().prepend("Hello ")).
            to("mqtt:foo?publishTopicName=" + BrokerSetup.TEST_TOPIC + "&host=" + conUrl);
        }
    });

    camelctx.start();
    try {
        MQTT mqtt = new MQTT();
        mqtt.setHost(conUrl);
        BlockingConnection connection = mqtt.blockingConnection();

        connection.connect();
        try {
            Topic topic = new Topic(BrokerSetup.TEST_TOPIC, QoS.AT_MOST_ONCE);
            connection.subscribe(new Topic[] { topic });

            ProducerTemplate producer = camelctx.createProducerTemplate();
            producer.asyncSendBody("direct:start", "Kermit");

            Message message = connection.receive(10, TimeUnit.SECONDS);
            message.ack();

            String result = new String(message.getPayload());
            Assert.assertEquals("Hello Kermit", result);
        } finally {
            connection.disconnect();
        }
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:41,代码来源:MQTTIntegrationTest.java


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