Interface MessageStore

All Superinterfaces:
AutoCloseable, HasMessageStore, Monitored<List<SerializedMessage>>
All Known Implementing Classes:
CollectionMessageStore, InMemoryEventStore, InMemoryMessageStore, InMemoryScheduleStore, TestServerScheduleStore

public interface MessageStore extends AutoCloseable, Monitored<List<SerializedMessage>>, HasMessageStore
A low-level store for serialized messages.

This interface defines an append-only log used to store SerializedMessage instances, typically representing commands, events, queries, or other domain messages. It supports batched retrieval and allows integration with in-memory or persistent message tracking implementations.

The MessageStore plays a central role in Flux Capacitor's tracking and message handling infrastructure. In testing, in-memory implementations of MessageStore are used to simulate Flux platform behavior.

This interface is also Monitored, allowing hooks to observe message publication, and extends HasMessageStore so it can expose itself as a reusable component.

See Also:
  • Method Details

    • append

      default CompletableFuture<Void> append(SerializedMessage... messages)
      Appends the given messages to the store.
      Parameters:
      messages - messages to append
      Returns:
      a CompletableFuture that completes when the messages have been successfully appended
    • append

      Appends a list of messages to the store.
      Parameters:
      messages - messages to append
      Returns:
      a CompletableFuture that completes when the messages have been successfully appended
    • getBatch

      default List<SerializedMessage> getBatch(Long lastIndex, int maxSize)
      Retrieves a batch of messages starting from the given lastIndex (exclusive).
      Parameters:
      lastIndex - minimum message index to start from (exclusive)
      maxSize - maximum number of messages to retrieve
      Returns:
      a list of SerializedMessage instances
    • getBatch

      List<SerializedMessage> getBatch(Long minIndex, int maxSize, boolean inclusive)
      Retrieves a batch of messages starting from the given minIndex.
      Parameters:
      minIndex - minimum message index to start from
      maxSize - maximum number of messages to retrieve
      inclusive - whether to include the message at minIndex
      Returns:
      a list of SerializedMessage instances
    • setRetentionTime

      void setRetentionTime(Duration retentionPeriod)
      Sets the retention period for messages. Messages older than this duration may be removed depending on the implementation.
      Parameters:
      retentionPeriod - duration to retain messages
    • unwrap

      default <T extends MessageStore> T unwrap(Class<T> type)
      Attempts to unwrap the current instance to a concrete implementation or extension of MessageStore.
      Type Parameters:
      T - the target type
      Parameters:
      type - the desired type to unwrap to
      Returns:
      the unwrapped instance
      Throws:
      UnsupportedOperationException - if the current instance cannot be unwrapped to the given type
    • close

      default void close()
      Default no-op close method. Override if resources need cleanup.
      Specified by:
      close in interface AutoCloseable
    • getMessageStore

      default MessageStore getMessageStore()
      Returns the current instance as the MessageStore.
      Specified by:
      getMessageStore in interface HasMessageStore