Class InterceptingEventSink

java.lang.Object
org.axonframework.messaging.eventhandling.InterceptingEventSink
All Implemented Interfaces:
DescribableComponent, EventSink

@Internal public class InterceptingEventSink extends Object implements EventSink
Decorator around the EventSink intercepting all events before they are published with dispatch interceptors.

This InterceptingEventSink is typically registered as a decorator and automatically kicks in whenever MessageDispatchInterceptors are present.

Since:
5.0.0
Author:
Steven van Beelen
  • Field Details

    • DECORATION_ORDER

      public static final int DECORATION_ORDER
      The order in which the InterceptingEventSink is applied as a decorator to the EventSink.

      As such, any decorator with a lower value will be applied to the delegate, and any higher value will be applied to the InterceptingEventSink itself. Using the same value can either lead to application of the decorator to the delegate or the InterceptingEventSink, depending on the order of registration.

      The order of the InterceptingEventSink is set to Integer.MIN_VALUE + 100 to ensure it is applied very early in the configuration process, but not the earliest to allow for other decorators to be applied.

      See Also:
  • Constructor Details

    • InterceptingEventSink

      public InterceptingEventSink(@Nonnull EventSink delegate, @Nonnull List<MessageDispatchInterceptor<? super EventMessage>> interceptors)
      Constructs a InterceptingEventSink, delegating publishing to the given delegate.

      The given interceptors are invoked before publishing is done by the given delegate.

      Parameters:
      delegate - The delegate EventSink that will handle all dispatching and handling logic.
      interceptors - The interceptors to invoke before publishing an event.
  • Method Details

    • publish

      public CompletableFuture<Void> publish(@Nullable ProcessingContext context, @Nonnull List<EventMessage> events)
      Description copied from interface: EventSink
      Publishes the given events within the given context, when present.

      When present, the post invocation phase is used to publish the events. As a consequence, the resulting CompletableFuture completes when the events are staged in that phase.

      When no ProcessingContext is provided, implementers of this interface may choose to create a ProcessingContext when necessary.

      Specified by:
      publish in interface EventSink
      Parameters:
      context - The processing context, if any, to publish the given events in.
      events - The events to publish in this sink.
      Returns:
      A CompletableFuture of Void. When this completes and a non-null context was given, this means the events have been successfully staged. When a null context was provided, successful completion of this future means the events where published.
    • 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.