Package org.eclipse.hono.adapter.mqtt
Class CommandSubscription
- java.lang.Object
-
- org.eclipse.hono.adapter.mqtt.AbstractSubscription
-
- org.eclipse.hono.adapter.mqtt.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:
command/DEFAULT_TENANT/4711/req/#unauthenticated devicecommand///req/#- authenticated devicec///q/#- authenticated device using short names
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.hono.adapter.mqtt.Subscription
Subscription.Key
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CommandSubscriptionfromTopic(io.vertx.mqtt.MqttTopicSubscription mqttTopicSub, org.eclipse.hono.auth.Device authenticatedDevice)Creates a command subscription object for the given topic.static CommandSubscriptionfromTopic(String topic, io.netty.handler.codec.mqtt.MqttQoS qos, org.eclipse.hono.auth.Device authenticatedDevice)Creates a command subscription object for the given topic.StringgetCommandPublishTopic(org.eclipse.hono.client.command.Command command)Gets the name of the topic that a command should be published to.Subscription.KeygetKey()Gets the key to identify a subscription in the list of subscriptions of an MQTT Endpoint.static Subscription.KeygetKey(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.StringgetRequestPart()Gets the request part of the subscription.static booleanhasCommandEndpointPrefix(String topic)Checks whether the given topic name starts with the command endpoint identifier.-
Methods inherited from class org.eclipse.hono.adapter.mqtt.AbstractSubscription
containsDeviceId, containsTenantId, getAuthenticatedDeviceId, getDeviceId, getEndpoint, getQos, getTenant, getTopic, isAuthenticated, isGatewaySubscriptionForSpecificDevice, logSubscribeFailure, logSubscribeSuccess, logUnsubscribe
-
-
-
-
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 ornull.- Returns:
- The CommandSubscription object or
nullif the topic does not match the rules. - Throws:
NullPointerException- if mqttTopicSub isnull.
-
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 ornull.- Returns:
- The CommandSubscription object or
nullif the topic does not match the rules. - Throws:
NullPointerException- if topic or qos isnull.
-
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:
trueif 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 ornull.- Returns:
- The key or
nullif the topic does not match the rules. - Throws:
NullPointerException- if topic isnull.
-
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 isnull.
-
-