message.qosLevel() + "]"); });
System.out.println("Just received message on [" + publish.topicName() + "] payload [" + publish.payload().toString(Charset.defaultCharset()) + "] with QoS [" + publish.qosLevel() + "]"); });
System.out.println("Just received message on [" + message.topicName() + "] payload [" + message.payload() + "] with QoS [" + message.qosLevel() + "]"); if (message.qosLevel() == MqttQoS.AT_LEAST_ONCE) { endpoint.publishAcknowledge(message.messageId()); } else if (message.qosLevel() == MqttQoS.EXACTLY_ONCE) { endpoint.publishReceived(message.messageId());
/** * Checks if the message has been published using QoS 1. * * @return {@code true} if the message has been published using QoS 1. */ public boolean isAtLeastOnce() { if (message == null) { return false; } else { return MqttQoS.AT_LEAST_ONCE == message.qosLevel(); } }
/** * @return Quality of service level */ public MqttQoS qosLevel() { if (cached_1 != null) { return cached_1; } MqttQoS ret = delegate.qosLevel(); cached_1 = ret; return ret; }
/** * @return Quality of service level */ public MqttQoS qosLevel() { if (cached_1 != null) { return cached_1; } MqttQoS ret = delegate.qosLevel(); cached_1 = ret; return ret; }
/** * @return Quality of service level */ public MqttQoS qosLevel() { if (cached_1 != null) { return cached_1; } MqttQoS ret = delegate.qosLevel(); cached_1 = ret; return ret; }
/** * Used for calling the publish handler when the remote MQTT client publishes a message * * @param msg published message */ void handlePublish(io.vertx.mqtt.messages.MqttPublishMessage msg) { synchronized (this.conn) { if (this.publishHandler != null) { this.publishHandler.handle(msg); } if (this.isPublishAutoAck) { switch (msg.qosLevel()) { case AT_LEAST_ONCE: this.publishAcknowledge(msg.messageId()); break; case EXACTLY_ONCE: this.publishReceived(msg.messageId()); break; } } } }
/** * Used for calling the publish handler when the remote MQTT client publishes a message * * @param msg published message */ void handlePublish(io.vertx.mqtt.messages.MqttPublishMessage msg) { synchronized (this.conn) { if (this.publishHandler != null) { this.publishHandler.handle(msg); } if (this.isPublishAutoAck) { switch (msg.qosLevel()) { case AT_LEAST_ONCE: this.publishAcknowledge(msg.messageId()); break; case EXACTLY_ONCE: this.publishReceived(msg.messageId()); break; } } } }
/** * Used for calling the publish handler when the remote MQTT client publishes a message * * @param msg published message */ void handlePublish(io.vertx.mqtt.messages.MqttPublishMessage msg) { synchronized (this.conn) { if (this.publishHandler != null) { this.publishHandler.handle(msg); } if (this.isPublishAutoAck) { switch (msg.qosLevel()) { case AT_LEAST_ONCE: this.publishAcknowledge(msg.messageId()); break; case EXACTLY_ONCE: this.publishReceived(msg.messageId()); break; } } } }
/** * Used for calling the publish handler when the server publishes a message * * @param msg published message */ private void handlePublish(MqttPublishMessage msg) { Handler<MqttPublishMessage> handler; switch (msg.qosLevel()) { case AT_MOST_ONCE: handler = this.publishHandler(); if (handler != null) { handler.handle(msg); } break; case AT_LEAST_ONCE: this.publishAcknowledge(msg.messageId()); handler = this.publishHandler(); if (handler != null) { handler.handle(msg); } break; case EXACTLY_ONCE: this.publishReceived(msg); // we will handle the PUBLISH when a PUBREL comes break; } }
/** * Used for calling the publish handler when the server publishes a message * * @param msg published message */ private void handlePublish(MqttPublishMessage msg) { Handler<MqttPublishMessage> handler; switch (msg.qosLevel()) { case AT_MOST_ONCE: handler = this.publishHandler(); if (handler != null) { handler.handle(msg); } break; case AT_LEAST_ONCE: this.publishAcknowledge(msg.messageId()); handler = this.publishHandler(); if (handler != null) { handler.handle(msg); } break; case EXACTLY_ONCE: this.publishReceived(msg); // we will handle the PUBLISH when a PUBREL comes break; } }
Future<ResourceIdentifier> mapTopic(final MqttContext ctx) { final Future<ResourceIdentifier> result = Future.future(); final ResourceIdentifier topic = ctx.topic(); ResourceIdentifier mappedTopic = null; if (getConfig().getControlPrefix().equals(topic.getEndpoint())) { // this is a "control" message ctx.setContentType(getConfig().getCtrlMsgContentType()); final String[] mappedPath = Arrays.copyOf(topic.getResourcePath(), topic.getResourcePath().length); mappedPath[0] = getEndpoint(ctx.message().qosLevel()); mappedTopic = ResourceIdentifier.fromPath(mappedPath); } else { // map "data" messages based on QoS ctx.setContentType(getConfig().getDataMsgContentType()); final String[] mappedPath = new String[topic.getResourcePath().length + 1]; System.arraycopy(topic.getResourcePath(), 0, mappedPath, 1, topic.getResourcePath().length); mappedPath[0] = getEndpoint(ctx.message().qosLevel()); mappedTopic = ResourceIdentifier.fromPath(mappedPath); } if (mappedTopic.getResourcePath().length < 3) { // topic does not contain account_name and client_id result.fail(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, "topic does not comply with Kura format")); } else { LOG.debug("mapped Kura message [topic: {}, QoS: {}] to Hono message [to: {}, device_id: {}, content-type: {}]", topic, ctx.message().qosLevel(), mappedTopic.getBasePath(), mappedTopic.getResourceId(), ctx.contentType()); result.complete(mappedTopic); } return result; }
Future<ResourceIdentifier> mapTopic(final MqttContext ctx) { final Future<ResourceIdentifier> result = Future.future(); final ResourceIdentifier topic = ctx.topic(); ResourceIdentifier mappedTopic = null; if (getConfig().getControlPrefix().equals(topic.getEndpoint())) { // this is a "control" message ctx.setContentType(getConfig().getCtrlMsgContentType()); final String[] mappedPath = Arrays.copyOf(topic.getResourcePath(), topic.getResourcePath().length); mappedPath[0] = getEndpoint(ctx.message().qosLevel()); mappedTopic = ResourceIdentifier.fromPath(mappedPath); } else { // map "data" messages based on QoS ctx.setContentType(getConfig().getDataMsgContentType()); final String[] mappedPath = new String[topic.getResourcePath().length + 1]; System.arraycopy(topic.getResourcePath(), 0, mappedPath, 1, topic.getResourcePath().length); mappedPath[0] = getEndpoint(ctx.message().qosLevel()); mappedTopic = ResourceIdentifier.fromPath(mappedPath); } if (mappedTopic.getResourcePath().length < 3) { // topic does not contain account_name and client_id result.fail(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, "topic does not comply with Kura format")); } else { LOG.debug("mapped Kura message [topic: {}, QoS: {}] to Hono message [to: {}, device_id: {}, content-type: {}]", topic, ctx.message().qosLevel(), mappedTopic.getBasePath(), mappedTopic.getResourceId(), ctx.contentType()); result.complete(mappedTopic); } return result; }
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(); }
@Override protected void endpointHandler(MqttEndpoint endpoint, TestContext context) { endpoint.publishHandler(message -> { log.info("Just received message on [" + message.topicName() + "] payload [" + message.payload().toString(Charset.defaultCharset()) + "] with QoS [" + message.qosLevel() + "]"); switch (message.qosLevel()) { case AT_LEAST_ONCE: endpoint.publishAcknowledge(message.messageId()); this.async.complete(); break; case EXACTLY_ONCE: endpoint.publishReceived(message.messageId()); break; case AT_MOST_ONCE: this.async.complete(); break; } }).publishReleaseHandler(messageId -> { endpoint.publishComplete(messageId); this.async.complete(); }); endpoint.accept(false); }
@Override protected void endpointHandler(MqttEndpoint endpoint, TestContext context) { endpoint.publishHandler(message -> { log.info("Just received message on [" + message.topicName() + "] payload [" + message.payload().toString(Charset.defaultCharset()) + "] with QoS [" + message.qosLevel() + "]"); switch (message.qosLevel()) { case AT_LEAST_ONCE: endpoint.publishAcknowledge(message.messageId()); this.async.complete(); break; case EXACTLY_ONCE: endpoint.publishReceived(message.messageId()); break; case AT_MOST_ONCE: this.async.complete(); break; } }).publishReleaseHandler(messageId -> { endpoint.publishComplete(messageId); this.async.complete(); }); endpoint.accept(false); }