Interface MessageStore

All Superinterfaces:
AutoCloseable
All Known Subinterfaces:
SnapshotMessageStore
All Known Implementing Classes:
DelegatingSnapshotMessageStore, OffHeapIndexingMessageStore, OnHeapCompactingMessageStore, OnHeapIndexingMessageStore, OnHeapRingBufferMessageStore

public interface MessageStore extends AutoCloseable
A repository used to store and retrieve Messages in their insertion order.

Message Store

When using a Message Store, we can take advantage of the asynchronous nature of a messaging infrastructure. When we send a message to a channel, we send a duplicate of the message to a special channel to be collected by the Message Store.

This can be performed by the component itself or we can insert a Wire Tap into the channel. We can consider the secondary channel that carries a copy of the message as part of the Control Bus. Sending a second message in a 'fire-and-forget' mode will not slow down the flow of the main application messages. It does, however, increase network traffic. That's why we may not store the complete message, but just a few of fields that are required for later analysis, such as a message ID, or the channel on which the message was sent and a timestamp.

See Also:
  • Method Details

    • getChannelNames

      Set<String> getChannelNames()
      Returns a set containing the channel names of the messages contained in the MessageStore
      Returns:
      set of channel names
    • getIndexes

      com.google.common.collect.ImmutableSet<Index> getIndexes()
    • getLatestChannelPosition

      ChannelPosition getLatestChannelPosition(String channelName)
      Returns the latest ChannelPosition of the given channel, derived from the messages contained in this MessageStore.

      The position is calculated by merging the optional positions of the messages.

      Messages without positions will not change the latest ChannelPosition. If no message contains position information, the returned ChannelPosition is ChannelPosition.fromHorizon()

      Parameters:
      channelName - the name of the channel
      Returns:
      ChannelPosition
    • getLatestChannelPosition

      @Deprecated default ChannelPosition getLatestChannelPosition()
      Deprecated.
    • stream

      Returns a Stream of all entries contained in the MessageStore.

      The stream will maintain the insertion order of the entries.

      Returns:
      Stream of entries
    • stream

      @Beta Stream<MessageStoreEntry> stream(Index index, String value)
      Returns a Stream of all entries contained in the MessageStore that have are matching the given Index value (optional operation).

      The stream will maintain the insertion order of the entries.

      Parameters:
      index - the Index
      value - the value identifying the requested messages in the specified index
      Returns:
      stream of message-store entries matching the index or emptyStream, if the index is not known, or if there are no entries
      Throws:
      UnsupportedOperationException - if the 'stream(Index,String)' operation is not supported by this store
    • add

      void add(@Nonnull MessageStoreEntry entry)
      Appends the specified element to the end of this list (optional operation).

      MessageStores that support this operation may place limitations on what elements may be added to this list. In particular, some stores will refuse to add entries for more than a single channel. MessageStore classes should clearly specify in their documentation any restrictions on what elements may be added.

      Parameters:
      entry - element to be appended to this message store
      Throws:
      UnsupportedOperationException - if the 'add' operation is not supported by this store
      NullPointerException - if the specified element is null
      IllegalArgumentException - if some property of this element prevents it from being added to this list
    • size

      default long size()
      Returns the number of messages contained in the MessageStore.

      Primarily used for testing purposes. If the MessageStore can not implement this without major performance impacts (like, for example, having to download and parse huge files from S3), the method is not required to be implemented.

      Returns:
      number of messages
    • close

      default void close()
      Specified by:
      close in interface AutoCloseable
    • isCompacting

      default boolean isCompacting()