Class EventTransformerChain

java.lang.Object
io.axoniq.framework.messaging.transformation.events.EventTransformerChain
All Implemented Interfaces:
DescribableComponent

public final class EventTransformerChain extends Object implements DescribableComponent
An immutable, thread-safe chain of EventTransformation instances that transforms events at read time. Events that match no transformation pass through unchanged; an event a transformation drops is removed. Use EventTransformerChain.Builder to construct and register transformations.

An exact identity match always takes precedence over a predicate match, independent of registration order; a predicate from is consulted only when no exact match applies, and among predicates the first registered match wins.

The chain is a thin read-time engine composing two read-models derived from the registered transformations: a TransformationIndex answering which transformation applies to an event, and a CriteriaWidener broadening read criteria so a type-filtering read also fetches the source types the chain transforms.

Since:
5.2.0
Author:
Laura Devriendt
  • Field Details

  • Method Details

    • transform

      public MessageStream<EventMessage> transform(MessageStream<? extends EventMessage> stream, @Nullable ProcessingContext context, MessageConverter converter, MessageTypeResolver messageTypeResolver)
      Transforms every event in the given stream by applying the chain at read time. Events matching no transformation pass through unchanged; an event a transformation drops is removed, and surviving events keep their stream position.
      Parameters:
      stream - the input stream of events
      context - the active processing context, or null when the read path supplies none
      converter - converts a stored payload to a transformation's declared input type
      messageTypeResolver - resolves a mapper output's type to verify it against the declared to
      Returns:
      the transformed stream
    • widen

      public EventCriteria widen(EventCriteria criteria)
      Widens the given read EventCriteria so a type-filtering read still returns every event this chain can transform into one of the queried types. Returns the same instance when nothing can be widened.
      Parameters:
      criteria - the read-time criteria to widen
      Returns:
      the widened criteria, or the same instance when nothing is broadened
    • describeTo

      public void describeTo(ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.
    • builder

      public static EventTransformerChain.Builder builder()
      Start building a new chain. Use EventTransformerChain.Builder.register(EventTransformation) to add transformations and, optionally, EventTransformerChain.Builder.maxIterationsPerEvent(int) to adjust the per-event iteration safety bound (default DEFAULT_MAX_ITERATIONS_PER_EVENT).
      Returns:
      a fresh EventTransformerChain.Builder