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


Java QoS.EXACTLY_ONCE属性代码示例

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


在下文中一共展示了QoS.EXACTLY_ONCE属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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");
   MQTT mqtt = new MQTT();
   mqtt.setHost("tcp://localhost:1883");
   BlockingConnection connection = mqtt.blockingConnection();
   connection.connect();
   System.out.println("Connected to Artemis");

   // Subscribe to topics
   Topic[] topics = {new Topic("mqtt/example/publish", QoS.AT_LEAST_ONCE), new Topic("test/#", QoS.EXACTLY_ONCE), new Topic("foo/+/bar", QoS.AT_LEAST_ONCE)};
   connection.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";

   connection.publish("mqtt/example/publish", payload1.getBytes(), QoS.AT_LEAST_ONCE, false);
   connection.publish("test/test", payload2.getBytes(), QoS.AT_MOST_ONCE, false);
   connection.publish("foo/1/bar", payload3.getBytes(), QoS.AT_MOST_ONCE, false);
   System.out.println("Sent messages.");

   Message message1 = connection.receive(5, TimeUnit.SECONDS);
   Message message2 = connection.receive(5, TimeUnit.SECONDS);
   Message message3 = connection.receive(5, TimeUnit.SECONDS);
   System.out.println("Received messages.");

   System.out.println(new String(message1.getPayload()));
   System.out.println(new String(message2.getPayload()));
   System.out.println(new String(message3.getPayload()));
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:33,代码来源:MQTTBasicPubSubExample.java

示例3: testSubscribeMultipleTopics

@Test(timeout = 30 * 10000)
public void testSubscribeMultipleTopics() throws Exception {

   byte[] payload = new byte[1024 * 32];
   for (int i = 0; i < payload.length; i++) {
      payload[i] = '2';
   }

   MQTT mqtt = createMQTTConnection();
   mqtt.setClientId("MQTT-Client");
   mqtt.setCleanSession(false);

   final BlockingConnection connection = mqtt.blockingConnection();
   connection.connect();

   Topic[] topics = {new Topic("Topic/A", QoS.EXACTLY_ONCE), new Topic("Topic/B", QoS.EXACTLY_ONCE)};
   Topic[] wildcardTopic = {new Topic("Topic/#", QoS.AT_LEAST_ONCE)};
   connection.subscribe(wildcardTopic);

   for (Topic topic : topics) {
      connection.publish(topic.name().toString(), payload, QoS.AT_LEAST_ONCE, false);
   }

   int received = 0;
   for (int i = 0; i < topics.length; ++i) {
      Message message = connection.receive();
      assertNotNull(message);
      received++;
      payload = message.getPayload();
      String messageContent = new String(payload);
      LOG.info("Received message from topic: " + message.getTopic() + " Message content: " + messageContent);
      message.ack();
   }

   assertEquals("Should have received " + topics.length + " messages", topics.length, received);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:36,代码来源:MQTTTest.java

示例4: main

public static void main(final String[] args) throws Exception {

      System.out.println("Connecting to Artemis using MQTT");
      MQTT mqtt = new MQTT();
      mqtt.setHost("tcp://localhost:1883");

      BlockingConnection connection = mqtt.blockingConnection();
      connection.connect();

      System.out.println("Connected to Artemis");

      // Subscribe to a topic
      Topic[] topics = {new Topic("mqtt/example/interceptor", QoS.EXACTLY_ONCE)};
      connection.subscribe(topics);
      System.out.println("Subscribed to topics.");

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

      connection.publish("mqtt/example/interceptor", payload1.getBytes(), QoS.EXACTLY_ONCE, false);

      System.out.println("Sent message");

      // Receive the sent message
      Message message1 = connection.receive(5, TimeUnit.SECONDS);

      String messagePayload = new String(message1.getPayload(), StandardCharsets.UTF_8);

      System.out.println("Received message: " + messagePayload);
   }
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:30,代码来源:InterceptorExample.java


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