Class CorrelatingInterceptor
- All Implemented Interfaces:
DispatchInterceptor
DispatchInterceptor that enriches outgoing messages with correlation metadata,
enabling full traceability across message flows within Fluxzero.
This interceptor ensures that dispatched messages inherit and extend the correlation context from the currently handled message and runtime environment. It collects metadata such as:
- Application ID and client identifiers
- Consumer/tracker information (if running inside a
Tracker) - Invocation ID (if within a tracked
Invocation) - Correlation ID and trace ID
- Trigger type and message type
Specifically, if the current message being handled is a request (e.g., a command or query) and the outgoing message is an event, the outgoing event will inherit the metadata of the incoming request. This is important for tying emitted events to the initiating request in logs, audits, or UIs.
In all cases, the interceptor adds the current correlation data retrieved from:
Fluxzero.currentCorrelationData().
Example
Event event = new MyEvent(...);
eventGateway.publish(event);
The published event will automatically contain metadata such as:
$correlationId$traceId$trigger$clientId,$clientName$tracker,$consumer
- See Also:
-
Field Summary
Fields inherited from interface DispatchInterceptor
defaultInterceptors, noOp -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioninterceptDispatch(Message message, MessageType messageType, String topic) Intercepts the dispatch of a message before it is serialized and published or locally handled.prepareLocalDispatch(LocalDispatchDescriptor descriptor) Prepares this interceptor for repeated local dispatches with the same static message characteristics.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DispatchInterceptor
andThen, interceptDispatch, modifySerializedMessage, monitorDispatch, withNamespace
-
Constructor Details
-
CorrelatingInterceptor
public CorrelatingInterceptor()
-
-
Method Details
-
interceptDispatch
Description copied from interface:DispatchInterceptorIntercepts the dispatch of a message before it is serialized and published or locally handled.You may modify the message or return
nullto block dispatching. Throwing an exception also prevents dispatching.- Specified by:
interceptDispatchin interfaceDispatchInterceptor- Parameters:
message- the message to be dispatchedmessageType- the type of the message (e.g., COMMAND, EVENT, etc.)topic- the target topic or null if not applicable- Returns:
- the modified message, the same message, or
nullto prevent dispatch
-
prepareLocalDispatch
Description copied from interface:DispatchInterceptorPrepares this interceptor for repeated local dispatches with the same static message characteristics.This optional method lets local handling apply an interceptor without creating a complete
Messagefirst. Implementations must preserve the observable behavior ofDispatchInterceptor.interceptDispatch(Message, MessageType, String). Returnnullwhen that is not possible; Fluxzero will then use the regular dispatch path for this payload type.The returned policy may be cached and used concurrently. State belonging to a single dispatch must be stored in the supplied
LocalExecution, not in the policy itself.- Specified by:
prepareLocalDispatchin interfaceDispatchInterceptor- Parameters:
descriptor- payload class, message type, and topic shared by the local dispatches- Returns:
- a thread-safe prepared policy, or
nullto use regular message-based dispatch
-