Interface CorrelationDataProvider
- All Known Implementing Classes:
DefaultCorrelationDataProvider
Correlation metadata is used to propagate contextual information (e.g. trace IDs, user info, client IDs) across messages within the same logical execution chain.
When a message is dispatched, the active CorrelationDataProvider is queried to generate key-value pairs that
are added to the message's metadata. These entries can then be accessed by downstream handlers to maintain
traceability and context awareness.
A CorrelationDataProvider may extract metadata based on:
- The
DeserializingMessagecurrently being handled - The
SerializedMessagemost recently published - The
Clientthat is processing the message - The
MessageTypeof the outgoing message
Standard Metadata Keys
The correlation data map may include the following keys:$applicationId– ID of the application this client belongs to (optional)$clientId– Unique identifier for this Fluxzero client instance$clientName– Logical name of the client (e.g. "service-A")$consumer– Consumer name of the currentTracker, if active$tracker– Unique ID of the currentTracker, if active$correlationId– ID used to correlate this message with the currently handled message (message index or ID if index is unavailable)$traceId– ID representing the trace this message belongs to (usually inherited from the message root)$trigger– Fully qualified class name of the message that triggered this one$triggerType– Type of the triggering message (e.g. COMMAND, QUERY, etc.)$invocation– ID of the current handlerInvocation, if any
Multiple providers can be composed using andThen(CorrelationDataProvider) to combine metadata from multiple sources.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault CorrelationDataProviderChains this provider with another, returning a composed provider that merges the metadata from both.default StringRetrieves the key used to identify the application ID in correlation metadata.default StringRetrieves the key representing the client identifier in the correlation metadata.default StringRetrieves the key associated with the client's name from the correlation metadata.default StringRetrieves the consumer key used to identify the consumer of a message.Returns correlation metadata based on the current message being handled (if any).getCorrelationData(DeserializingMessage currentMessage) Returns correlation metadata derived from the current deserializing message.getCorrelationData(Client client, SerializedMessage currentMessage, MessageType messageType) Returns correlation metadata derived from a serialized message and optional context.default StringReturns the key used for identifying the correlation ID within the metadata.default StringRetrieves the key used to identify the delay metadata within correlation data.default StringRetrieves the key associated with the invocation context within the correlation metadata.default StringReturns the key used to identify the trace ID in correlation metadata.default StringRetrieves the key representing the tracker component in correlation metadata.default StringRetrieves the trigger key used to identify the triggering context for correlation metadata.default StringReturns the key associated with the trigger type in the correlation data.
-
Method Details
-
getCorrelationData
Returns correlation metadata based on the current message being handled (if any).Delegates to
getCorrelationData(DeserializingMessage)using the current thread-localDeserializingMessage.- Returns:
- a map of correlation metadata entries
-
getCorrelationData
Returns correlation metadata derived from the current deserializing message.- Parameters:
currentMessage- the message currently being handled (can benull)- Returns:
- a map of correlation metadata entries
-
getCorrelationData
default Map<String,String> getCorrelationData(@Nullable Client client, @Nullable SerializedMessage currentMessage, @Nullable MessageType messageType) Returns correlation metadata derived from a serialized message and optional context.This method may be invoked when publishing messages without a
DeserializingMessagecontext, such as in asynchronous dispatch or system-level operations.- Parameters:
client- the client instance performing the dispatch (can benull)currentMessage- the last serialized message in context (can benull)messageType- the type of the outgoing message (e.g.COMMAND,EVENT, etc.)- Returns:
- a map of correlation metadata entries
-
getApplicationIdKey
Retrieves the key used to identify the application ID in correlation metadata.- Returns:
- a string representing the application ID key
-
getClientIdKey
Retrieves the key representing the client identifier in the correlation metadata.- Returns:
- the key used to identify the client in correlation data
-
getClientNameKey
Retrieves the key associated with the client's name from the correlation metadata.- Returns:
- a string representing the key for the client's name
-
getConsumerKey
Retrieves the consumer key used to identify the consumer of a message.- Returns:
- a string representing the consumer key
-
getTrackerKey
Retrieves the key representing the tracker component in correlation metadata.- Returns:
- the tracker key as a string
-
getCorrelationIdKey
Returns the key used for identifying the correlation ID within the metadata.- Returns:
- a string representing the key for the correlation ID
-
getTraceIdKey
Returns the key used to identify the trace ID in correlation metadata.- Returns:
- a string representing the trace ID key.
-
getTriggerKey
Retrieves the trigger key used to identify the triggering context for correlation metadata.- Returns:
- the trigger key as a string
-
getTriggerTypeKey
Returns the key associated with the trigger type in the correlation data.- Returns:
- a string representing the trigger type key
-
getInvocationKey
Retrieves the key associated with the invocation context within the correlation metadata.- Returns:
- the invocation key as a string
-
getDelayKey
Retrieves the key used to identify the delay metadata within correlation data.- Returns:
- a string representing the delay metadata key
-
andThen
Chains this provider with another, returning a composed provider that merges the metadata from both.If keys overlap, the values from the second (next) provider will overwrite those from this provider.
- Parameters:
next- the provider to apply after this one- Returns:
- a composed
CorrelationDataProviderthat merges the results of both
-