Class MessageRoutingInterceptor
java.lang.Object
io.fluxcapacitor.javaclient.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.
Flux Platform 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 Flux Platform.
- See Also:
-
Field Summary
Fields inherited from interface io.fluxcapacitor.javaclient.publishing.DispatchInterceptor
noOp
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioninterceptDispatch
(Message message, MessageType messageType, String topic) Returns the unmodifiedMessage
as 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.publishing.DispatchInterceptor
andThen, monitorDispatch
-
Constructor Details
-
MessageRoutingInterceptor
public MessageRoutingInterceptor()
-
-
Method Details
-
interceptDispatch
Returns the unmodifiedMessage
as this interceptor only modifies the serialized form.- Specified by:
interceptDispatch
in 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
null
to 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:
modifySerializedMessage
in 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
SerializedMessage
instance, possibly updated with a segment
-