String tenantId = subscription.getTenant(); String deviceId = subscription.getDeviceId(); if (subscription.isAuthenticated()) { subscription.getRequestPart(), commandRequestId, command.getName()); endpoint.publish(topic, command.getPayload(), qos, false, false); metrics.incrementCommandDeliveredToDevice(subscription.getTenant()); LOG.trace("command published to device [tenant-id: {}, device-id: {}, MQTT client-id: {}]", subscription.getTenant(), subscription.getDeviceId(), endpoint.clientIdentifier()); final Map<String, String> items = new HashMap<>(3); items.put(Fields.EVENT, "command published to device");
sendDisconnectedTtdEvent(cmdSub.getTenant(), cmdSub.getDeviceId(), authenticatedDevice, null) .setHandler(sendAttempt -> { consumer.close(null); span.log(items); LOG.debug("created subscription [tenant: {}, device: {}, filter: {}, requested QoS: {}, granted QoS: {}]", cmdSub.getTenant(), cmdSub.getDeviceId(), subscription.topicName(), subscription.qualityOfService(), MqttQoS.AT_MOST_ONCE); return cmdSub; TracingHelper.logError(span, items); LOG.debug("cannot create subscription [tenant: {}, device: {}, filter: {}, requested QoS: {}]", cmdSub.getTenant(), cmdSub.getDeviceId(), subscription.topicName(), subscription.qualityOfService(), t); return Future.failedFuture(t); if (f.succeeded() && f.result() instanceof CommandSubscription) { final CommandSubscription s = (CommandSubscription) f.result(); sendConnectedTtdEvent(s.getTenant(), s.getDeviceId(), authenticatedDevice, span.context());
LOG.debug("ignoring unsubscribe request for unsupported topic filter [{}]", topic); } else { final String tenantId = cmdSub.getTenant(); final String deviceId = cmdSub.getDeviceId(); final Map<String, Object> items = new HashMap<>(2);
private Future<MessageConsumer> createCommandConsumer(final MqttEndpoint mqttEndpoint, final CommandSubscription sub) { // if a device does not specify a keep alive in its CONNECT packet then // the default value of the CommandConnection will be used final long livenessCheckInterval = mqttEndpoint.keepAliveTimeSeconds() * 1000 / 2; return getCommandConnection().createCommandConsumer( sub.getTenant(), sub.getDeviceId(), commandContext -> { Tags.COMPONENT.set(commandContext.getCurrentSpan(), getTypeName()); final Command command = commandContext.getCommand(); if (command.isValid()) { onCommandReceived(mqttEndpoint, sub, commandContext); } else { // issue credit so that application(s) can send the next command commandContext.reject(new ErrorCondition(Constants.AMQP_BAD_REQUEST, "malformed command message"), 1); } }, remoteClose -> {}, livenessCheckInterval); }