Interface DispatchInterceptor
- All Known Implementing Classes:
AdhocDispatchInterceptor
,AuthenticatingInterceptor
,CorrelatingInterceptor
,DataProtectionInterceptor
,MessageRoutingInterceptor
,SchedulingInterceptor
,WebResponseCompressingInterceptor
,WebsocketResponseInterceptor
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A DispatchInterceptor
allows observing and transforming messages during the dispatch process. It is typically
used to inject metadata, rewrite payloads, log outgoing messages, or prevent dispatching certain messages based on
custom rules.
Key behaviors:
interceptDispatch(io.fluxcapacitor.javaclient.common.Message, io.fluxcapacitor.common.MessageType, java.lang.String)
is used for altering or blocking a message before it's handled or published.modifySerializedMessage(io.fluxcapacitor.common.api.SerializedMessage, io.fluxcapacitor.javaclient.common.Message, io.fluxcapacitor.common.MessageType, java.lang.String)
can change the final serialized message before it's stored or sent to the Flux platform.monitorDispatch(io.fluxcapacitor.javaclient.common.Message, io.fluxcapacitor.common.MessageType, java.lang.String)
is a post-processing hook for monitoring without side effects or blocking.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DispatchInterceptor
No-op implementation of theDispatchInterceptor
that returns the original message unchanged. -
Method Summary
Modifier and TypeMethodDescriptiondefault DispatchInterceptor
andThen
(DispatchInterceptor nextInterceptor) Chains this interceptor with another.interceptDispatch
(Message message, MessageType messageType, String topic) Intercepts the dispatch of a message before it is serialized and published or locally handled.default SerializedMessage
modifySerializedMessage
(SerializedMessage serializedMessage, Message message, MessageType messageType, String topic) Allows modifications to the serialized representation of the message before it is actually published.default void
monitorDispatch
(Message message, MessageType messageType, String topic) Hook to observe the dispatch of a message.
-
Field Details
-
noOp
No-op implementation of theDispatchInterceptor
that returns the original message unchanged.
-
-
Method Details
-
interceptDispatch
Intercepts the dispatch of a message before it is serialized and published or locally handled.You may modify the message or return
null
to block dispatching. Throwing an exception also prevents dispatching.- 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
default SerializedMessage modifySerializedMessage(SerializedMessage serializedMessage, Message message, MessageType messageType, String topic) Allows modifications to the serialized representation of the message before it is actually published.This is called after
interceptDispatch(io.fluxcapacitor.javaclient.common.Message, io.fluxcapacitor.common.MessageType, java.lang.String)
and should not be used to block dispatching — useinterceptDispatch(io.fluxcapacitor.javaclient.common.Message, io.fluxcapacitor.common.MessageType, java.lang.String)
for that purpose instead.- Parameters:
serializedMessage
- the serialized form of the messagemessage
- the deserialized message objectmessageType
- the message typetopic
- the target topic- Returns:
- the modified or original
SerializedMessage
-
monitorDispatch
Hook to observe the dispatch of a message. This method is called after all interceptors have had a chance to block or modify the message.Use this for logging or metrics, but not to alter or block the message.
- Parameters:
message
- the final message about to be handled or publishedmessageType
- the type of the messagetopic
- the topic to which the message is dispatched (can be null)
-
andThen
Chains this interceptor with another. The resulting interceptor applies this one first, then the next one.- Parameters:
nextInterceptor
- the interceptor to run after this one- Returns:
- a new
DispatchInterceptor
representing the combined logic
-