private long startTimer(final Integer msgId) { LOG.trace("Start a timer for [{}] ms", config.getCommandAckTimeout()); return vertx.setTimer(config.getCommandAckTimeout(), timerId -> { LOG.trace("Timer [{}] expired", timerId); Optional.ofNullable(removeFromWaitingForAcknowledgement(msgId)).ifPresent(value -> { final CommandSubscription subscription = value.two(); final CommandContext commandContext = value.three(); LOG.debug( "Timed out waiting for acknowledgment for command sent to device [tenant-id: {}, device-id: {}, MQTT client-id: {}, QoS: {}]", subscription.getTenant(), subscription.getDeviceId(), subscription.getClientId(), subscription.getQos()); final Map<String, String> items = new HashMap<>(3); items.put(Fields.EVENT, "Timed out waiting for acknowledgment for command sent to device"); items.put(TracingHelper.TAG_CLIENT_ID.getKey(), subscription.getClientId()); items.put(TracingHelper.TAG_QOS.getKey(), subscription.getQos().toString()); commandContext.getCurrentSpan().log(items); commandContext.release(1); }); }); }
private void afterCommandPublished(final CommandSubscription subscription, final CommandContext commandContext) { metrics.incrementCommandDeliveredToDevice(subscription.getTenant()); LOG.debug("Published command to device [tenant-id: {}, device-id: {}, MQTT client-id: {}, QoS: {}]", subscription.getTenant(), subscription.getDeviceId(), subscription.getClientId(), subscription.getQos()); final Map<String, String> items = new HashMap<>(4); items.put(Fields.EVENT, "Published command to device"); items.put(Tags.MESSAGE_BUS_DESTINATION.getKey(), subscription.getTopic()); items.put(TracingHelper.TAG_CLIENT_ID.getKey(), subscription.getClientId()); items.put(TracingHelper.TAG_QOS.getKey(), subscription.getQos().toString()); commandContext.getCurrentSpan().log(items); commandContext.accept(1); }
/** * Invoked when a device sends an MQTT <em>PUBACK</em> packet. * * @param msgId The msgId of the command published with QoS 1. * @param consumer The consumer to be invoked if not {@code null} on arrival of PUBACK. * @throws NullPointerException if msgId is {@code null}. */ public void handlePubAck(final Integer msgId, final BiConsumer<CommandSubscription, CommandContext> consumer) { Objects.requireNonNull(msgId); LOG.trace("Acknowledgement received for command [Msg-id: {}] that has been sent to device.", msgId); Optional.ofNullable(removeFromWaitingForAcknowledgement(msgId)).ifPresent(value -> { cancelTimer(value.one()); final CommandSubscription subscription = value.two(); final CommandContext commandContext = value.three(); if (consumer != null) { consumer.accept(subscription, commandContext); } LOG.debug( "Acknowledged [Msg-id: {}] command to device [tenant-id: {}, device-id: {}, MQTT client-id: {}, QoS: {}]", msgId, subscription.getTenant(), subscription.getDeviceId(), subscription.getClientId(), subscription.getQos()); final Map<String, String> items = new HashMap<>(3); items.put(Fields.EVENT, "Published command has been acknowledged"); items.put(TracingHelper.TAG_CLIENT_ID.getKey(), subscription.getClientId()); items.put(TracingHelper.TAG_QOS.getKey(), subscription.getQos().toString()); commandContext.getCurrentSpan().log(items); }); }
items.put(Fields.EVENT, "command published to device"); items.put(Tags.MESSAGE_BUS_DESTINATION.getKey(), topic); items.put(TracingHelper.TAG_QOS.getKey(), qos.toString()); commandContext.getCurrentSpan().log(items); commandContext.accept(1);
items.put(Fields.EVENT, "Publishing command to device"); items.put(TracingHelper.TAG_CLIENT_ID.getKey(), subscription.getClientId()); items.put(TracingHelper.TAG_QOS.getKey(), subscription.getQos().toString()); commandContext.getCurrentSpan().log(items);
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) .withTag(Tags.MESSAGE_BUS_DESTINATION.getKey(), context.message().topicName()) .withTag(TracingHelper.TAG_QOS.getKey(), qos.toString()) .withTag(Tags.COMPONENT.getKey(), getTypeName()) .withTag(TracingHelper.TAG_CLIENT_ID.getKey(), context.deviceEndpoint().clientIdentifier())
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) .withTag(Tags.MESSAGE_BUS_DESTINATION.getKey(), context.message().topicName()) .withTag(TracingHelper.TAG_QOS.getKey(), qos.toString()) .withTag(Tags.COMPONENT.getKey(), getTypeName()) .withTag(TracingHelper.TAG_CLIENT_ID.getKey(), context.deviceEndpoint().clientIdentifier())