Interface ReplayStatusChangedHandler

All Superinterfaces:
MessageHandler
All Known Subinterfaces:
EventHandlingComponent
All Known Implementing Classes:
AnnotatedEventHandlingComponent, DeadLetteringEventHandlingComponent, DelegatingEventHandlingComponent, InterceptingEventHandlingComponent, ReplayBlockingEventHandlingComponent, SequenceCachingEventHandlingComponent, SequenceOverridingEventHandlingComponent, SequencingEventHandlingComponent, SimpleEventHandlingComponent, TracingEventHandlingComponent
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@Internal @FunctionalInterface public interface ReplayStatusChangedHandler extends MessageHandler
Functional interface for handling ReplayStatusChanged messages.

Implementations of this interface process replay status changes, typically to prepare for and finalize an event replay. Actions to consider during a ReplayStatus change are cleaning up the projection state, clearing caches, or switching storage solution aliases. To that end, the ReplayStatusChange message contains the ReplayStatus changed to.

Replay status change handlers are registered via ReplayStatusChangedHandlerRegistry.subscribe(ReplayStatusChangedHandler).

Example usage:


 ReplayStatusChangeHandler handler = (statusChange, context) -> {
     if (statusChange.status() == REPLAY) {
         repository.deleteAll();
         cache.clear();
     }
     return MessageStream.empty();
 };
 
Since:
5.1.0
Author:
Simon Zambrovski, Stefan Dragisic, Steven van Beelen
See Also:
  • Method Details

    • handle

      Handles the given ReplayStatusChanged message, allowing for tasks to be performed when the replay starts and ends.

      This method is invoked on the moment the ReplayStatus is about to change as part of the event handling ProcessingContext. In doing so, this handler has two concrete moments when it is invoked:

      1. When the ReplayStatus changes from ReplayStatus.REGULAR to ReplayStatus.REPLAY, exactly before the first replayed event is processed
      2. When the ReplayStatus changes from ReplayStatus.REPLAY to ReplayStatus.REGULAR, exactly after processing the final event of the replay

      If this operation returns a failed MessageStream, event handling that occurs within the given context is impacted. The failure will be passed to the ErrorHandler, typically resulting in a rollback of the invoked event handling tasks.

      Parameters:
      statusChange - the replay status context message containing replay status information
      context - the processing context for this operation
      Returns:
      an empty message stream after handling completes successfully