Interface EventTransformation
- All Superinterfaces:
MessageTransformation<EventMessage>
MessageTransformation describing how stored events of one MessageType are
rewritten into another when they are read. A transformation is either a 1:1 payload mapping, a pure rename,
or a 1:0 drop.
A mapping is built through one of two from paths, each continuing with to(...) to declare the
resulting identity and transform(...) to supply the payload mapper:
- Concrete (
from(MessageType)): matches a sourceMessageTypeby exact equality. The source type is known up front. Prefer this path whenever the source identities are known, registering one transformation per version step. Exact matches are resolved by a constant-time identity lookup and let the chain widen read criteria to precisely those source types, so they impose no per-event scanning cost. - Predicate-based (
from(Predicate)): matches everyMessageTypefor which the supplied predicate returnstrue. Reach for this only when the source identities cannot be enumerated up front: each predicate is evaluated against non-exact events in registration order, a per-event cost that grows with the number of predicates, and the widened read criteria are necessarily broader than the concrete path's. Both can carry a significant performance penalty.
rename(MessageType, MessageType): it leaves the payload unchanged and, unlike
the mapping paths, may change the QualifiedName rather than only the version. A drop is built with
drop(MessageType): matched events are removed from the read stream while their stream position is still
advanced.
// Concrete mapping: rewrite a single, known source type.
EventTransformation.from(new MessageType("com.example.CourseCreated", "1.0.0"))
.to(new MessageType("com.example.CourseCreated", "2.0.0"))
.transform(String.class, (payload, context) -> payload);
// Predicate-based mapping: match many source types, declaring them so reads stay type-filtered.
EventTransformation.from(type -> "1.0.0".equals(type.version()))
.declaringFromTypes(new QualifiedName("com.example.CourseCreated"))
.to(new MessageType("com.example.CourseCreated", "2.0.0"))
.transform(String.class, (payload, context) -> payload);
// Pure rename: same payload, new identity.
EventTransformation.rename(new MessageType("com.example.CourseCreated", "1.0.0"),
new MessageType("com.example.CourseRegistered", "1.0.0"));
// Drop: remove matched events from the read stream.
EventTransformation.drop(new MessageType("com.example.CourseCreated", "1.0.0"));
Why the declared from types matter. When entities are sourced, read criteria are widened so a
query for the to type also returns events still stored under the from type(s) this transformation
rewrites. For the concrete path the source type is always known. For the predicate path the matched types cannot
be enumerated, so the source types must be declared explicitly through
EventTransformation.PredicateFromStep.declaringFromTypes(QualifiedName...). Declaring an incomplete set means a read for the
to type is not widened to the omitted types, leaving entities without events they expect to receive.
Omitting declaringFromTypes entirely is the safe fallback: the read's type filter is dropped for that
target, and matching falls back to tags, broader but never missing events.
- Since:
- 5.2.0
- Author:
- Laura Devriendt
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classContinuation offrom(Predicate); optionally restricts the predicate match to a set of declaredfromtype names beforeto(...)is supplied.static final classstatic final classContinuation offrom(...).to(...); supplies the payload mapper. -
Method Summary
Modifier and TypeMethodDescriptionstatic EventTransformationdrop(MessageType source) Drop events of identitysourcefrom the read stream, so no handler receives them.from(Predicate<MessageType> sourcePredicate) Begin a 1:1 transformation matching anyMessageTypefor which the supplied predicate returnstrue.static EventTransformation.ToStepfrom(MessageType source) Begin a 1:1 transformation matching the givenfromidentity by exact equality.matcher()Thefrom-side matcher selecting the events this transformation applies to.static EventTransformationrename(MessageType source, MessageType target) Create a pure rename of events fromsourcetotarget, leaving the payload unchanged.Methods inherited from interface io.axoniq.framework.messaging.transformation.MessageTransformation
transform
-
Method Details
-
from
Begin a 1:1 transformation matching the givenfromidentity by exact equality. Continue withto(...)thentransform(...).- Parameters:
source- thefromidentity- Returns:
- a builder awaiting
to(...)
-
from
Begin a 1:1 transformation matching anyMessageTypefor which the supplied predicate returnstrue. Optionally restrict the match to specificfromtype names viaEventTransformation.PredicateFromStep.declaringFromTypes(QualifiedName...), then continue withto(...).- Parameters:
sourcePredicate- the matcher- Returns:
- a builder optionally restricting the match before awaiting
to(...)
-
rename
Create a pure rename of events fromsourcetotarget, leaving the payload unchanged. Unlikefrom(MessageType), a rename may change theQualifiedName, not only the version.- Parameters:
source- thefromidentity to matchtarget- thetoidentity applied to the output- Returns:
- the completed rename
EventTransformation, ready to register without further builder steps - Throws:
IllegalArgumentException- ifsourceandtargetare identical
-
drop
Drop events of identitysourcefrom the read stream, so no handler receives them. A dropped event's stream position is still advanced, so a streaming processor resumes after it rather than reprocessing it.- Parameters:
source- the identity to drop- Returns:
- a completed drop
EventTransformation, ready to register without further builder steps
-
matcher
Thefrom-side matcher selecting the events this transformation applies to. The chain's lookup uses this; the declaredtoidentity, if any, is variant-specific and not part of this contract.- Returns:
- the
from-side matcher
-