Interface EventAppender

All Superinterfaces:
DescribableComponent
All Known Implementing Classes:
ProcessingContextEventAppender

public interface EventAppender extends DescribableComponent
Component that appends events to an EventSink in the context of a ProcessingContext. This makes the EventAppender the preferred way to append events from within another message handling method.

The events will be appended in the context this appender was created for. You can construct one through the forContext(ProcessingContext).

When using annotation-based @MessageHandler-methods and you have declared an argument of type EventAppender, the appender will automatically be injected by the EventAppenderParameterResolverFactory.

As this component is ProcessingContext-scoped, it is not retrievable from the Configuration.

Since:
5.0.0
Author:
Mitchell Herrijgers
  • Method Details

    • forContext

      static EventAppender forContext(ProcessingContext context)
      Creates an appender for the given ProcessingContext.

      Use this from within a message handler, or any other method that receives a ProcessingContext, instead of appending directly through an EventSink: the appender returned here is bound to that context, so every event it appends is published with that context's resources correctly applied.

      Every invocation returns a fresh instance bound to the given context, since context may override resources on top of a shared parent (see ProcessingContext.withResource(org.axonframework.messaging.core.Context.ResourceKey<T>, T)) - reusing an instance across such branches would risk it silently operating against the wrong one.

      Parameters:
      context - The ProcessingContext to create the appender for.
      Returns:
      A fresh appender specific for the given context.
    • forContext

      static EventAppender forContext(ProcessingContext context, EventSink eventSink, MessageTypeResolver messageTypeResolver)
      Creates an appender for the given ProcessingContext and EventSink.

      Use this from within a message handler, or any other method that receives a ProcessingContext, instead of appending directly through an EventSink: the appender returned here is bound to that context, so every event it appends is published with that context's resources correctly applied.

      Every invocation returns a fresh instance bound to the given context, since context may override resources on top of a shared parent (see ProcessingContext.withResource(org.axonframework.messaging.core.Context.ResourceKey<T>, T)) - reusing an instance across such branches would risk it silently operating against the wrong one.

      Parameters:
      context - The ProcessingContext to create the appender for.
      eventSink - The EventSink to use for the appender.
      messageTypeResolver - The MessageTypeResolver to use for the appender.
      Returns:
      A fresh appender specific for the given context.
    • append

      default void append(Object... events)
      Append a collection of events to the event store in the current ProcessingContext. The events will be published when the context commits.
      Parameters:
      events - The collection of events to publish.
    • append

      void append(List<?> events)
      Append a collection of events to the event store in the current ProcessingContext. The events will be published when the context commits.
      Parameters:
      events - The collection of events to publish.
    • append

      void append(List<?> events, Metadata metadata)
      Append a collection of events to the event store in the current ProcessingContext, all with the given Metadata. If an event is already a Message, the provided metadata is merged with its existing metadata (provided values take precedence on conflict).
      Parameters:
      events - The collection of events to publish.
      metadata - The metadata to attach to every event.
    • append

      default void append(Object event, Metadata metadata)
      Append a single event to the event store in the current ProcessingContext with the given Metadata. If the event is already a Message, the provided metadata is merged with its existing metadata (provided values take precedence on conflict).
      Parameters:
      event - The event to publish.
      metadata - The metadata to attach to the event.