Class SequenceOverridingEventHandlingComponent

java.lang.Object
org.axonframework.messaging.eventhandling.processing.streaming.segmenting.SequenceOverridingEventHandlingComponent
All Implemented Interfaces:
DescribableComponent, MessageHandler, EventHandler, EventHandlingComponent

@Internal public class SequenceOverridingEventHandlingComponent extends Object implements EventHandlingComponent
Decorator implementation of EventHandlingComponent that uses a configurable SequencingPolicy to determine the sequence identifier for events, while delegating all other operations to an underlying EventHandlingComponent.

This component first attempts to determine sequence identification using the configured sequencing policy. If the policy returns Optional.empty(), only then it falls back to the delegate component's sequence identifier. This allows for overriding the sequencing behavior of the underlying component.

Since:
5.0.0
Author:
Mateusz Nowak
See Also:
  • Constructor Details

    • SequenceOverridingEventHandlingComponent

      public SequenceOverridingEventHandlingComponent(@Nonnull SequencingPolicy sequencingPolicy, @Nonnull EventHandlingComponent delegate)
      Creates a new SequenceOverridingEventHandlingComponent that uses the given sequencingPolicy to override sequence identification while delegating all other operations to the delegate component.
      Parameters:
      sequencingPolicy - The policy to use for determining sequence identifiers for events.
      delegate - The underlying event handling component to delegate operations to.
  • Method Details

    • sequenceIdentifierFor

      @Nonnull public Object sequenceIdentifierFor(@Nonnull EventMessage event, @Nonnull ProcessingContext context)
      Description copied from interface: EventHandlingComponent
      Returns the sequence identifier for the given event. When two events have the same sequence identifier (as defined by their equals method), they will be executed sequentially. Important: All EventHandlers for the same QualifiedName within a single EventHandlingComponent must return the same sequence identifier for a given event. Mixing different sequence identifiers within the scope of a single EventHandlingComponent is not supported and may lead to undefined behavior.
      Specified by:
      sequenceIdentifierFor in interface EventHandlingComponent
      Parameters:
      event - The event for which to get the sequencing identifier.
      context - The processing context in which the event is being handled.
      Returns:
      A sequence identifier for the given event.
    • supportedEvents

      public Set<QualifiedName> supportedEvents()
      Description copied from interface: EventHandlingComponent
      All supported events, referenced through a QualifiedName.
      Specified by:
      supportedEvents in interface EventHandlingComponent
      Returns:
      All supported events, referenced through a QualifiedName.
    • supports

      public boolean supports(@Nonnull QualifiedName eventName)
      Description copied from interface: EventHandlingComponent
      Checks whether the given eventName is supported by this component.
      Specified by:
      supports in interface EventHandlingComponent
      Parameters:
      eventName - The name of the event to check for support.
      Returns:
      true if the given eventName is supported, false otherwise.
    • handle

      @Nonnull public MessageStream.Empty<Message> handle(@Nonnull EventMessage event, @Nonnull ProcessingContext context)
      Description copied from interface: EventHandler
      Handles the given event within the given context.

      The result of handling is an empty stream.

      Specified by:
      handle in interface EventHandler
      Parameters:
      event - The event to handle.
      context - The context to the given event is handled in.
      Returns:
      An empty stream containing nothing.
    • describeTo

      public void describeTo(@Nonnull 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.