Java Code Examples for io.vertx.mqtt.MqttClientOptions#setKeepAliveTimeSeconds()

The following examples show how to use io.vertx.mqtt.MqttClientOptions#setKeepAliveTimeSeconds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MqttHelpers.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
static MqttClientOptions createMqttClientOptions(MqttConnectorCommonConfiguration config) {
    MqttClientOptions options = new MqttClientOptions();
    options.setCleanSession(config.getAutoCleanSession());
    options.setAutoGeneratedClientId(config.getAutoGeneratedClientId());
    options.setAutoKeepAlive(config.getAutoKeepAlive());
    options.setClientId(config.getClientId().orElse(null));
    options.setConnectTimeout(config.getConnectTimeoutSeconds());
    options.setKeepAliveTimeSeconds(config.getKeepAliveSeconds());
    options.setMaxInflightQueue(config.getMaxInflightQueue());
    options.setMaxMessageSize(config.getMaxMessageSize());
    options.setPassword(config.getPassword().orElse(null));
    options.setReconnectAttempts(config.getReconnectAttempts());
    options.setReconnectInterval(TimeUnit.SECONDS.toMillis(config.getReconnectIntervalSeconds()));
    options.setSsl(config.getSsl());
    options.setTrustAll(config.getTrustAll());
    options.setUsername(config.getUsername().orElse(null));
    options.setWillQoS(config.getWillQos());
    options.setWillFlag(config.getWillFlag());
    options.setWillRetain(config.getWillRetain());
    return options;
}
 
Example 2
Source File: MqttClientConnectTest.java    From vertx-mqtt with Apache License 2.0 6 votes vote down vote up
@Test
public void connectDisconnectWithIdleOption(TestContext context) {
  Async async = context.async();
  MqttClientOptions options = new MqttClientOptions();
  options.setKeepAliveTimeSeconds(100);
  MqttClient client = MqttClient.create(Vertx.vertx(),options);

  client.connect(TestUtil.BROKER_PORT, TestUtil.BROKER_ADDRESS, c -> {

    assertTrue(c.succeeded());

    client
      .disconnect(ar -> {
        assertTrue(ar.succeeded());
        async.countDown();
      });
  });

  async.await();
}
 
Example 3
Source File: MqttClientPingTest.java    From vertx-mqtt with Apache License 2.0 5 votes vote down vote up
@Test
public void autoPing(TestContext context) throws InterruptedException {

  Async async = context.async();
  MqttClientOptions options = new MqttClientOptions();
  options.setKeepAliveTimeSeconds(KEEPALIVE_TIMEOUT);

  log.info("Auto ping ... " + PING_NUMBER + " times timeout " + KEEPALIVE_TIMEOUT);

  count = 0;
  MqttClient client = MqttClient.create(Vertx.vertx(), options);
  client.connect(TestUtil.BROKER_PORT,  TestUtil.BROKER_ADDRESS, c -> {
    assertTrue(c.succeeded());
    client.pingResponseHandler(v -> {

      log.info("Pingresp <-- ");
      count++;
      if (count == PING_NUMBER) {
        client.disconnect();
        async.countDown();
      }
    });

  });

  async.await();
}