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

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

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

MQTT.setCleanSession介绍

暂无

代码示例

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

main.mqtt.setKeepAlive(Short.parseShort(shift(argl)));
} else if ("-c".equals(arg)) {
  main.mqtt.setCleanSession(false);
} else if ("-i".equals(arg)) {
  main.mqtt.setClientId(shift(argl));

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

main.mqtt.setKeepAlive(Short.parseShort(shift(argl)));
} else if ("-c".equals(arg)) {
  main.mqtt.setCleanSession(false);
} else if ("-i".equals(arg)) {
  main.mqtt.setClientId(shift(argl));

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

client.setCleanSession(options.isCleanConnection());

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

m_mqtt.setCleanSession(false);
m_mqtt.setClientId("Subscriber");
m_subscriber = m_mqtt.blockingConnection();

代码示例来源: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 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: org.eclipse.kapua/kapua-client-gateway-provider-fuse

@Override
  public FuseChannel build() throws Exception {
    final URI broker = Objects.requireNonNull(broker(), "Broker must be set");
    final String clientId = Strings.nonEmptyText(clientId(), "clientId");
    final MqttNamespace namespace = Objects.requireNonNull(namespace(), "Namespace must be set");
    final BinaryPayloadCodec codec = Objects.requireNonNull(codec(), "Codec must be set");
    final MQTT mqtt = new MQTT();
    mqtt.setCleanSession(false);
    mqtt.setHost(broker);
    mqtt.setClientId(clientId);
    final Object credentials = credentials();
    if (credentials == null) {
      // none
    } else if (credentials instanceof UserAndPassword) {
      final UserAndPassword userAndPassword = (UserAndPassword) credentials;
      mqtt.setUserName(userAndPassword.getUsername());
      mqtt.setPassword(userAndPassword.getPasswordAsString());
    } else {
      throw new IllegalStateException(
          String.format("Unknown credentials type: %s", credentials.getClass().getName()));
    }
    final CallbackConnection connection = mqtt.callbackConnection();
    final FuseChannel result = new FuseChannel(clientId, namespace, codec, connection);
    return result;
  }
}

代码示例来源:origin: eclipse/kapua

@Override
  public FuseChannel build() throws Exception {
    final URI broker = Objects.requireNonNull(broker(), "Broker must be set");
    final String clientId = Strings.nonEmptyText(clientId(), "clientId");
    final MqttNamespace namespace = Objects.requireNonNull(namespace(), "Namespace must be set");
    final BinaryPayloadCodec codec = Objects.requireNonNull(codec(), "Codec must be set");
    final MQTT mqtt = new MQTT();
    mqtt.setCleanSession(false);
    mqtt.setHost(broker);
    mqtt.setClientId(clientId);
    final Object credentials = credentials();
    if (credentials == null) {
      // none
    } else if (credentials instanceof UserAndPassword) {
      final UserAndPassword userAndPassword = (UserAndPassword) credentials;
      mqtt.setUserName(userAndPassword.getUsername());
      mqtt.setPassword(userAndPassword.getPasswordAsString());
    } else {
      throw new IllegalStateException(
          String.format("Unknown credentials type: %s", credentials.getClass().getName()));
    }
    final CallbackConnection connection = mqtt.callbackConnection();
    final FuseChannel result = new FuseChannel(clientId, namespace, codec, connection);
    return result;
  }
}

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

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

代码示例来源: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: sitewhere/sitewhere

mqtt.setCleanSession(component.isCleanSession());
component.getLogger().info("MQTT clean session flag being set to '" + component.isCleanSession() + "'.");

代码示例来源: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/apex-malhar

client.setClientId(mqttClientConfig.getClientId());
client.setCleanSession(mqttClientConfig.isCleanSession());
client.setConnectAttemptsMax(mqttClientConfig.getConnectAttemptsMax());
client.setHost(mqttClientConfig.getHost(), mqttClientConfig.getPort());

代码示例来源:origin: org.apache.apex/malhar-contrib

client.setClientId(mqttClientConfig.getClientId());
client.setCleanSession(mqttClientConfig.isCleanSession());
client.setConnectAttemptsMax(mqttClientConfig.getConnectAttemptsMax());
client.setHost(mqttClientConfig.getHost(), mqttClientConfig.getPort());

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

MQTT mqtt = createMQTTConnection();
mqtt.setClientId("");
mqtt.setCleanSession(true);

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

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

代码示例来源:origin: org.apache.apex/malhar-contrib

client.setClientId(mqttClientConfig.getClientId());
client.setCleanSession(mqttClientConfig.isCleanSession());
client.setConnectAttemptsMax(mqttClientConfig.getConnectAttemptsMax());
client.setHost(mqttClientConfig.getHost(), mqttClientConfig.getPort());

代码示例来源:origin: apache/apex-malhar

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

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

mqtt.setCleanSession(!"durable".equals(clientId));

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

mqtt.setCleanSession(!"durable".equals(clientId));

相关文章