Class RecordingEventBus

java.lang.Object
org.axonframework.test.fixture.RecordingEventSink
org.axonframework.test.fixture.RecordingEventBus
All Implemented Interfaces:
DescribableComponent, SubscribableEventSource, EventBus, EventSink

@Internal public class RecordingEventBus extends RecordingEventSink implements EventBus
An EventBus implementation recording all the events that are published.

The recorded events can then be used to assert expectations with test cases.

Since:
5.0.0
Author:
Mateusz Nowak
  • Constructor Details

    • RecordingEventBus

      public RecordingEventBus(@Nonnull EventBus delegate)
      Creates a new RecordingEventBus that will record all events published to the given delegate.
      Parameters:
      delegate - The EventBus to which events will be published.
  • Method Details

    • subscribe

      public Registration subscribe(@Nonnull BiFunction<List<? extends EventMessage>,ProcessingContext,CompletableFuture<?>> eventsBatchConsumer)
      Description copied from interface: SubscribableEventSource
      Subscribe the given eventsBatchConsumer to this event source. When subscribed, it will receive all events published to this source since the subscription.

      If the given eventsBatchConsumer is already subscribed, nothing happens.

      Note on ProcessingContext: The ProcessingContext parameter passed to the consumer may be null. When null, it is the responsibility of the registered eventsBatchConsumer to create an appropriate ProcessingContext as needed for processing the events.

      Specified by:
      subscribe in interface SubscribableEventSource
      Parameters:
      eventsBatchConsumer - The event batches consumer to subscribe.
      Returns:
      A Registration handle to unsubscribe the eventsBatchConsumer. When unsubscribed, it will no longer receive events.
    • 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
      Overrides:
      describeTo in class RecordingEventSink
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.