Class MessageRoutingInterceptor
java.lang.Object
io.fluxzero.sdk.publishing.routing.MessageRoutingInterceptor
- All Implemented Interfaces:
DispatchInterceptor
A
DispatchInterceptor that assigns a routing segment to messages prior to dispatch.
This interceptor computes a consistent hash-based segment index for each message using
ConsistentHashing.computeSegment(String) and injects it into the serialized message if no segment has already
been set.
Fluxzero Runtime uses the segment value for consistent message routing and load distribution. It ensures that all messages with the same routing key are handled by the same segment, preserving message affinity and ordering guarantees within that segment.
Behavior
- If
SerializedMessage#getSegment()isnull, the interceptor computes the segment from the message's routing key viaHasMessage.computeRoutingKey(). - If a segment is already assigned, the interceptor leaves it unchanged.
- The message content itself is not modified; only the serialized representation is updated.
This interceptor is typically enabled by default for most gateway clients (e.g., command, event, query, etc.), ensuring that routing behavior is applied uniformly before messages are published to Fluxzero Runtime.
- See Also:
-
Field Summary
Fields inherited from interface DispatchInterceptor
noOp -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioninterceptDispatch(Message message, MessageType messageType, String topic) Returns the unmodifiedMessageas this interceptor only modifies the serialized form.modifySerializedMessage(SerializedMessage serializedMessage, Message m, MessageType messageType, String topic) Computes and sets the routing segment on the serialized message if not already present.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DispatchInterceptor
andThen, monitorDispatch
-
Constructor Details
-
MessageRoutingInterceptor
public MessageRoutingInterceptor()
-
-
Method Details
-
interceptDispatch
Returns the unmodifiedMessageas this interceptor only modifies the serialized form.- 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
-
modifySerializedMessage
public SerializedMessage modifySerializedMessage(SerializedMessage serializedMessage, Message m, MessageType messageType, String topic) Computes and sets the routing segment on the serialized message if not already present.- Specified by:
modifySerializedMessagein interfaceDispatchInterceptor- Parameters:
serializedMessage- the message to be sentm- the original message objectmessageType- the type of message (e.g., command, event, query)topic- the topic to which the message will be published- Returns:
- the same
SerializedMessageinstance, possibly updated with a segment
-