Interface HasMessage
- All Superinterfaces:
HasMetadata
- All Known Implementing Classes:
DefaultEntityHelper.DeserializingMessageWithEntity
,DefaultEntityHelper.MessageWithEntity
,DeserializingMessage
,Message
,Schedule
,WebRequest
,WebResponse
Message
instance.
This abstraction allows access to common message properties (payload, metadata, timestamp, ID, routing key) without
requiring the caller to know if they're working with a Message
, Schedule
, or a wrapped domain
object.
Implementations must return a consistent toMessage()
representation and may override routing logic using
annotations such as RoutingKey
.
Responsibilities
- Expose payload and metadata via delegation
- Enable routing key extraction via
computeRoutingKey()
- Support typed deserialization using
getPayloadAs(Type)
- See Also:
-
Field Summary
FieldsFields inherited from interface io.fluxcapacitor.common.api.HasMetadata
FINAL_CHUNK
-
Method Summary
Modifier and TypeMethodDescriptionComputes the default routing key for this message.default String
Returns the unique ID of the underlying message.default <R> R
Retrieves the message payload, deserializing if necessary, cast to the expected type.default <R> R
getPayloadAs
(Type type) Retrieves the message payload, deserializing if necessary and optionally converted to the given type.default Class
<?> Returns the runtime class of the payload object, orVoid.class
if the payload isnull
.getRoutingKey
(String propertyName) Attempts to resolve the routing key from the given property name.getRoutingKey
(String propertyName, boolean warnIfMissing) Attempts to resolve the routing key from the specified property name.default Instant
Returns the timestamp at which the message was created or published.Returns the underlyingMessage
representation of this object.Methods inherited from interface io.fluxcapacitor.common.api.HasMetadata
chunked, getMetadata, lastChunk
-
Field Details
-
warnedAboutMissingProperty
-
-
Method Details
-
toMessage
Message toMessage()Returns the underlyingMessage
representation of this object.- Returns:
- the
Message
backing this instance
-
getPayload
default <R> R getPayload()Retrieves the message payload, deserializing if necessary, cast to the expected type.By default, this delegates to
toMessage().getPayload()
.- Type Parameters:
R
- the expected payload type- Returns:
- the deserialized payload
-
getPayloadAs
Retrieves the message payload, deserializing if necessary and optionally converted to the given type.By default, this performs a conversion of the payload using
JsonUtils
.- Type Parameters:
R
- the expected payload type- Returns:
- the payload converted to the given type
-
getPayloadClass
Returns the runtime class of the payload object, orVoid.class
if the payload isnull
.- Returns:
- the payload's class
-
getMessageId
Returns the unique ID of the underlying message.- Returns:
- the message ID
-
getTimestamp
Returns the timestamp at which the message was created or published.- Returns:
- the message timestamp
-
computeRoutingKey
Computes the default routing key for this message.The key is extracted based on the
RoutingKey
annotation on the payload type or one of its properties. If none is found, and the message is aSchedule
, the schedule ID is used instead.- Returns:
- the resolved routing key, if available
-
getRoutingKey
Attempts to resolve the routing key from the given property name.This checks metadata first, then the payload itself. Logs a warning the first time a property is missing for a given payload class.
- Parameters:
propertyName
- the name of the field, method, or metadata key to use- Returns:
- the routing key if found
-
getRoutingKey
Attempts to resolve the routing key from the specified property name.Optionally logs a warning if the key is missing, but only once per class-property combination.
- Parameters:
propertyName
- the property to use for routingwarnIfMissing
- whether to log a warning on first failure- Returns:
- the routing key if resolved
-