Class EventBusMessage
- java.lang.Object
-
- org.eclipse.hono.util.EventBusMessage
-
public class EventBusMessage extends Object
A wrapper around a JSON object which can be used to convey request and/or response information for Hono API operations via the vert.x event bus.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static EventBusMessage
forOperation(String operation)
Creates a new (request) message for an operation.static EventBusMessage
forOperation(org.apache.qpid.proton.message.Message message)
Creates a new (request) message from an AMQP 1.0 message.static EventBusMessage
forStatusCode(int status)
Creates a new (response) message for a status code.static EventBusMessage
fromJson(io.vertx.core.json.JsonObject json)
Creates a new message from a JSON object.String
getCacheDirective()
Gets the value of the cache directive property.Object
getCorrelationId()
Gets the value of the correlation identifier property.String
getDeviceId()
Gets the value of the device identifier property.String
getGatewayId()
Gets the value of the gateway identifier property.io.vertx.core.json.JsonObject
getJsonPayload()
Gets the value of the payload property.io.vertx.core.json.JsonObject
getJsonPayload(io.vertx.core.json.JsonObject defaultValue)
Gets the value of the payload property.String
getObjectId()
Gets the value of the object identifier property.String
getOperation()
Gets the operation to invoke.<T> T
getProperty(String key)
Gets a property value.String
getReplyToAddress()
Gets the value of the reply-to address property.String
getResourceVersion()
Gets the value of the cache resource version property.EventBusMessage
getResponse(int status)
Creates a new response message in reply to this (request) message.io.opentracing.SpanContext
getSpanContext()
Gets the OpenTracingSpanContext
that has been set on this message.Integer
getStatus()
Gets the status code indicating the outcome of the invocation of the operation.String
getTenant()
Gets the value of the tenant identifier property.boolean
hasErrorStatus()
Checks if the status code indicating the outcome of the invocation of the operation represents an error.boolean
hasResponseProperties()
Checks if this (response) message has all properties required for successful delivery to the client.EventBusMessage
setCacheDirective(CacheDirective directive)
Adds a property for the cache directive.EventBusMessage
setCorrelationId(Object id)
Adds a property for the correlation identifier.EventBusMessage
setCorrelationId(org.apache.qpid.proton.message.Message message)
Adds a property for the correlation identifier.EventBusMessage
setDeviceId(String deviceId)
Adds a property for the device identifier.EventBusMessage
setDeviceId(org.apache.qpid.proton.message.Message msg)
Adds a property for the device identifier.EventBusMessage
setGatewayId(String id)
Adds a property for the gateway identifier.EventBusMessage
setGatewayId(org.apache.qpid.proton.message.Message msg)
Adds a property for the gateway identifier.EventBusMessage
setJsonPayload(io.vertx.core.json.JsonObject payload)
Adds a property for the request/response payload.EventBusMessage
setJsonPayload(org.apache.qpid.proton.message.Message msg)
Adds a property for the request/response payload.EventBusMessage
setProperty(String name, Object value)
Adds a property with a value.EventBusMessage
setReplyToAddress(String address)
Adds a property for the address that responses to this (request) message should be sent.EventBusMessage
setReplyToAddress(org.apache.qpid.proton.message.Message msg)
Adds a property for the address that responses to this (request) message should be sent to.EventBusMessage
setResourceVersion(String version)
Adds a property for the resource version option.void
setSpanContext(io.opentracing.SpanContext spanContext)
Sets an OpenTracingSpanContext
on this message.EventBusMessage
setStringProperty(String name, org.apache.qpid.proton.message.Message msg)
Adds a property with a value from an AMQP message.EventBusMessage
setTenant(String tenantId)
Adds a property for the tenant identifier.EventBusMessage
setTenant(org.apache.qpid.proton.message.Message msg)
Adds a property for the tenant identifier.io.vertx.core.json.JsonObject
toJson()
Creates a JSON object representation of this message.
-
-
-
Method Detail
-
forOperation
public static EventBusMessage forOperation(String operation)
Creates a new (request) message for an operation.- Parameters:
operation
- The name of the operation.- Returns:
- The request message.
- Throws:
NullPointerException
- if operation isnull
.
-
forOperation
public static EventBusMessage forOperation(org.apache.qpid.proton.message.Message message)
Creates a new (request) message from an AMQP 1.0 message.The operation will be determined from the message's subject.
- Parameters:
message
- The AMQP message.- Returns:
- The request message.
- Throws:
NullPointerException
- if message isnull
.IllegalArgumentException
- if the message has no subject set.
-
forStatusCode
public static EventBusMessage forStatusCode(int status)
Creates a new (response) message for a status code.- Parameters:
status
- The status code indicating the outcome of the operation.- Returns:
- The response message.
-
getResponse
public EventBusMessage getResponse(int status)
Creates a new response message in reply to this (request) message.This method copies the following properties from the request to the response (if not
null
):- status
- operation
- correlationId
- replyToAddress
- tenant
- Parameters:
status
- The status code indicating the outcome of the operation.- Returns:
- The response message.
- Throws:
NullPointerException
- if request isnull
.
-
fromJson
public static EventBusMessage fromJson(io.vertx.core.json.JsonObject json)
Creates a new message from a JSON object.Whether the created message represents a request or a response is determined by the status and operation properties.
- Parameters:
json
- The JSON object.- Returns:
- The message.
-
hasResponseProperties
public boolean hasResponseProperties()
Checks if this (response) message has all properties required for successful delivery to the client.- Returns:
true
if this message hasnon-null
values for properties operation, replyToAddress and correlationId.
-
getOperation
public String getOperation()
Gets the operation to invoke.- Returns:
- The operation of
null
if this is a response message.
-
getStatus
public Integer getStatus()
Gets the status code indicating the outcome of the invocation of the operation.- Returns:
- The status code or
null
if this is a request message.
-
hasErrorStatus
public boolean hasErrorStatus()
Checks if the status code indicating the outcome of the invocation of the operation represents an error.- Returns:
true
if this is a response message and the status code represents an error.
-
setReplyToAddress
public EventBusMessage setReplyToAddress(String address)
Adds a property for the address that responses to this (request) message should be sent.The property will only be added if the value is not
null
.- Parameters:
address
- The address.- Returns:
- This message for chaining.
-
setReplyToAddress
public EventBusMessage setReplyToAddress(org.apache.qpid.proton.message.Message msg)
Adds a property for the address that responses to this (request) message should be sent to.The property will only be added if the AMQP message contains a non-
null
reply-to property.- Parameters:
msg
- The AMQP message to retrieve the value from.- Returns:
- This message for chaining.
-
getReplyToAddress
public String getReplyToAddress()
Gets the value of the reply-to address property.- Returns:
- The value or
null
if not set.
-
setTenant
public EventBusMessage setTenant(String tenantId)
Adds a property for the tenant identifier.The property will only be added if the value is not
null
.- Parameters:
tenantId
- The tenant identifier.- Returns:
- This message for chaining.
-
setTenant
public EventBusMessage setTenant(org.apache.qpid.proton.message.Message msg)
Adds a property for the tenant identifier.The property will only be added if the AMQP message contains a non-
null
tenant identifier.- Parameters:
msg
- The AMQP message to retrieve the value from.- Returns:
- This message for chaining.
-
getTenant
public String getTenant()
Gets the value of the tenant identifier property.- Returns:
- The value or
null
if not set.
-
setDeviceId
public EventBusMessage setDeviceId(String deviceId)
Adds a property for the device identifier.The property will only be added if the value is not
null
.- Parameters:
deviceId
- The device identifier.- Returns:
- This message for chaining.
-
setDeviceId
public EventBusMessage setDeviceId(org.apache.qpid.proton.message.Message msg)
Adds a property for the device identifier.The property will only be added if the AMQP message contains a non-
null
device identifier.- Parameters:
msg
- The AMQP message to retrieve the value from.- Returns:
- This message for chaining.
-
getDeviceId
public String getDeviceId()
Gets the value of the device identifier property.- Returns:
- The value or
null
if not set.
-
getObjectId
public String getObjectId()
Gets the value of the object identifier property.- Returns:
- The value or
null
if not set.
-
setJsonPayload
public EventBusMessage setJsonPayload(io.vertx.core.json.JsonObject payload)
Adds a property for the request/response payload.The property will only be added if the value is not
null
.- Parameters:
payload
- The payload.- Returns:
- This message for chaining.
-
setJsonPayload
public EventBusMessage setJsonPayload(org.apache.qpid.proton.message.Message msg)
Adds a property for the request/response payload.The property will only be added if the AMQP message contains a JSON payload.
- Parameters:
msg
- The AMQP message to retrieve the payload from.- Returns:
- This message for chaining.
- Throws:
io.vertx.core.json.DecodeException
- if the payload of the AMQP message does not contain proper JSON.
-
getJsonPayload
public io.vertx.core.json.JsonObject getJsonPayload()
Gets the value of the payload property.- Returns:
- The value or
null
if not set.
-
getJsonPayload
public io.vertx.core.json.JsonObject getJsonPayload(io.vertx.core.json.JsonObject defaultValue)
Gets the value of the payload property.- Parameters:
defaultValue
- The default value.- Returns:
- The value of the payload property or the given default value if not set.
-
setGatewayId
public EventBusMessage setGatewayId(String id)
Adds a property for the gateway identifier.The property will only be added if the value is not
null
.- Parameters:
id
- The gateway identifier.- Returns:
- This message for chaining.
-
setGatewayId
public EventBusMessage setGatewayId(org.apache.qpid.proton.message.Message msg)
Adds a property for the gateway identifier.The property will only be added if the AMQP message contains a non-
null
gateway identifier.- Parameters:
msg
- The AMQP message to retrieve the value from.- Returns:
- This message for chaining.
-
getGatewayId
public String getGatewayId()
Gets the value of the gateway identifier property.- Returns:
- The value or
null
if not set.
-
setCacheDirective
public EventBusMessage setCacheDirective(CacheDirective directive)
Adds a property for the cache directive.The property will only be added if the value is not
null
.- Parameters:
directive
- The cache directive.- Returns:
- This message for chaining.
-
getCacheDirective
public String getCacheDirective()
Gets the value of the cache directive property.- Returns:
- The value or
null
if not set.
-
setCorrelationId
public EventBusMessage setCorrelationId(org.apache.qpid.proton.message.Message message)
Adds a property for the correlation identifier.The value of the property is set
- to the AMQP message's correlation identifier, if not
null
, or - to the AMQP message's message identifier, if not
null
.
- Parameters:
message
- The AMQP message to retrieve the value from.- Returns:
- This message for chaining.
- Throws:
IllegalArgumentException
- if the message doesn't contain a correlation id nor a message id.
- to the AMQP message's correlation identifier, if not
-
setCorrelationId
public EventBusMessage setCorrelationId(Object id)
Adds a property for the correlation identifier.The property will only be added if the value is not
null
.- Parameters:
id
- The correlation identifier.- Returns:
- This message for chaining.
- Throws:
IllegalArgumentException
- if the identifier is neither aString
nor anUnsignedLong
nor aUUID
nor aBinary
.
-
getCorrelationId
public Object getCorrelationId()
Gets the value of the correlation identifier property.- Returns:
- The value or
null
if not set.
-
setResourceVersion
public EventBusMessage setResourceVersion(String version)
Adds a property for the resource version option.The property will only be added if the value is not
null
.- Parameters:
version
- The version value.- Returns:
- This message for chaining.
-
getResourceVersion
public String getResourceVersion()
Gets the value of the cache resource version property.- Returns:
- The value or
null
if not set.
-
setProperty
public EventBusMessage setProperty(String name, Object value)
Adds a property with a value.The property will only be added if the value is not
null
.- Parameters:
name
- The name of the property.value
- the value to set.- Returns:
- This message for chaining.
- Throws:
NullPointerException
- if name isnull
.
-
setStringProperty
public EventBusMessage setStringProperty(String name, org.apache.qpid.proton.message.Message msg)
Adds a property with a value from an AMQP message.The property will only be added if the AMQP message contains a non-
null
application property of the given name.- Parameters:
name
- The name of the property.msg
- The AMQP message to retrieve the value from.- Returns:
- This message for chaining.
-
getProperty
public <T> T getProperty(String key)
Gets a property value.- Type Parameters:
T
- The type of the field.- Parameters:
key
- The name of the property.- Returns:
- The property value or
null
if no such property exists or is not of the expected type. - Throws:
NullPointerException
- if key isnull
.
-
setSpanContext
public void setSpanContext(io.opentracing.SpanContext spanContext)
Sets an OpenTracingSpanContext
on this message.This may be the tracing context associated with the (request) message for which this
EventBusMessage
was created. The span context should be used as the parent context of each OpenTracingSpan
that is created as part of processing this event bus message.Note: the span context instance will not get serialized when sending this event bus message over the vert.x event bus!
- Parameters:
spanContext
- TheSpanContext
to set (may be null).
-
getSpanContext
public io.opentracing.SpanContext getSpanContext()
Gets the OpenTracingSpanContext
that has been set on this message.The span context should be used as the parent context of each OpenTracing
Span
that is created as part of processing this event bus message.- Returns:
SpanContext
ornull
.
-
toJson
public io.vertx.core.json.JsonObject toJson()
Creates a JSON object representation of this message.The
fromJson(JsonObject)
method can be used to create aEventBusMethod
from its JSON representation.- Returns:
- The JSOn object.
-
-