Class AbstractVertxBasedMqttProtocolAdapter<T extends MqttProtocolAdapterProperties>

    • Field Detail

      • MINIMAL_MEMORY_JVM

        protected static final int MINIMAL_MEMORY_JVM
        The minimum amount of memory (bytes) that the adapter requires to run on a standard Java VM.
        See Also:
        Constant Field Values
      • MINIMAL_MEMORY_SUBSTRATE

        protected static final int MINIMAL_MEMORY_SUBSTRATE
        The minimum amount of memory (bytes) that the adapter requires to run on a Substrate VM (i.e. when running as a GraalVM native image).
        See Also:
        Constant Field Values
      • MEMORY_PER_CONNECTION

        protected static final int MEMORY_PER_CONNECTION
        The amount of memory (bytes) required for each connection.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractVertxBasedMqttProtocolAdapter

        public AbstractVertxBasedMqttProtocolAdapter()
    • Method Detail

      • setAuthHandler

        public final void setAuthHandler​(AuthHandler<MqttConnectContext> authHandler)
        Sets the authentication handler to use for authenticating devices.
        Parameters:
        authHandler - The handler to use.
        Throws:
        NullPointerException - if handler is null.
      • setMetrics

        public final void setMetrics​(MqttAdapterMetrics metrics)
        Sets the metrics for this service.
        Parameters:
        metrics - The metrics
      • getMetrics

        protected final MqttAdapterMetrics getMetrics()
        Gets the metrics for this service.
        Returns:
        The metrics
      • handleBeforeCredentialsValidation

        protected io.vertx.core.Future<Void> handleBeforeCredentialsValidation​(DeviceCredentials credentials,
                                                                               MqttConnectContext executionContext)
        Handles any operations that should be invoked as part of the authentication process after the credentials got determined and before they get validated. Can be used to perform checks using the credentials and tenant information before the potentially expensive credentials validation is done

        The default implementation updates the trace sampling priority in the execution context tracing span. It also verifies that the tenant provided via the credentials is enabled and that the adapter is enabled for that tenant, failing the returned future if either is not the case.

        Subclasses should override this method in order to perform additional operations after calling this super method.

        Parameters:
        credentials - The credentials.
        executionContext - The execution context, including the TenantObject.
        Returns:
        A future indicating the outcome of the operation. A failed future will fail the authentication attempt.
      • setMqttSecureServer

        public void setMqttSecureServer​(io.vertx.mqtt.MqttServer server)
        Sets the MQTT server to use for handling secure MQTT connections.
        Parameters:
        server - The server.
        Throws:
        NullPointerException - if the server is null.
        IllegalStateException - if the adapter has already been started.
      • setMqttInsecureServer

        public void setMqttInsecureServer​(io.vertx.mqtt.MqttServer server)
        Sets the MQTT server to use for handling non-secure MQTT connections.
        Parameters:
        server - The server.
        Throws:
        NullPointerException - if the server is null.
        IllegalStateException - if the adapter has already been started.
      • uploadMessage

        public final io.vertx.core.Future<Void> uploadMessage​(MqttContext ctx,
                                                              org.eclipse.hono.util.ResourceIdentifier resource,
                                                              io.vertx.mqtt.messages.MqttPublishMessage message)
        Forwards a message to the AMQP Messaging Network.
        Parameters:
        ctx - The context in which the MQTT message has been published.
        resource - The resource that the message should be forwarded to.
        message - The message to send.
        Returns:
        A future indicating the outcome of the operation.

        The future will succeed if the message has been forwarded successfully. Otherwise the future will fail with a ServiceInvocationException.

        Throws:
        NullPointerException - if any of context, resource or payload is null.
        IllegalArgumentException - if the payload is empty.
      • uploadTelemetryMessage

        public final io.vertx.core.Future<Void> uploadTelemetryMessage​(MqttContext ctx,
                                                                       String tenant,
                                                                       String deviceId,
                                                                       io.vertx.core.buffer.Buffer payload)
        Forwards a telemetry message to the AMQP Messaging Network.
        Parameters:
        ctx - The context in which the MQTT message has been published.
        tenant - The tenant of the device that has produced the data.
        deviceId - The id of the device that has produced the data.
        payload - The message payload to send.
        Returns:
        A future indicating the outcome of the operation.

        The future will succeed if the message has been forwarded successfully. Otherwise the future will fail with a ServiceInvocationException.

        Throws:
        NullPointerException - if any of context, tenant, device ID or payload is null.
        IllegalArgumentException - if the context does not contain a telemetry message or if the payload is empty.
      • uploadEventMessage

        public final io.vertx.core.Future<Void> uploadEventMessage​(MqttContext ctx,
                                                                   String tenant,
                                                                   String deviceId,
                                                                   io.vertx.core.buffer.Buffer payload)
        Forwards an event to the AMQP Messaging Network.
        Parameters:
        ctx - The context in which the MQTT message has been published.
        tenant - The tenant of the device that has produced the data.
        deviceId - The id of the device that has produced the data.
        payload - The message payload to send.
        Returns:
        A future indicating the outcome of the operation.

        The future will succeed if the message has been forwarded successfully. Otherwise the future will fail with a ServiceInvocationException.

        Throws:
        NullPointerException - if any of context, tenant, device ID or payload is null.
        IllegalArgumentException - if the context does not contain an event or if the payload is empty.
      • uploadCommandResponseMessage

        public final io.vertx.core.Future<Void> uploadCommandResponseMessage​(MqttContext ctx,
                                                                             org.eclipse.hono.util.ResourceIdentifier targetAddress)
        Uploads a command response message.
        Parameters:
        ctx - The context in which the MQTT message has been published.
        targetAddress - The address that the response should be forwarded to.
        Returns:
        A future indicating the outcome of the operation.

        The future will succeed if the message has been uploaded successfully. Otherwise, the future will fail with a ServiceInvocationException.

        Throws:
        NullPointerException - if any of the parameters are null.
      • onClose

        protected void onClose​(io.vertx.mqtt.MqttEndpoint endpoint)
        Invoked before the connection with a device is closed.

        Subclasses should override this method in order to release any device specific resources.

        This default implementation does nothing.

        Parameters:
        endpoint - The connection to be closed.
      • onPublishedMessage

        protected abstract io.vertx.core.Future<Void> onPublishedMessage​(MqttContext ctx)
        Processes an MQTT message that has been published by a device.

        Subclasses should determine

        • the tenant and identifier of the device that has published the message
        • the payload to send downstream
        • the content type of the payload
        and then invoke one of the upload* methods to send the message downstream.
        Parameters:
        ctx - The context in which the MQTT message has been published. The MqttContext.topic() method will return a non-null resource identifier for the topic that the message has been published to.
        Returns:
        A future indicating the outcome of the operation.

        The future will succeed if the message has been successfully uploaded. Otherwise, the future will fail with a ServiceInvocationException.

      • customizeDownstreamMessageProperties

        protected void customizeDownstreamMessageProperties​(Map<String,​Object> messageProperties,
                                                            MqttContext ctx)
        Invoked before the message is sent to the downstream peer.

        Subclasses may override this method in order to customize the properties used for sending the message, e.g. adding custom properties.

        Parameters:
        messageProperties - The properties that are being added to the downstream message.
        ctx - The message processing context.
      • onMessageSent

        protected void onMessageSent​(MqttContext ctx)
        Invoked when a message has been forwarded downstream successfully.

        This default implementation does nothing.

        Subclasses should override this method in order to e.g. update metrics counters.

        Parameters:
        ctx - The context in which the MQTT message has been published.
      • onMessageUndeliverable

        protected void onMessageUndeliverable​(MqttContext ctx)
        Invoked when a message could not be forwarded downstream.

        This method will only be invoked if the failure to forward the message has not been caused by the device that published the message. In particular, this method will not be invoked for messages that cannot be authorized or that are published to an unsupported/unrecognized topic. Such messages will be silently discarded.

        This default implementation does nothing.

        Subclasses should override this method in order to e.g. update metrics counters.

        Parameters:
        ctx - The context in which the MQTT message has been published.
      • getCommandPayload

        protected io.vertx.core.Future<io.vertx.core.buffer.Buffer> getCommandPayload​(org.eclipse.hono.client.command.CommandContext ctx)
        Get the buffer to send as a command to the gateway/device.

        Subclasses should override this method in order to overwrite the provided command.

        Parameters:
        ctx - The command context for this command.
        Returns:
        A future containing the mapped buffer.