Interface EventTransformation

All Superinterfaces:
MessageTransformation<EventMessage>

public sealed interface EventTransformation extends MessageTransformation<EventMessage>
An event-specific 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 source MessageType by 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 every MessageType for which the supplied predicate returns true. 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.
A pure rename is built with 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
  • Method Details

    • from

      Begin a 1:1 transformation matching the given from identity by exact equality. Continue with to(...) then transform(...).
      Parameters:
      source - the from identity
      Returns:
      a builder awaiting to(...)
    • from

      Begin a 1:1 transformation matching any MessageType for which the supplied predicate returns true. Optionally restrict the match to specific from type names via EventTransformation.PredicateFromStep.declaringFromTypes(QualifiedName...), then continue with to(...).
      Parameters:
      sourcePredicate - the matcher
      Returns:
      a builder optionally restricting the match before awaiting to(...)
    • rename

      static EventTransformation rename(MessageType source, MessageType target)
      Create a pure rename of events from source to target, leaving the payload unchanged. Unlike from(MessageType), a rename may change the QualifiedName, not only the version.
      Parameters:
      source - the from identity to match
      target - the to identity applied to the output
      Returns:
      the completed rename EventTransformation, ready to register without further builder steps
      Throws:
      IllegalArgumentException - if source and target are identical
    • drop

      static EventTransformation drop(MessageType source)
      Drop events of identity source from 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

      The from-side matcher selecting the events this transformation applies to. The chain's lookup uses this; the declared to identity, if any, is variant-specific and not part of this contract.
      Returns:
      the from-side matcher