Java Code Examples for io.vertx.mqtt.MqttClient#exceptionHandler()

The following examples show how to use io.vertx.mqtt.MqttClient#exceptionHandler() . 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: MqttClientSslTest.java    From vertx-mqtt with Apache License 2.0 6 votes vote down vote up
@Test
public void clientSslClientTruststoreTest(TestContext context) {

  this.context = context;
  JksOptions jksOptions = new JksOptions().setPath("/tls/client-truststore.jks");

  MqttClientOptions clientOptions = new MqttClientOptions()
    .setSsl(true)
    .setTrustStoreOptions(jksOptions);

  MqttClient client = MqttClient.create(vertx, clientOptions);
  client.exceptionHandler(t -> context.assertTrue(false));

  Async async = context.async();
  client.connect(MQTT_SERVER_TLS_PORT, MQTT_SERVER_HOST, s -> client.disconnect(d -> async.countDown()));
  async.await();
}
 
Example 2
Source File: MqttClientSslTest.java    From vertx-mqtt with Apache License 2.0 5 votes vote down vote up
@Test
public void clientSslTrustAllTest(TestContext context) {
  MqttClientOptions clientOptions = new MqttClientOptions()
    .setSsl(true)
    .setTrustAll(true);

  MqttClient client = MqttClient.create(vertx, clientOptions);
  client.exceptionHandler(t -> context.assertTrue(false));

  this.context = context;
  Async async = context.async();
  client.connect(MQTT_SERVER_TLS_PORT, MQTT_SERVER_HOST, s -> client.disconnect(d -> async.countDown()));
  async.await();
}
 
Example 3
Source File: MqttClientMaxMessageSizeTest.java    From vertx-mqtt with Apache License 2.0 5 votes vote down vote up
@Test
public void decoderMaxMessageSize(TestContext context) throws InterruptedException {
  Async async = context.async();
  MqttClient client = MqttClient.create(Vertx.vertx(),
    new MqttClientOptions()
      .setMaxMessageSize(MQTT_MAX_MESSAGE_SIZE)
  );

  client.subscribeCompletionHandler(sc -> {
    log.info("SUBACK <---");
    byte[] message = new byte[MQTT_BIG_MESSAGE_SIZE];
    client.publish(MQTT_TOPIC, Buffer.buffer(message), AT_MOST_ONCE, false, false);
    log.info("PUBLISH ---> ... with big message size which should cause decoder exception");
  });

  client.exceptionHandler(t->{
    log.error("Exception raised", t);

    if (t instanceof DecoderException) {
      log.info("PUBLISH <--- message with big size");
      async.countDown();
    }
  });

  log.info("CONNECT --->");
  client.connect(TestUtil.BROKER_PORT, TestUtil.BROKER_ADDRESS, c -> {
    assertTrue(c.succeeded());
    log.info("CONNACK <---");
    client.subscribe(MQTT_TOPIC, 0);
    log.info("SUBSCRIBE --->");
  });

  async.await();
}