Interface Journal
StateRepository or 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 Journal will be stored in a MessageStore. The store must have a
journal-key index, so the Journal is able to return the Stream
of messages (more precisely MessageStoreEntry) for every entity stored in the {code StateRepository}
when calling getJournalFor(String).
In order to identify the messages for an entity, journalKeyOf(String) must return the key of
the associated messages for a given entityId, which is the key of the stored entities: the key that
would be used, for example, to get the entity from the StateRepository.
A number of default implementations of the Journal interface can be created using the Journal
helper Journals.
Implementation hints:
If you intend to write your own Journal, you need to make sure, that messages will be added
to the journal's MessageStore, for example by registering
JournalingInterceptor for every message-log receiver that has to be journaled. The journal's
MessageStore must have a Index.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 the partitionKey is used as primary key of your journaled entities.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncom.google.common.collect.ImmutableList<String>The List of channels that take influence on this Journal.default Stream<MessageStoreEntry>getJournalFor(String entityId) Returns theMessageStoreEntriescontaining all messages that where modifying the state of the entity identified byentityId.Returns theMessageStoreused to store the messages of the journaled entities.getName()The name of the journal.default StringjournalKeyOf(String entityId) Calculates the journal key for a given entityId.
-
Method Details
-
getName
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<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
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
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.
-