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


Java MQTT.setTracer方法代码示例

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


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

示例1: createMQTTSslConnection

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
private MQTT createMQTTSslConnection(String clientId, boolean clean) throws Exception {
   MQTT mqtt = new MQTT();
   mqtt.setConnectAttemptsMax(1);
   mqtt.setReconnectAttemptsMax(0);
   mqtt.setTracer(createTracer());
   mqtt.setHost("ssl://localhost:" + port);
   if (clientId != null) {
      mqtt.setClientId(clientId);
   }
   mqtt.setCleanSession(clean);

   SSLContext ctx = SSLContext.getInstance("TLS");
   ctx.init(new KeyManager[0], new TrustManager[]{new DefaultTrustManager()}, new SecureRandom());
   mqtt.setSslContext(ctx);
   return mqtt;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:17,代码来源:MQTTTestSupport.java

示例2: createMQTTTcpConnection

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
private MQTT createMQTTTcpConnection(String clientId, boolean clean) throws Exception {
   MQTT mqtt = new MQTT();
   mqtt.setConnectAttemptsMax(1);
   mqtt.setReconnectAttemptsMax(0);
   mqtt.setTracer(createTracer());
   mqtt.setVersion("3.1.1");
   if (clientId != null) {
      mqtt.setClientId(clientId);
   }
   mqtt.setCleanSession(clean);
   mqtt.setHost("localhost", port);
   return mqtt;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:14,代码来源:MQTTTestSupport.java

示例3: createMQTTTcpConnection

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
private MQTT createMQTTTcpConnection(String clientId, boolean clean, int port) throws Exception {
   MQTT mqtt = new MQTT();
   mqtt.setConnectAttemptsMax(1);
   mqtt.setReconnectAttemptsMax(0);
   mqtt.setTracer(createTracer());
   if (clientId != null) {
      mqtt.setClientId(clientId);
   }
   mqtt.setCleanSession(clean);
   mqtt.setHost("localhost", port);
   return mqtt;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:MQTTNetworkOfBrokersFailoverTest.java

示例4: testMQTTRetainQoS

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Test(timeout = 60 * 1000)
public void testMQTTRetainQoS() throws Exception {
   String[] topics = {"AT_MOST_ONCE", "AT_LEAST_ONCE", "EXACTLY_ONCE"};
   for (int i = 0; i < topics.length; i++) {
      final String topic = topics[i];

      MQTT mqtt = createMQTTConnection();
      mqtt.setClientId("foo");
      mqtt.setKeepAlive((short) 2);

      final int[] actualQoS = {-1};
      mqtt.setTracer(new Tracer() {
         @Override
         public void onReceive(MQTTFrame frame) {
            // validate the QoS
            if (frame.messageType() == PUBLISH.TYPE) {
               actualQoS[0] = frame.qos().ordinal();
            }
         }
      });

      final BlockingConnection connection = mqtt.blockingConnection();
      connection.connect();
      connection.publish(topic, topic.getBytes(), QoS.EXACTLY_ONCE, true);
      connection.subscribe(new Topic[]{new Topic(topic, QoS.valueOf(topic))});

      final Message msg = connection.receive(5000, TimeUnit.MILLISECONDS);
      assertNotNull(msg);
      assertEquals(topic, new String(msg.getPayload()));
      int waitCount = 0;
      while (actualQoS[0] == -1 && waitCount < 10) {
         Thread.sleep(1000);
         waitCount++;
      }
      assertEquals(i, actualQoS[0]);
      msg.ack();

      connection.unsubscribe(new String[]{topic});
      connection.disconnect();
   }

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:43,代码来源:MQTTTest.java


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