Class DocumentHandlerDecorator
java.lang.Object
io.fluxzero.sdk.tracking.handling.DocumentHandlerDecorator
- All Implemented Interfaces:
HandlerDecorator
A
HandlerDecorator that intercepts handler methods annotated with HandleDocument and synchronizes
their return values with a DocumentStore.
This decorator ensures that searchable document views (e.g. projections or read models) are automatically updated when a message is handled. If the handler method returns an object of the same type as the incoming message payload (and is non-passive), the decorator will:
- Index the return value into the configured document store, if non-null and its
Revisionis newer than the original version (before upcasting). - Delete the corresponding document if the return value is
null.
The collection name is derived from the message topic. Timestamps for indexing can be determined in two ways:
- If
SearchParametersare available, they are used to extract timestamps. - Otherwise, the message metadata keys
"$start"and"$end"are used (if present).
Example Usage
@HandleDocument
UserProfile update(UserProfile document) {
return document.toBuilder().status(active).build(); //gives every existing user a status of active
}
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface HandlerDecorator
HandlerDecorator.MergedDecorator -
Field Summary
Fields inherited from interface HandlerDecorator
noOp -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionwrap(Handler<DeserializingMessage> handler) Wraps the given handler with additional behavior.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HandlerDecorator
andThen
-
Constructor Details
-
DocumentHandlerDecorator
public DocumentHandlerDecorator()
-
-
Method Details
-
wrap
Description copied from interface:HandlerDecoratorWraps the given handler with additional behavior.- Specified by:
wrapin interfaceHandlerDecorator- Parameters:
handler- the original handler to be wrapped- Returns:
- a decorated handler
-