akka.persistence.multidc.scaladsl
Abstract method that must be implemented by concrete subclass to define the command handlers of the entity.
Abstract method that must be implemented by concrete subclass to define
the command handlers of the entity. CommandHandler
defines command handlers and optional
functions for other signals, e.g. Termination
messages if watch
is used.
Note that you can have different handlers based on current state by using CommandHandler.byState
.
Apply the event
to the state
.
Apply the event
to the state
. Return the new State
.
Abstract method that must be implemented by concrete subclass to define the initial state of the entity.
Abstract method that must be implemented by concrete subclass to define the initial state of the entity.
All data centers
All data centers
Called to create the timestamp when an event is persisted.
Called to create the timestamp when an event is persisted. May be overridden if you want to use another clock source, or for testing purposes.
The id of the current entity
The id of the current entity
Side effects from the event handler are generally discouraged, but for some use cases you may need to trigger side effects after consuming replicated events and then this method can be implemented.
Side effects from the event handler are generally discouraged, but for some use cases you may need to trigger side effects after consuming replicated events and then this method can be implemented. It is called for all events, but it is not called during recovery. Side effects after recovery should be done in #recoveryCompleted based on the state.
The context contains information about which DC the event was originally persisted in, and access to the ordinary ActorContext.
Current state, after the event was applied.
The event that was consumed.
Effect, for example persisting new event.
The id of the current entity
The id of the current entity
The 'self' field holds the ActorRef for this actor.
The 'self' field holds the ActorRef for this actor.
Can be used to send messages to itself:
self ! message
Used as the implicit sender
for !
Java API: Name of the data-center in which this entity is running
Java API: Name of the data-center in which this entity is running
Special akka.event.LoggingAdapter which adds the enclosing replicated entity persistenceId to each log statement.
Special akka.event.LoggingAdapter which adds the enclosing replicated entity persistenceId to each log statement.
Configure how it should add such metadata under the akka.persistence.multi-datacenter.logging
config section.
WARNING: The logger may only be used after construction of the ReplicatedEntity has completed, i.e. not in its constructor.
WARNING: When using the MDC features of this logger, and NOT using Lightbend Monitoring's automatic MDC propagation, be awere that the MDC context would be lost if the logger were to be invoked from a Future.
Other data centers, allDcs
without selfDc
Other data centers, allDcs
without selfDc
When migrating from PersistenceActor you need to define the exact format of the persistenceId to match the old identifiers in one of the data centers, which hosts the old data which are stored with persistence ids that don't include the data center suffix.
When migrating from PersistenceActor you need to define the exact format of the persistenceId to match the old identifiers in one of the data centers, which hosts the old data which are stored with persistence ids that don't include the data center suffix. The prefix and separator is probably also different for old persistenceId.
The persistenceId
is by default the concatenation of persistenceIdPrefix
, entityId
and the data center identifier, separated with |
.
User overridable callback.
User overridable callback.
Is called asynchronously after 'actor.stop()' is invoked. Empty default implementation.
This method is called to notify the entity that the recovery process is finished.
This method is called to notify the entity that the recovery process is finished.
The returned Effect will be applied immediately, in the same way it would be in a CommandHandler.
More often than not returning a simple Effect.none
is what would be done in this hook,
however any other effect is also valid, including persisting events to signify a successful recovery.
Apply the event
that was persisted by another data center to the given state.
Apply the event
that was persisted by another data center to the given state.
Return the new State
. By default this invokes eventHandler
but in case more
context of the event is needed this can be overridden instead. See also
#selfEventHandler.
The 'self' field holds the ActorRef for this actor.
The 'self' field holds the ActorRef for this actor.
Can be used to send messages to itself:
self ! message
Used as the implicit sender
for !
Name of the data-center in which this entity is running
Name of the data-center in which this entity is running
Apply the event
that was persisted by this data center to the given state.
Apply the event
that was persisted by this data center to the given state.
Return the new State
. By default this invokes eventHandler
but in case more
context of the event is needed this can be overridden instead. See also
#replicatedEventHandler.
When migrating from PersistentActor to Replicated entity this method is
called to be able to convert old snapshots to the new State
if needed.
When migrating from PersistentActor to Replicated entity this method is
called to be able to convert old snapshots to the new State
if needed.
By default it tries to cast the oldSnapshot
to State
.
User overridable definition the strategy to use for supervising child actors.
User overridable definition the strategy to use for supervising child actors.
Advanced version of tagsFor(Event)
carrying additional contextual information about the event.
Advanced version of tagsFor(Event)
carrying additional contextual information about the event.
Allows adding adding tags to the persisted event, along will information where the event originated (if it
originated in this Dc, or was it replicated to this Dc).
Tags can be useful during reconstruction of a read side, using persistence queries like eventsByTag
.
Invoked before passing an to-be-persisted Event to the underlying journal.
WARNING: Make sure to override only one of the overloads of tagsFor
to avoid confusion.
A
ReplicatedEntity
has a stable entity identifier, with which it can be accessed from anywhere in the cluster. It is run by an actor and the state is persistent using event sourcing.initialState
andbehavior
are abstract methods that your concrete subclass must implement. The behavior is defined as a set of handlers given a state. The handlers are functions to process incoming commands.Persistent and replicated events are applied to the state with the
eventHandler
method.The
ReplicatedEntity
receives commands of typeCommand
that can be validated before persisting state changes as events of typeEvent
. The functions that process incoming commands are registered in theCommandHandler
usingonCommand
of theCommandHandler
.A command may also be read-only and only perform some side-effect, such as replying to the request. Such command handlers are registered using
onReadOnlyCommand
of theCommandHandler
. Replies are sent with thesender()
ActorRef
in the context or anActorRef
that is passed in the command.A command handler returns a
Effect
directive that defines what event or events, if any, to persist. Use thethenPersist
,thenPersistAll
ordone
methods of the context that is passed to the command handler function to create theEffect
directive.When an event has been persisted successfully the state of type
State
is updated by applying the event to the current state by invoking theeventHandler
. TheeventHandler
returns the new state. The state must be immutable, so you return a new instance of the state. Current state is passed as parameter to the event handler. The same event handlers are also used when the entity is started up to recover its state from the stored events.After persisting an event, external side effects can be performed with the
andThen
function of theEffect
directive. A typical side effect is to reply to the request to confirm that it was performed successfully. Replies are sent with thesender()
ActorRef
in the context or anActorRef
that is passed in the command.The event handlers are typically only updating the state, but they may also change the behavior of the entity in the sense that new functions for processing commands and events may be defined for a given state. This is useful when implementing finite state machine (FSM) like entities.
When the entity is started the state is recovered by replaying stored events. To reduce this recovery time the entity may start the recovery from a snapshot of the state and then only replaying the events that were stored after the snapshot. Such snapshots are automatically saved after a configured number of persisted events.
the super type of all commands
the super type of all events
the type of the state