Package org.eclipse.hono.adapter.mqtt
Class ErrorSubscription
- java.lang.Object
-
- org.eclipse.hono.adapter.mqtt.AbstractSubscription
-
- org.eclipse.hono.adapter.mqtt.ErrorSubscription
-
- All Implemented Interfaces:
Subscription
public final class ErrorSubscription extends AbstractSubscription
A device's MQTT subscription for error messages.Supported topic filters:
error|e/[TENANT]/[DEVICE_ID]/#
(empty tenant/device segments can also be omitted)Examples:
error/DEFAULT_TENANT/4711/#unauthenticated deviceerror///#- authenticated devicee///#- authenticated device using short name
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.hono.adapter.mqtt.Subscription
Subscription.Key
-
-
Field Summary
Fields Modifier and Type Field Description static StringCOMMAND_RESPONSE_ENDPOINTEndpoint used in the topic of the published error message identifying the message that lead to the error as a command response message.static StringCOMMAND_RESPONSE_ENDPOINT_SHORTShort variant of the endpoint used in the topic of the published error message identifying the message that lead to the error as a command response message.static StringERROR_ENDPOINTThe name of the error endpoint.static StringERROR_ENDPOINT_SHORTThe short name of the error endpoint.static StringUNKNOWN_ENDPOINTEndpoint used in the topic of the published error message identifying the topic endpoint in the message that lead to the error as unknown.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ErrorSubscriptionfromTopic(io.vertx.mqtt.MqttTopicSubscription mqttTopicSub, org.eclipse.hono.auth.Device authenticatedDevice)Creates a error subscription object for the given topic.static ErrorSubscriptionfromTopic(String topic, io.netty.handler.codec.mqtt.MqttQoS qos, org.eclipse.hono.auth.Device authenticatedDevice)Creates a error subscription object for the given topic.StringgetErrorPublishTopic(String messageEndpoint, String deviceId, String correlationId, int errorCode)Gets the name of the topic that an error should be published to.StringgetErrorPublishTopic(MqttContext context, int errorCode)Gets the name of the topic that an error should be published to.Subscription.KeygetKey()Gets the key to identify a subscription in the list of (same-type) subscriptions of an MQTT Endpoint.static Subscription.KeygetKey(String tenantId, String deviceId)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)Gets the key to identify an error subscription in the list of error subscriptions of an MQTT Endpoint.static booleanhasErrorEndpointPrefix(String topic)Checks whether the given topic name starts with the error 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
-
-
-
-
Field Detail
-
ERROR_ENDPOINT
public static final String ERROR_ENDPOINT
The name of the error endpoint.- See Also:
- Constant Field Values
-
ERROR_ENDPOINT_SHORT
public static final String ERROR_ENDPOINT_SHORT
The short name of the error endpoint.- See Also:
- Constant Field Values
-
UNKNOWN_ENDPOINT
public static final String UNKNOWN_ENDPOINT
Endpoint used in the topic of the published error message identifying the topic endpoint in the message that lead to the error as unknown.- See Also:
- Constant Field Values
-
COMMAND_RESPONSE_ENDPOINT
public static final String COMMAND_RESPONSE_ENDPOINT
Endpoint used in the topic of the published error message identifying the message that lead to the error as a command response message.- See Also:
- Constant Field Values
-
COMMAND_RESPONSE_ENDPOINT_SHORT
public static final String COMMAND_RESPONSE_ENDPOINT_SHORT
Short variant of the endpoint used in the topic of the published error message identifying the message that lead to the error as a command response message.- See Also:
- Constant Field Values
-
-
Method Detail
-
fromTopic
public static ErrorSubscription fromTopic(io.vertx.mqtt.MqttTopicSubscription mqttTopicSub, org.eclipse.hono.auth.Device authenticatedDevice)
Creates a error 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 error subscription object.
- Parameters:
mqttTopicSub- The MqttTopicSubscription request from device for error subscription.authenticatedDevice- The authenticated device ornull.- Returns:
- The ErrorSubscription object or
nullif the topic does not match the rules. - Throws:
NullPointerException- if mqttTopicSub isnull.
-
fromTopic
public static ErrorSubscription fromTopic(String topic, io.netty.handler.codec.mqtt.MqttQoS qos, org.eclipse.hono.auth.Device authenticatedDevice)
Creates a error 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 error subscription object.
- Parameters:
topic- The topic to subscribe for errors.qos- The quality-of-service level for the subscription.authenticatedDevice- The authenticated device ornull.- Returns:
- The ErrorSubscription object or
nullif the topic does not match the rules. - Throws:
NullPointerException- if topic or qos isnull.
-
hasErrorEndpointPrefix
public static boolean hasErrorEndpointPrefix(String topic)
Checks whether the given topic name starts with the error endpoint identifier.- Parameters:
topic- The topic to check.- Returns:
trueif the topic has the error endpoint prefix.
-
getKey
public static Subscription.Key getKey(String topic, org.eclipse.hono.auth.Device authenticatedDevice)
Gets the key to identify an error subscription in the list of error subscriptions of an MQTT Endpoint.Only returns a non-null key if the topic is valid.
- Parameters:
topic- The topic to subscribe for errors.authenticatedDevice- The authenticated device ornull.- Returns:
- The key or
nullif the topic does not match the rules. - Throws:
NullPointerException- if topic isnull.
-
getKey
public static Subscription.Key getKey(String tenantId, String deviceId)
Gets the key to identify a subscription in the list of subscriptions of an MQTT Endpoint.- Parameters:
tenantId- The tenant identifier.deviceId- The device identifier.- Returns:
- The key.
- Throws:
NullPointerException- If tenantId or deviceId isnull.
-
getKey
public Subscription.Key getKey()
Description copied from interface:SubscriptionGets the key to identify a subscription in the list of (same-type) subscriptions of an MQTT Endpoint.- Returns:
- The key.
-
getErrorPublishTopic
public String getErrorPublishTopic(MqttContext context, int errorCode)
Gets the name of the topic that an error should be published to.- Parameters:
context- The context in which the error occurred.errorCode- The error code.- Returns:
- The topic name.
- Throws:
NullPointerException- if context isnull.
-
getErrorPublishTopic
public String getErrorPublishTopic(String messageEndpoint, String deviceId, String correlationId, int errorCode)
Gets the name of the topic that an error should be published to.- Parameters:
messageEndpoint- The endpoint of the message for which to send the error (e.g. "telemetry").deviceId- The identifier of the device for which to send the error (may benull). The value will be used if it is not empty and differs from the (not empty) device identifier of this error subscription.correlationId- The identifier of the message for which to send the error (may benull).errorCode- The error code.- Returns:
- The topic name.
-
-