Package org.eclipse.hono.adapter.mqtt
Class MqttContext
- java.lang.Object
-
- org.eclipse.hono.util.MapBasedExecutionContext
-
- org.eclipse.hono.util.MapBasedTelemetryExecutionContext
-
- org.eclipse.hono.adapter.mqtt.MqttContext
-
- All Implemented Interfaces:
org.eclipse.hono.util.ExecutionContext,org.eclipse.hono.util.TelemetryExecutionContext
public final class MqttContext extends org.eclipse.hono.util.MapBasedTelemetryExecutionContextA dictionary of relevant information required during the processing of an MQTT message published by a device.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMqttContext.ErrorHandlingModeModes defining how to handle errors raised when a device publishes a message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacknowledge()Sends a PUBACK for the message to the device.voidapplyMappedTargetAddress(org.eclipse.hono.util.ResourceIdentifier mappedTargetAddress)Apply a mapped targetAddress to this mqtt context.org.eclipse.hono.auth.DeviceauthenticatedDevice()Gets the identity of the authenticated device that has published the message.StringcontentType()Gets the content type of the message payload.StringcorrelationId()Gets the correlation identifier taken either from a corresponding property bag value or the message packet id.io.vertx.mqtt.MqttEndpointdeviceEndpoint()Gets the MQTT endpoint over which the message has been received.StringdeviceId()Gets the identifier of the device that the message originates from.MetricsTags.EndpointTypeendpoint()Gets the endpoint that the message has been published to.static MqttContextfromPublishPacket(io.vertx.mqtt.messages.MqttPublishMessage publishedMessage, io.vertx.mqtt.MqttEndpoint deviceEndpoint, io.opentracing.Span span)Creates a new context for a published message.static MqttContextfromPublishPacket(io.vertx.mqtt.messages.MqttPublishMessage publishedMessage, io.vertx.mqtt.MqttEndpoint deviceEndpoint, io.opentracing.Span span, org.eclipse.hono.auth.Device authenticatedDevice)Creates a new context for a published message.MqttContext.ErrorHandlingModegetErrorHandlingMode(boolean errorSubscriptionExists)Gets the mode defining how to handle errors raised when a device publishes a message.StringgetOrigAddress()org.eclipse.hono.util.QoSgetRequestedQos()io.micrometer.core.instrument.Timer.SamplegetTimer()Gets the object used for measuring the time it takes to process this request.Optional<Duration>getTimeToLive()booleanisAtLeastOnce()Checks if the message has been published using QoS 1.io.vertx.mqtt.messages.MqttPublishMessagemessage()Gets the MQTT message to process.PropertyBagpropertyBag()Gets the property bag object from the property-bag set in the message's topic.voidsetContentType(String contentType)Sets the content type of the message payload.voidsetTimer(io.micrometer.core.instrument.Timer.Sample timer)Sets the object to use for measuring the time it takes to process this request.Stringtenant()Gets the tenant that the device belongs to that published the message.org.eclipse.hono.util.ResourceIdentifiertopic()Gets the topic that the message has been published to.-
Methods inherited from class org.eclipse.hono.util.MapBasedTelemetryExecutionContext
getAuthenticatedDevice
-
Methods inherited from class org.eclipse.hono.util.MapBasedExecutionContext
get, get, getTracingContext, getTracingSpan, put
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Method Detail
-
fromPublishPacket
public static MqttContext fromPublishPacket(io.vertx.mqtt.messages.MqttPublishMessage publishedMessage, io.vertx.mqtt.MqttEndpoint deviceEndpoint, io.opentracing.Span span)
Creates a new context for a published message.- Parameters:
publishedMessage- The MQTT message to process.deviceEndpoint- The endpoint representing the device that has published the message.span- The OpenTracing root span that is used to track the processing of this context.- Returns:
- The context.
- Throws:
NullPointerException- if any of the parameters isnull.
-
fromPublishPacket
public static MqttContext fromPublishPacket(io.vertx.mqtt.messages.MqttPublishMessage publishedMessage, io.vertx.mqtt.MqttEndpoint deviceEndpoint, io.opentracing.Span span, org.eclipse.hono.auth.Device authenticatedDevice)
Creates a new context for a published message.- Parameters:
publishedMessage- The published MQTT message.deviceEndpoint- The endpoint representing the device that has published the message.span- The OpenTracing root span that is used to track the processing of this context.authenticatedDevice- The authenticated device identity (may benull).- Returns:
- The context.
- Throws:
NullPointerException- if any of the parameters except authenticatedDevice isnull.
-
getRequestedQos
public org.eclipse.hono.util.QoS getRequestedQos()
-
message
public io.vertx.mqtt.messages.MqttPublishMessage message()
Gets the MQTT message to process.- Returns:
- The message.
-
deviceEndpoint
public io.vertx.mqtt.MqttEndpoint deviceEndpoint()
Gets the MQTT endpoint over which the message has been received.- Returns:
- The endpoint.
-
authenticatedDevice
public org.eclipse.hono.auth.Device authenticatedDevice()
Gets the identity of the authenticated device that has published the message.- Returns:
- The identity or
nullif the device has not been authenticated.
-
contentType
public String contentType()
Gets the content type of the message payload.The type has either been set via
setContentType(String)or it is the type determined from the message topic's property bag, if it contains a content type.- Returns:
- The type of the message payload or
nullif the type is unknown.
-
setContentType
public void setContentType(String contentType)
Sets the content type of the message payload.This overwrites the content type determined from the message topic's property bag (if any).
- Parameters:
contentType- The type.- Throws:
NullPointerException- if contentType isnull.
-
topic
public org.eclipse.hono.util.ResourceIdentifier topic()
Gets the topic that the message has been published to.- Returns:
- The topic or
nullif the topic could not be parsed into a resource identifier.
-
applyMappedTargetAddress
public void applyMappedTargetAddress(org.eclipse.hono.util.ResourceIdentifier mappedTargetAddress)
Apply a mapped targetAddress to this mqtt context.The device identifier included in the address overrides the device identifier derived from the message topic.
- Parameters:
mappedTargetAddress- The mappedTargetAddress.
-
tenant
public String tenant()
Gets the tenant that the device belongs to that published the message.- Returns:
- The tenant identifier or
nullif the device is not authenticated and the message's topic does not contain a tenant identifier.
-
deviceId
public String deviceId()
Gets the identifier of the device that the message originates from.It is taken from the message topic or, if not set there, from the authenticated device.
In a scenario of a gateway sending a message on behalf of an edge device, the returned identifier is the edge device identifier.
- Returns:
- The device identifier or
nullif the topic of the message does not contain a device identifier and the device is not authenticated.
-
correlationId
public String correlationId()
Gets the correlation identifier taken either from a corresponding property bag value or the message packet id.- Returns:
- The correlation identifier or
nullin case of a QoS 0 message with no corresponding property bag value.
-
propertyBag
public PropertyBag propertyBag()
Gets the property bag object from the property-bag set in the message's topic.- Returns:
- The property bag (which may be empty) or
nullif the topic isnullor empty.
-
endpoint
public MetricsTags.EndpointType endpoint()
Gets the endpoint that the message has been published to.The name is determined from the endpoint path segment of the topic that the message has been published to.
- Returns:
- The endpoint or
nullif the message does not contain a topic.
-
isAtLeastOnce
public boolean isAtLeastOnce()
Checks if the message has been published using QoS 1.- Returns:
trueif the message has been published using QoS 1.
-
acknowledge
public void acknowledge()
Sends a PUBACK for the message to the device.
-
setTimer
public void setTimer(io.micrometer.core.instrument.Timer.Sample timer)
Sets the object to use for measuring the time it takes to process this request.- Parameters:
timer- The timer.
-
getTimer
public io.micrometer.core.instrument.Timer.Sample getTimer()
Gets the object used for measuring the time it takes to process this request.- Returns:
- The timer or
nullif not set.
-
getErrorHandlingMode
public MqttContext.ErrorHandlingMode getErrorHandlingMode(boolean errorSubscriptionExists)
Gets the mode defining how to handle errors raised when a device publishes a message.- Parameters:
errorSubscriptionExists-trueif the device has an error topic subscription.- Returns:
- the effective mode.
-
getOrigAddress
public String getOrigAddress()
- Returns:
- The message topic.
-
-