if (ch.succeeded()) { System.out.println("Connected to a server"); client.subscribe(MQTT_TOPIC, 0); } else { System.out.println("Failed to connect to a server");
/** * Subscribes to the topic with a specified QoS level * @param topic topic you subscribe on * @param qos QoS level * @param subscribeSentHandler handler called after SUBSCRIBE packet sent with packetid * @return current MQTT client instance */ public io.vertx.rxjava.mqtt.MqttClient subscribe(String topic, int qos, Handler<AsyncResult<Integer>> subscribeSentHandler) { delegate.subscribe(topic, qos, subscribeSentHandler); return this; }
private void subscribe(TestContext context, MqttQoS qos) { this.messageId = 0; Async async = context.async(); MqttClient client = MqttClient.create(Vertx.vertx()); client.subscribeCompletionHandler(suback -> { assertTrue(suback.messageId() == messageId); assertTrue(suback.grantedQoSLevels().contains(qos.value())); log.info("subscribing complete for message id = " + suback.messageId() + " with QoS " + suback.grantedQoSLevels()); client.disconnect(); async.countDown(); }); client.connect(TestUtil.BROKER_PORT, TestUtil.BROKER_ADDRESS, ar -> { assertTrue(ar.succeeded()); client.subscribe(MQTT_TOPIC, qos.value(), done -> { assertTrue(done.succeeded()); messageId = done.result(); log.info("subscribing on [" + MQTT_TOPIC + "] with QoS [" + qos.value() + "] message id = " + messageId); }); }); async.await(); } }
/** * Subscribes to the topics with related QoS levels * @param topics topics and related QoS levels to subscribe to * @return current MQTT client instance */ public io.vertx.rxjava.mqtt.MqttClient subscribe(Map<String, Integer> topics) { delegate.subscribe(topics); return this; }
private void subscribe(TestContext context, MqttQoS qos) { this.messageId = 0; Async async = context.async(); MqttClient client = MqttClient.create(Vertx.vertx()); client.subscribeCompletionHandler(suback -> { assertTrue(suback.messageId() == messageId); assertTrue(suback.grantedQoSLevels().contains(qos.value())); log.info("subscribing complete for message id = " + suback.messageId() + " with QoS " + suback.grantedQoSLevels()); client.disconnect(); async.countDown(); }); client.connect(TestUtil.BROKER_PORT, TestUtil.BROKER_ADDRESS, ar -> { assertTrue(ar.succeeded()); client.subscribe(MQTT_TOPIC, qos.value(), done -> { assertTrue(done.succeeded()); messageId = done.result(); log.info("subscribing on [" + MQTT_TOPIC + "] with QoS [" + qos.value() + "] message id = " + messageId); }); }); async.await(); } }
/** * Subscribes to the topic and adds a handler which will be called after the request is sent * @param topics topics you subscribe on * @param subscribeSentHandler handler called after SUBSCRIBE packet sent with packetid * @return current MQTT client instance */ public io.vertx.rxjava.mqtt.MqttClient subscribe(Map<String, Integer> topics, Handler<AsyncResult<Integer>> subscribeSentHandler) { delegate.subscribe(topics, subscribeSentHandler); return this; }
assertTrue(ar.succeeded()); client.subscribe(MQTT_TOPIC, qos.value(), ar1 -> { assertTrue(ar1.succeeded()); messageId = ar1.result();
/** * Subscribes to the topic with a specified QoS level * @param topic topic you subscribe on * @param qos QoS level * @return current MQTT client instance */ public io.vertx.rxjava.mqtt.MqttClient subscribe(String topic, int qos) { delegate.subscribe(topic, qos); return this; }
assertTrue(ar.succeeded()); client.subscribe(MQTT_TOPIC, qos.value(), ar1 -> { assertTrue(ar1.succeeded()); messageId = ar1.result();
/** * Subscribes to the topic with a specified QoS level * @param topic topic you subscribe on * @param qos QoS level * @param subscribeSentHandler handler called after SUBSCRIBE packet sent with packetid * @return current MQTT client instance */ public io.vertx.rxjava.mqtt.MqttClient subscribe(String topic, int qos, Handler<AsyncResult<Integer>> subscribeSentHandler) { delegate.subscribe(topic, qos, subscribeSentHandler); return this; }
assertTrue(c.succeeded()); log.info("CONNACK <---"); client.subscribe(MQTT_TOPIC, 0); log.info("SUBSCRIBE --->"); });
/** * Subscribes to the topic with a specified QoS level * @param topic topic you subscribe on * @param qos QoS level * @return current MQTT client instance */ public io.vertx.rxjava.mqtt.MqttClient subscribe(String topic, int qos) { delegate.subscribe(topic, qos); return this; }
assertTrue(c.succeeded()); log.info("CONNACK <---"); client.subscribe(MQTT_TOPIC, 0); log.info("SUBSCRIBE --->"); });
/** * Subscribes to the topics with related QoS levels * @param topics topics and related QoS levels to subscribe to * @return current MQTT client instance */ public io.vertx.rxjava.mqtt.MqttClient subscribe(Map<String, Integer> topics) { delegate.subscribe(topics); return this; }
/** * Subscribes to the topic and adds a handler which will be called after the request is sent * @param topics topics you subscribe on * @param subscribeSentHandler handler called after SUBSCRIBE packet sent with packetid * @return current MQTT client instance */ public io.vertx.rxjava.mqtt.MqttClient subscribe(Map<String, Integer> topics, Handler<AsyncResult<Integer>> subscribeSentHandler) { delegate.subscribe(topics, subscribeSentHandler); return this; }
public void testSubscribe(String topicFilter, boolean mustBeValid, TestContext context) { log.info(String.format("test subscribing for \"%s\" topic", topicFilter)); Async async = context.async(2); MqttClient client = MqttClient.create(Vertx.vertx()); client.connect(TestUtil.BROKER_PORT, TestUtil.BROKER_ADDRESS, c -> { Assert.assertTrue(c.succeeded()); client.subscribe( topicFilter, 0, ar -> { assertThat(ar.succeeded(), is(mustBeValid)); log.info("subscribe message id = " + ar.result()); async.countDown(); client .disconnect(ar1 -> { Assert.assertTrue(ar1.succeeded()); async.countDown(); }); }); }); async.await(); } }
public void testSubscribe(String topicFilter, boolean mustBeValid, TestContext context) { log.info(String.format("test subscribing for \"%s\" topic", topicFilter)); Async async = context.async(2); MqttClient client = MqttClient.create(Vertx.vertx()); client.connect(TestUtil.BROKER_PORT, TestUtil.BROKER_ADDRESS, c -> { Assert.assertTrue(c.succeeded()); client.subscribe( topicFilter, 0, ar -> { assertThat(ar.succeeded(), is(mustBeValid)); log.info("subscribe message id = " + ar.result()); async.countDown(); client .disconnect(ar1 -> { Assert.assertTrue(ar1.succeeded()); async.countDown(); }); }); }); async.await(); } }
private void subscribeAndReceive(TestContext context, MqttQoS qos) { Async async = context.async(); MqttClient client = MqttClient.create(Vertx.vertx()); client.publishHandler(publish -> { assertTrue(publish.qosLevel() == qos); log.info("Just received message on [" + publish.topicName() + "] payload [" + publish.payload().toString(Charset.defaultCharset()) + "] with QoS [" + publish.qosLevel() + "]"); client.disconnect(); async.countDown(); }); client.connect(TestUtil.BROKER_PORT, TestUtil.BROKER_ADDRESS, ar -> { assertTrue(ar.succeeded()); client.subscribe(MQTT_TOPIC, qos.value()); client.publish( MQTT_TOPIC, Buffer.buffer(MQTT_MESSAGE.getBytes()), qos, false, false ); }); async.await(); }
private void subscribeAndReceive(TestContext context, MqttQoS qos) { Async async = context.async(); MqttClient client = MqttClient.create(Vertx.vertx()); client.publishHandler(publish -> { assertTrue(publish.qosLevel() == qos); log.info("Just received message on [" + publish.topicName() + "] payload [" + publish.payload().toString(Charset.defaultCharset()) + "] with QoS [" + publish.qosLevel() + "]"); client.disconnect(); async.countDown(); }); client.connect(TestUtil.BROKER_PORT, TestUtil.BROKER_ADDRESS, ar -> { assertTrue(ar.succeeded()); client.subscribe(MQTT_TOPIC, qos.value()); client.publish( MQTT_TOPIC, Buffer.buffer(MQTT_MESSAGE.getBytes()), qos, false, false ); }); async.await(); }