org.fusesource.mqtt.client.MQTT.setClientId()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中org.fusesource.mqtt.client.MQTT.setClientId()方法的一些代码示例,展示了MQTT.setClientId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MQTT.setClientId()方法的具体详情如下:
包路径:org.fusesource.mqtt.client.MQTT
类名称:MQTT
方法名:setClientId

MQTT.setClientId介绍

暂无

代码示例

代码示例来源:origin: fusesource/mqtt-client

public void setClientId(String clientId) {
  this.setClientId(utf8(clientId));
}
public void setClientId(UTF8Buffer clientId) {

代码示例来源:origin: apache/storm

/**
 * Initializes {@code connection}.
 * @throws Exception if an exception during connecting to connector occurs
 */
public static void startPublisher() throws Exception {
  MQTT client = new MQTT();
  client.setTracer(new MqttLogger());
  client.setHost("tcp://localhost:1883");
  client.setClientId("MqttBrokerPublisher");
  connection = client.blockingConnection();
  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      try {
        LOG.info("Shutting down MQTT client...");
        connection.disconnect();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  });
  connection.connect();
}

代码示例来源:origin: fusesource/mqtt-client

main.mqtt.setCleanSession(false);
} else if ("-i".equals(arg)) {
  main.mqtt.setClientId(shift(argl));
} else if ("-u".equals(arg)) {
  main.mqtt.setUserName(shift(argl));

代码示例来源:origin: fusesource/mqtt-client

main.mqtt.setCleanSession(false);
} else if ("-i".equals(arg)) {
  main.mqtt.setClientId(shift(argl));
} else if ("-u".equals(arg)) {
  main.mqtt.setUserName(shift(argl));

代码示例来源:origin: apache/storm

client.setSslContext(SslUtils.sslContext(uri.getScheme(), keyStoreLoader));
client.setClientId(clientId);
LOG.info("MQTT ClientID: {}", client.getClientId().toString());
client.setCleanSession(options.isCleanConnection());

代码示例来源:origin: andsel/moquette

mqtt.setClientId("WillTestamentPublisher");
mqtt.setWillRetain(false);
mqtt.setWillMessage(willTestamentMsg);
m_mqtt.setClientId("Subscriber");
m_subscriber = m_mqtt.blockingConnection();
m_subscriber.connect();

代码示例来源:origin: org.fusesource.mqtt-client/mqtt-client

public void setClientId(String clientId) {
  this.setClientId(utf8(clientId));
}
public void setClientId(UTF8Buffer clientId) {

代码示例来源:origin: apache/activemq-artemis

@Override
public void setClientId(String clientId) {
 mqtt.setClientId(clientId);
}

代码示例来源:origin: tuanhiep/mqtt-jmeter

private FutureConnection createConnection(String host,String clientId) {
  try {
    MQTT client = new MQTT();
    client.setHost(host);
    client.setClientId(clientId);
    return client.futureConnection();
  } catch (URISyntaxException e) {
    getLogger().error(e.getMessage());
    return null;
  }
}
private FutureConnection createConnection(String host,String clientId,String user, String password) {

代码示例来源:origin: dempeZheng/forest-chat

public void init(String host, int port) throws Exception {
  mqtt = new MQTT();
  mqtt.setHost(host, port);
  mqtt.setUserName(uid);
  mqtt.setPassword(pwd);
  mqtt.setClientId(uid);
}

代码示例来源:origin: tuanhiep/mqtt-jmeter

private CallbackConnection createConnection(String host, String clientId,
    boolean durable) throws URISyntaxException {
  MQTT client = new MQTT();
  client.setHost(host);
  client.setClientId(clientId);
  client.setCleanSession(!durable);
  return client.callbackConnection();
}

代码示例来源:origin: tuanhiep/mqtt-jmeter

private FutureConnection createConnection(String host,String clientId,String user, String password) {
  try {
    MQTT client = new MQTT();
    client.setHost(host);
    client.setUserName(user);
    client.setPassword(password);
    client.setClientId(clientId);
    return client.futureConnection();
  } catch (URISyntaxException e) {
    getLogger().error(e.getMessage());
    return null;
  }
}

代码示例来源:origin: tuanhiep/mqtt-jmeter

private CallbackConnection createConnection(String host, String clientId,
    boolean durable, String user, String password)
    throws URISyntaxException {
  MQTT client = new MQTT();
  client.setHost(host);
  client.setClientId(clientId);
  client.setUserName(user);
  client.setPassword(password);
  client.setCleanSession(!durable);
  return client.callbackConnection();
}

代码示例来源:origin: apache/activemq-artemis

@Test(timeout = 60 * 1000)
public void testMQTT311Connection() throws Exception {
 MQTT mqtt = createMQTTConnection();
 mqtt.setClientId("foo");
 mqtt.setVersion("3.1.1");
 final BlockingConnection connection = mqtt.blockingConnection();
 connection.connect();
 connection.disconnect();
}

代码示例来源:origin: apache/activemq-artemis

@Test(timeout = 30 * 1000)
public void testValidZeroLengthClientId() throws Exception {
 MQTT mqtt = createMQTTConnection();
 mqtt.setClientId("");
 mqtt.setCleanSession(true);
 BlockingConnection connection = mqtt.blockingConnection();
 connection.connect();
 connection.disconnect();
}

代码示例来源:origin: apache/activemq-artemis

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;
}

代码示例来源:origin: apache/activemq-artemis

@Test(timeout = 60 * 1000)
public void testPingKeepsInactivityMonitorAlive() throws Exception {
 MQTT mqtt = createMQTTConnection();
 mqtt.setClientId("foo");
 mqtt.setKeepAlive((short) 2);
 final BlockingConnection connection = mqtt.blockingConnection();
 connection.connect();
 assertTrue("KeepAlive didn't work properly", Wait.waitFor(() -> connection.isConnected()));
 connection.disconnect();
}

代码示例来源:origin: apache/activemq-artemis

@Test(timeout = 30 * 1000)
public void testDefaultKeepAliveWhenClientSpecifiesZero() throws Exception {
 stopBroker();
 protocolConfig = "transport.defaultKeepAlive=2000";
 startBroker();
 MQTT mqtt = createMQTTConnection();
 mqtt.setClientId("foo");
 mqtt.setKeepAlive((short) 0);
 final BlockingConnection connection = mqtt.blockingConnection();
 connection.connect();
 assertTrue("KeepAlive didn't work properly", Wait.waitFor(() -> connection.isConnected()));
}

代码示例来源:origin: apache/activemq-artemis

@Test(timeout = 60 * 1000)
public void testPingOnMQTT() throws Exception {
 stopBroker();
 protocolConfig = "maxInactivityDuration=-1";
 startBroker();
 MQTT mqtt = createMQTTConnection();
 mqtt.setClientId("test-mqtt");
 mqtt.setKeepAlive((short) 2);
 final BlockingConnection connection = mqtt.blockingConnection();
 connection.connect();
 assertTrue("KeepAlive didn't work properly", Wait.waitFor(() -> connection.isConnected()));
 connection.disconnect();
}

代码示例来源:origin: apache/activemq-artemis

@Test(timeout = 60 * 1000)
public void testTurnOffInactivityMonitor() throws Exception {
 stopBroker();
 protocolConfig = "transport.useInactivityMonitor=false";
 startBroker();
 MQTT mqtt = createMQTTConnection();
 mqtt.setClientId("foo3");
 mqtt.setKeepAlive((short) 2);
 final BlockingConnection connection = mqtt.blockingConnection();
 connection.connect();
 assertTrue("KeepAlive didn't work properly", Wait.waitFor(() -> connection.isConnected()));
 connection.disconnect();
}

相关文章