Class CommandSubscription

  • All Implemented Interfaces:
    Subscription

    public final class CommandSubscription
    extends AbstractSubscription
    A device's MQTT subscription for command messages.

    Supported topic filters: command|c/[+|TENANT]/[+|DEVICE_ID]/req|q/#

    Examples:

    1. command/DEFAULT_TENANT/4711/req/# unauthenticated device
    2. command///req/# - authenticated device
    3. c///q/# - authenticated device using short names
    • Method Detail

      • fromTopic

        public static CommandSubscription fromTopic​(io.vertx.mqtt.MqttTopicSubscription mqttTopicSub,
                                                    org.eclipse.hono.auth.Device authenticatedDevice)
        Creates a command subscription object for the given topic.

        If the authenticated device is given, it is used to either validate the tenant and device-id given via the topic or, if the topic doesn't contain these values, the authenticated device is used to provide tenant and device-id for the created command subscription object.

        Parameters:
        mqttTopicSub - The MqttTopicSubscription request from device for command subscription.
        authenticatedDevice - The authenticated device or null.
        Returns:
        The CommandSubscription object or null if the topic does not match the rules.
        Throws:
        NullPointerException - if mqttTopicSub is null.
      • fromTopic

        public static CommandSubscription fromTopic​(String topic,
                                                    io.netty.handler.codec.mqtt.MqttQoS qos,
                                                    org.eclipse.hono.auth.Device authenticatedDevice)
        Creates a command subscription object for the given topic.

        If the authenticated device is given, it is used to either validate the tenant and device-id given via the topic or, if the topic doesn't contain these values, the authenticated device is used to provide tenant and device-id for the created command subscription object.

        Parameters:
        topic - The topic to subscribe for commands.
        qos - The quality-of-service level for the subscription.
        authenticatedDevice - The authenticated device or null.
        Returns:
        The CommandSubscription object or null if the topic does not match the rules.
        Throws:
        NullPointerException - if topic or qos is null.
      • hasCommandEndpointPrefix

        public static boolean hasCommandEndpointPrefix​(String topic)
        Checks whether the given topic name starts with the command endpoint identifier.
        Parameters:
        topic - The topic to check.
        Returns:
        true if the topic has the command endpoint prefix.
      • getKey

        public static Subscription.Key getKey​(String topic,
                                              org.eclipse.hono.auth.Device authenticatedDevice)
        Get the key to identify a command subscription in the list of command subscriptions of an MQTT Endpoint.

        Only returns a non-null key if the topic is valid.

        Parameters:
        topic - The topic of the subscription.
        authenticatedDevice - The authenticated device or null.
        Returns:
        The key or null if the topic does not match the rules.
        Throws:
        NullPointerException - if topic is null.
      • getKey

        public Subscription.Key getKey()
        Gets the key to identify a subscription in the list of subscriptions of an MQTT Endpoint. An MQTT Endpoint can't have multiple subscriptions with the same key, meaning with respect to command subscriptions that there can only be one command subscription per device.
        Returns:
        The key.
      • getRequestPart

        public String getRequestPart()
        Gets the request part of the subscription.
        Returns:
        The request part.
      • getCommandPublishTopic

        public String getCommandPublishTopic​(org.eclipse.hono.client.command.Command command)
        Gets the name of the topic that a command should be published to.
        Parameters:
        command - The command to publish.
        Returns:
        The topic name.
        Throws:
        NullPointerException - if command is null.