Class Message
java.lang.Object
io.fluxcapacitor.javaclient.common.Message
- All Implemented Interfaces:
HasMetadata
,HasMessage
- Direct Known Subclasses:
Schedule
,WebRequest
,WebResponse
Represents a unit of communication within the Flux platform, wrapping a payload and its metadata.
A Message
serves as the base class for all messages in Flux (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
withX
andaddMetadata
methods 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 io.fluxcapacitor.javaclient.common.HasMessage
warnedAboutMissingProperty
Fields inherited from interface io.fluxcapacitor.common.api.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 Message
Converts any object into aMessage
.<R> R
Returns the strongly typed payload of the message.serialize
(Serializer serializer) Serializes this message to aSerializedMessage
using the providedSerializer
.Returns the underlyingMessage
representation 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.common.HasMessage
computeRoutingKey, getMessageId, getPayloadAs, getPayloadClass, getRoutingKey, getRoutingKey, getTimestamp
Methods inherited from interface io.fluxcapacitor.common.api.HasMetadata
chunked, getMetadata, lastChunk
-
Constructor Details
-
Message
Constructs a message with the given payload and empty metadata.- Parameters:
payload
- the message payload
-
Message
Constructs a message with the given payload and metadata.- Parameters:
payload
- the message payloadmetadata
- the associated metadata
-
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 ifnull
timestamp
- 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
Message
instance
-
getPayload
public <R> R getPayload()Returns the strongly typed payload of the message.- Specified by:
getPayload
in interfaceHasMessage
- Type Parameters:
R
- the expected type of the payload- Returns:
- the payload
-
toMessage
Description copied from interface:HasMessage
Returns the underlyingMessage
representation of this object.- Specified by:
toMessage
in interfaceHasMessage
- Returns:
- the
Message
backing this instance
-
withPayload
Returns a new message instance with the provided payload and existing metadata, ID, and timestamp. -
addMetadata
Returns a new message with the combined metadata. -
addMetadata
Adds a single metadata entry. -
addMetadata
Adds multiple metadata entries. -
addMetadata
Adds metadata from a given map. -
addUser
Attaches a user object to the metadata using the configuredUserProvider
. -
serialize
Serializes this message to aSerializedMessage
using the providedSerializer
.
-