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


Java MQTT.setConnectAttemptsMax方法代码示例

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


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

示例1: canDetectTheMQTTProtocol

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Test// (timeout=60 * 1000)
    public void canDetectTheMQTTProtocol() throws Exception {

        DetectingGateway gateway = createGateway();

        // Lets establish a connection....
        MQTT mqtt = new MQTT();
        mqtt.setHost("localhost", gateway.getBoundPort());
        mqtt.setClientId("myclientid");
//        mqtt.setVersion("3.1.1");
        mqtt.setUserName("broker0/chirino");
        mqtt.setConnectAttemptsMax(1);

        org.fusesource.mqtt.client.BlockingConnection connection = mqtt.blockingConnection();
        connection.connect();

        assertEquals(1, gateway.getSuccessfulConnectionAttempts());
        assertEquals(1, gateway.getConnectedClients().length);
        assertConnectedToBroker(0);
        connection.kill();
    }
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:22,代码来源:DetectingGatewayTest.java

示例2: testConnection

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Test(timeout = 30000)
public void testConnection() throws Exception {
   for (String version : Arrays.asList("3.1", "3.1.1")) {

      BlockingConnection connection = null;
      try {
         MQTT mqtt = createMQTTConnection("test-" + version, true);
         mqtt.setUserName(fullUser);
         mqtt.setPassword(fullPass);
         mqtt.setConnectAttemptsMax(1);
         mqtt.setVersion(version);
         connection = mqtt.blockingConnection();
         connection.connect();
         BlockingConnection finalConnection = connection;
         assertTrue("Should be connected", Wait.waitFor(() -> finalConnection.isConnected(), 5000, 100));
      } finally {
         if (connection != null && connection.isConnected()) connection.disconnect();
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:21,代码来源:MQTTSecurityTest.java

示例3: testConnectionWithNullPassword

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Test(timeout = 30000, expected = EOFException.class)
public void testConnectionWithNullPassword() throws Exception {
   for (String version : Arrays.asList("3.1", "3.1.1")) {

      BlockingConnection connection = null;
      try {
         MQTT mqtt = createMQTTConnection("test-" + version, true);
         mqtt.setUserName(fullUser);
         mqtt.setPassword((String) null);
         mqtt.setConnectAttemptsMax(1);
         mqtt.setVersion(version);
         connection = mqtt.blockingConnection();
         connection.connect();
         fail("Connect should fail");
      } finally {
         if (connection != null && connection.isConnected()) connection.disconnect();
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:20,代码来源:MQTTSecurityTest.java

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

示例5: testConnectWithLargePassword

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Test
public void testConnectWithLargePassword() throws Exception {
   for (String version : Arrays.asList("3.1", "3.1.1")) {
      String longString = new String(new char[65535]);

      BlockingConnection connection = null;
      try {
         MQTT mqtt = createMQTTConnection("test-" + version, true);
         mqtt.setUserName(longString);
         mqtt.setPassword(longString);
         mqtt.setConnectAttemptsMax(1);
         mqtt.setVersion(version);
         connection = mqtt.blockingConnection();
         connection.connect();
         BlockingConnection finalConnection = connection;
         assertTrue("Should be connected", Wait.waitFor(() -> finalConnection.isConnected(), 5000, 100));
      } finally {
         if (connection != null && connection.isConnected()) connection.disconnect();
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:22,代码来源:MQTTTest.java

示例6: setup

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Override
public void setup(OperatorContext context)
{
  try {
    client = new MQTT();
    if (mqttClientConfig.getClientId() != null) {
      client.setClientId(mqttClientConfig.getClientId());
    }
    client.setCleanSession(mqttClientConfig.isCleanSession());
    client.setConnectAttemptsMax(mqttClientConfig.getConnectAttemptsMax());
    client.setHost(mqttClientConfig.getHost(), mqttClientConfig.getPort());
    client.setKeepAlive(mqttClientConfig.getKeepAliveInterval());
    if (mqttClientConfig.getPassword() != null) {
      client.setPassword(mqttClientConfig.getPassword());
    }
    if (mqttClientConfig.getUserName() != null) {
      client.setUserName(mqttClientConfig.getUserName());
    }
    if (mqttClientConfig.getWillMessage() != null) {
      client.setWillMessage(mqttClientConfig.getWillMessage());
      client.setWillQos(mqttClientConfig.getWillQos());
      client.setWillRetain(mqttClientConfig.isWillRetain());
      client.setWillTopic(mqttClientConfig.getWillTopic());
    }
    connection = client.blockingConnection();
    connection.connect();
  } catch (Throwable t) {
    throw new RuntimeException(t);
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:31,代码来源:AbstractMqttOutputOperator.java

示例7: retrieveMQTTConnection

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
private static BlockingConnection retrieveMQTTConnection(String host, String truststorePath, String truststorePass, String keystorePath, String keystorePass) throws Exception {
   MQTT mqtt = new MQTT();
   mqtt.setConnectAttemptsMax(0);
   mqtt.setReconnectAttemptsMax(0);
   mqtt.setHost(host);
   mqtt.setSslContext(SSLSupport.createContext("JKS", keystorePath, keystorePass, "JKS", truststorePath, truststorePass));
   mqtt.setCleanSession(true);

   BlockingConnection connection = mqtt.blockingConnection();
   connection.connect();
   return connection;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:MqttCrlEnabledExample.java

示例8: retrieveMQTTConnection

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
private BlockingConnection retrieveMQTTConnection(String host, String truststorePath, String truststorePass, String keystorePath, String keystorePass) throws Exception {
   MQTT mqtt = new MQTT();
   mqtt.setConnectAttemptsMax(1);
   mqtt.setReconnectAttemptsMax(0);
   mqtt.setHost(host);
   SSLContext sslContext = SSLSupport.createContext(TransportConstants.DEFAULT_KEYSTORE_PROVIDER, keystorePath, keystorePass, TransportConstants.DEFAULT_TRUSTSTORE_PROVIDER, truststorePath, truststorePass);
   mqtt.setSslContext(sslContext);

   BlockingConnection connection = mqtt.blockingConnection();
   connection.connect();
   return connection;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:MQTTSecurityCRLTest.java

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

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

示例11: activate

import org.fusesource.mqtt.client.MQTT; //导入方法依赖的package包/类
@Override
public void activate(OperatorContext context)
{
  try {
    client = new MQTT();
    if (mqttClientConfig.getClientId() != null) {
      client.setClientId(mqttClientConfig.getClientId());
    }
    client.setCleanSession(mqttClientConfig.isCleanSession());
    client.setConnectAttemptsMax(mqttClientConfig.getConnectAttemptsMax());
    client.setHost(mqttClientConfig.getHost(), mqttClientConfig.getPort());
    client.setKeepAlive(mqttClientConfig.getKeepAliveInterval());
    if (mqttClientConfig.getPassword() != null) {
      client.setPassword(mqttClientConfig.getPassword());
    }
    if (mqttClientConfig.getUserName() != null) {
      client.setUserName(mqttClientConfig.getUserName());
    }
    if (mqttClientConfig.getWillMessage() != null) {
      client.setWillMessage(mqttClientConfig.getWillMessage());
      client.setWillQos(mqttClientConfig.getWillQos());
      client.setWillRetain(mqttClientConfig.isWillRetain());
    }
    if (mqttClientConfig.getWillTopic() != null) {
      client.setWillTopic(mqttClientConfig.getWillTopic());
    }
    initializeConnection();
    thread = new Thread(new Runnable()
    {
      @Override
      public void run()
      {
        while (true) {
          try {
            Message msg = connection.receive();
            holdingBuffer.add(msg);
          } catch (Exception ex) {
            LOG.error("Trouble receiving", ex);
          }
        }
      }

    });
    thread.start();
  } catch (Exception ex) {
    LOG.error("Caught exception during activation: ", ex);
    throw new RuntimeException(ex);
  }

}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:51,代码来源:AbstractMqttInputOperator.java


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