Interface Journal
-
public interface JournalA Journal contains all the messages that where leading to the current state of a single event-sourced entity stored in aStateRepositoryor in some other kind of storage.Messages can come from different channels. The Journal will keep track not only of the messages for a single entity, but also from the originating channel for every message.
The messages of a
Journalwill be stored in aMessageStore. The store must have ajournal-key index, so theJournalis able to return theStreamof messages (more preciselyMessageStoreEntry) for every entity stored in the {code StateRepository} when callinggetJournalFor(String).In order to identify the messages for an entity,
journalKeyOf(String)must return the key of the associated messages for a givenentityId, which is the key of the stored entities: the key that would be used, for example, togetthe entity from the StateRepository.A number of default implementations of the
Journalinterface can be created using theJournalhelperJournals.Implementation hints:
If you intend to write your own
Journal, you need to make sure, that messages will be added to thejournal's MessageStore, for example by registeringJournalingInterceptorfor every message-log receiver that has to be journaled. The journal'sMessageStoremust have aIndex.JOURNAL_KEY.In most cases, the journal-key index will be calculated by just using the message's
Key.partitionKey()as journal key. This is the case, if thepartitionKeyis used as primary key of your journaled entities.- See Also:
- EIP: Message Store
-
-
Method Summary
Modifier and Type Method Description com.google.common.collect.ImmutableList<java.lang.String>getJournaledChannels()The List of channels that take influence on this Journal.default java.util.stream.Stream<MessageStoreEntry>getJournalFor(java.lang.String entityId)Returns theMessageStoreEntriescontaining all messages that where modifying the state of the entity identified byentityId.MessageStoregetMessageStore()Returns theMessageStoreused to store the messages of the journaled entities.java.lang.StringgetName()The name of the journal.default java.lang.StringjournalKeyOf(java.lang.String entityId)Calculates the journal key for a given entityId.
-
-
-
Method Detail
-
getName
java.lang.String getName()
The name of the journal.In most cases, this will be equal to the name of the journaled
StateRepository- Returns:
- journal name
-
getJournaledChannels
com.google.common.collect.ImmutableList<java.lang.String> getJournaledChannels()
The List of channels that take influence on this Journal.For every channel, a
JournalingInterceptoris auto-configured, if theJournalis registered as a Spring Bean. The interceptors will take care ofaddingincoming messages to thejournal's MessageStore.- Returns:
- list of channel names
-
getMessageStore
MessageStore getMessageStore()
Returns theMessageStoreused to store the messages of the journaled entities.The store must be indexed for
Index.JOURNAL_KEY. For every given entity, the journal-key must match the key returned byjournalKeyOf(String)- Returns:
- MessageStore
-
journalKeyOf
default java.lang.String journalKeyOf(java.lang.String entityId)
Calculates the journal key for a given entityId.The returned key will be used to fetch the messages for the entity.
The default implementation will simply return the
entityId, assuming that the message'sKey.partitionKey()will be used as a primary key for stored entites.- Parameters:
entityId- the key used to get the entity from aStateRepositoryor other entity store.- Returns:
- key used to identify the messages for the entity
-
getJournalFor
default java.util.stream.Stream<MessageStoreEntry> getJournalFor(java.lang.String entityId)
Returns theMessageStoreEntriescontaining all messages that where modifying the state of the entity identified byentityId.The default implementation assumes, that all stored messages can be found by calling
getMessageStore().stream(Index.JOURNAL_KEY, journalKeyOf(entityId));.- Parameters:
entityId- the key of the entity. In most cases, this will be the partitionKey of the message.- Returns:
- stream of MessageStoreEntry that have influenced the entity, ordered from oldest to youngest messages.
-
-