Class DeserializingMessage
- All Implemented Interfaces:
HasMetadata
,HasMessage
- Direct Known Subclasses:
DefaultEntityHelper.DeserializingMessageWithEntity
Message
that supports lazy deserialization, context caching, type adaptation, and batch-level
execution utilities.
DeserializingMessage
combines a SerializedMessage
with deserialization and routing logic while
maintaining the original message context (type, topic, metadata, and payload).
Key Features
- Supports on-demand deserialization of a
Message
- Provides thread-local access to the message that is currently being handled
- Allows attaching resources to the current message or message batch/li>
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic MessageFormatter
The formatter used to produce a human-readable representation of this message, primarily for logging or debugging.Fields inherited from interface io.fluxcapacitor.javaclient.common.HasMessage
warnedAboutMissingProperty
Fields inherited from interface io.fluxcapacitor.common.api.HasMetadata
FINAL_CHUNK
-
Constructor Summary
ConstructorsModifierConstructorDescriptionDeserializingMessage
(SerializedMessage message, Function<Type, Object> payload, MessageType messageType, String topic, Serializer serializer) DeserializingMessage
(@NonNull Message message, MessageType messageType, Serializer serializer) DeserializingMessage
(@NonNull Message message, MessageType messageType, String topic, Serializer serializer) protected
DeserializingMessage
(@NonNull DeserializingMessage input) DeserializingMessage
(DeserializingObject<byte[], SerializedMessage> delegate, MessageType messageType, String topic, Serializer serializer) -
Method Summary
Modifier and TypeMethodDescription<T> T
apply
(Function<DeserializingMessage, T> action) <T> T
computeContextIfAbsent
(Class<T> contextKey, Function<DeserializingMessage, ? extends T> provider) static <K,
V> V computeForBatch
(K key, BiFunction<? super K, ? super V, ? extends V> function) static <K,
V> V computeForBatchIfAbsent
(K key, Function<? super K, ? extends V> function) static <V> V
getBatchResource
(Object key) static <V> V
getBatchResourceOrDefault
(Object key, V defaultValue) static DeserializingMessage
Returns the currentDeserializingMessage
being processed in this thread, ornull
if none is set.getIndex()
Returns the unique ID of the underlying message.Returns theMetadata
associated with this object.static Optional
<DeserializingMessage> Returns the currentDeserializingMessage
being processed in this thread, if available.<V> V
Retrieves the message payload, deserializing if necessary, cast to the expected type.<R> R
getPayloadAs
(Type type) Retrieves the message payload, deserializing if necessary and optionally converted to the given type.Class
<?> Returns the runtime class of the payload object, orVoid.class
if the payload isnull
.Returns the timestamp at which the message was created or published.getType()
static Stream
<DeserializingMessage> handleBatch
(Stream<DeserializingMessage> batch) boolean
void
run
(Consumer<DeserializingMessage> task) Returns the underlyingMessage
representation of this object.toString()
static void
whenBatchCompletes
(ThrowingConsumer<Throwable> executable) withMetadata
(Metadata metadata) withPayload
(Object payload) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.common.HasMessage
computeRoutingKey, getRoutingKey, getRoutingKey
Methods inherited from interface io.fluxcapacitor.common.api.HasMetadata
chunked, lastChunk
-
Field Details
-
messageFormatter
The formatter used to produce a human-readable representation of this message, primarily for logging or debugging. By default, this usesMessageFormatter.DEFAULT
.In advanced scenarios, users may replace this field with a custom
MessageFormatter
implementation to modify how deserializing messages are rendered (e.g., to include metadata or correlation IDs).
-
-
Constructor Details
-
DeserializingMessage
public DeserializingMessage(SerializedMessage message, Function<Type, Object> payload, MessageType messageType, String topic, Serializer serializer) -
DeserializingMessage
public DeserializingMessage(DeserializingObject<byte[], SerializedMessage> delegate, MessageType messageType, String topic, Serializer serializer) -
DeserializingMessage
public DeserializingMessage(@NonNull @NonNull Message message, MessageType messageType, Serializer serializer) -
DeserializingMessage
public DeserializingMessage(@NonNull @NonNull Message message, MessageType messageType, String topic, Serializer serializer) -
DeserializingMessage
-
-
Method Details
-
run
-
apply
-
toMessage
Description copied from interface:HasMessage
Returns the underlyingMessage
representation of this object.- Specified by:
toMessage
in interfaceHasMessage
- Returns:
- the
Message
backing this instance
-
getMetadata
Description copied from interface:HasMetadata
Returns theMetadata
associated with this object.- Specified by:
getMetadata
in interfaceHasMetadata
- Returns:
- metadata attached to this instance; never
null
-
withMetadata
-
withPayload
-
getMessageId
Description copied from interface:HasMessage
Returns the unique ID of the underlying message.- Specified by:
getMessageId
in interfaceHasMessage
- Returns:
- the message ID
-
getIndex
-
getTimestamp
Description copied from interface:HasMessage
Returns the timestamp at which the message was created or published.- Specified by:
getTimestamp
in interfaceHasMessage
- Returns:
- the message timestamp
-
isDeserialized
public boolean isDeserialized() -
getPayload
public <V> V getPayload()Description copied from interface:HasMessage
Retrieves the message payload, deserializing if necessary, cast to the expected type.By default, this delegates to
toMessage().getPayload()
.- Specified by:
getPayload
in interfaceHasMessage
- Type Parameters:
V
- the expected payload type- Returns:
- the deserialized payload
-
getPayloadAs
Description copied from interface:HasMessage
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
.- Specified by:
getPayloadAs
in interfaceHasMessage
- Type Parameters:
R
- the expected payload type- Returns:
- the payload converted to the given type
-
getPayloadClass
Description copied from interface:HasMessage
Returns the runtime class of the payload object, orVoid.class
if the payload isnull
.- Specified by:
getPayloadClass
in interfaceHasMessage
- Returns:
- the payload's class
-
getType
-
getSerializedObject
-
withData
-
computeContextIfAbsent
public <T> T computeContextIfAbsent(Class<T> contextKey, Function<DeserializingMessage, ? extends T> provider) -
getCurrent
Returns the currentDeserializingMessage
being processed in this thread, ornull
if none is set.This method provides direct (nullable) access to the thread-local message context. Prefer
getOptionally()
when you want to safely handle absence of context.Note: This method should typically be called only inside handler code or interceptors where a
DeserializingMessage
is known to be active.- Returns:
- the current message or
null
if no message is being processed - See Also:
-
getOptionally
Returns the currentDeserializingMessage
being processed in this thread, if available.This method is safe to call in any thread and will return
Optional.empty()
if no message is currently being handled. It is particularly useful for utility classes or exception handlers that want to conditionally access message metadata.Example
Optional<DeserializingMessage> message = DeserializingMessage.getOptionally(); message.map(DeserializingMessage::getPayloadType) .ifPresent(type -> log.debug("Handling message of type {}", type));
- Returns:
- an
Optional
containing the current message or empty if none is set - See Also:
-
toString
-
handleBatch
-
whenBatchCompletes
-
computeForBatch
-
computeForBatchIfAbsent
-
getBatchResource
-
getBatchResourceOrDefault
-