Class Message
java.lang.Object
io.fluxzero.sdk.common.Message
- All Implemented Interfaces:
HasMetadata, HasMessage
- Direct Known Subclasses:
Schedule, WebRequest, WebResponse
Represents a unit of communication within the Fluxzero Runtime, wrapping a payload and its metadata.
A Message serves as the base class for all messages in Fluxzero (e.g., commands, events, queries, web
requests). It contains a strongly typed payload, immutable metadata, a globally unique message ID, and a timestamp.
Messages can be enriched with metadata, transformed with a new payload, or serialized for transmission.
Key Features
- Immutable, with
withXandaddMetadatamethods for safe transformation - Supports auto-generation of message ID and timestamp if not provided
- Lazy routing key computation via
getRoutingKey()
- See Also:
-
Field Summary
Fields inherited from interface HasMessage
warnedAboutMissingPropertyFields inherited from interface HasMetadata
FINAL_CHUNK -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a message with the given payload and empty metadata.Constructs a message with the given payload and metadata.Full constructor for internal use and deserialization. -
Method Summary
Modifier and TypeMethodDescriptionaddMetadata(Metadata metadata) Returns a new message with the combined metadata.addMetadata(Object... keyValues) Adds multiple metadata entries.addMetadata(String key, Object value) Adds a single metadata entry.addMetadata(Map<String, ?> values) Adds metadata from a given map.Attaches a user object to the metadata using the configuredUserProvider.static MessageConverts any object into aMessage.<R> RReturns the strongly typed payload of the message.serialize(Serializer serializer) Serializes this message to aSerializedMessageusing the providedSerializer.Returns the underlyingMessagerepresentation of this object.withPayload(Object payload) Returns a new message instance with the provided payload and existing metadata, ID, and timestamp.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HasMessage
computeRoutingKey, getMessageId, getPayloadAs, getPayloadClass, getRoutingKey, getRoutingKey, getTimestampMethods inherited from interface HasMetadata
chunked, getMetadata, lastChunk
-
Constructor Details
-
Message
Constructs a message with the given payload and empty metadata.- Parameters:
payload- the message payload
-
Message
-
Message
@ConstructorProperties({"payload","metadata","messageId","timestamp"}) public Message(Object payload, Metadata metadata, String messageId, Instant timestamp) Full constructor for internal use and deserialization.- Parameters:
payload- the payloadmetadata- metadata for the messagemessageId- optional unique ID; auto-generated ifnulltimestamp- optional creation time; defaults to current time ifnull
-
-
Method Details
-
asMessage
Converts any object into aMessage. If the object already implementsHasMessage, the existing message is returned.- Parameters:
object- the input object to wrap- Returns:
- a
Messageinstance
-
getPayload
public <R> R getPayload()Returns the strongly typed payload of the message.- Specified by:
getPayloadin interfaceHasMessage- Type Parameters:
R- the expected type of the payload- Returns:
- the payload
-
toMessage
Description copied from interface:HasMessageReturns the underlyingMessagerepresentation of this object.- Specified by:
toMessagein interfaceHasMessage- Returns:
- the
Messagebacking this instance
-
withPayload
-
addMetadata
-
addMetadata
-
addMetadata
-
addMetadata
-
addUser
Attaches a user object to the metadata using the configuredUserProvider. -
serialize
Serializes this message to aSerializedMessageusing the providedSerializer.
-