Interface EventSourcedBehavior<Command,Event,State>
EventSourcedBehavior can be done with the methods defined here.
Not for user extension
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classTheCommandHandlerdefines how to act on commands. -
Method Summary
Modifier and TypeMethodDescriptioneventAdapter(EventAdapter<Event, ?> adapter) Transform the event to another type before giving to the journal.onPersistFailure(BackoffSupervisorStrategy backoffStrategy) Back off strategy for persist failures.receiveSignal(scala.PartialFunction<scala.Tuple2<State, Signal>, scala.runtime.BoxedUnit> signalHandler) Allows the event sourced behavior to react on signals.snapshotAdapter(SnapshotAdapter<State> adapter) Transform the state to another type before giving to the journal.snapshotWhen(scala.Function3<State, Event, Object, Object> predicate) Initiates a snapshot if the givenpredicateevaluates to true.withEventPublishing(boolean enabled) Publish events to the system event stream aspekko.persistence.typed.PublishedEventafter they have been persistedwithJournalPluginConfig(scala.Option<com.typesafe.config.Config> id) Change the journal plugin config that this actor should use.Change the journal plugin id that this actor should use.withRecovery(Recovery recovery) Change the recovery strategy.withReplication(org.apache.pekko.persistence.typed.internal.ReplicationContextImpl context) INTERNAL APIwithRetention(RetentionCriteria criteria) Criteria for retention/deletion of snapshots and events.withSnapshotPluginConfig(scala.Option<com.typesafe.config.Config> id) Change the snapshot store plugin config that this actor should use.Change the snapshot store plugin id that this actor should use.withStashCapacity(int size) Define a custom stash capacity per entity.withTagger(scala.Function1<Event, scala.collection.immutable.Set<String>> tagger) Thetaggerfunction should give event tags, which will be used in persistence query
-
Method Details
-
persistenceId
PersistenceId persistenceId() -
receiveSignal
EventSourcedBehavior<Command,Event, receiveSignalState> (scala.PartialFunction<scala.Tuple2<State, Signal>, scala.runtime.BoxedUnit> signalHandler) Allows the event sourced behavior to react on signals.The regular lifecycle signals can be handled as well as Pekko Persistence specific signals (snapshot and recovery related). Those are all subtypes of
pekko.persistence.typed.EventSourcedSignal -
signalHandler
- Returns:
- The currently defined signal handler or an empty handler if no custom handler previously defined
-
withJournalPluginId
Change the journal plugin id that this actor should use. -
withSnapshotPluginId
Change the snapshot store plugin id that this actor should use. -
withJournalPluginConfig
EventSourcedBehavior<Command,Event, withJournalPluginConfigState> (scala.Option<com.typesafe.config.Config> id) Change the journal plugin config that this actor should use.- Since:
- 1.1.3
-
withSnapshotPluginConfig
EventSourcedBehavior<Command,Event, withSnapshotPluginConfigState> (scala.Option<com.typesafe.config.Config> id) Change the snapshot store plugin config that this actor should use.- Since:
- 1.1.3
-
snapshotWhen
EventSourcedBehavior<Command,Event, snapshotWhenState> (scala.Function3<State, Event, Object, Object> predicate) Initiates a snapshot if the givenpredicateevaluates to true.Decide to store a snapshot based on the State, Event and sequenceNr when the event has been successfully persisted.
When persisting multiple events at once the snapshot is triggered after all the events have been persisted.
Snapshots triggered by
snapshotWhenwill not trigger deletes of old snapshots and events ifEventSourcedBehavior.withRetentionwithRetentionCriteria.snapshotEveryis used together withsnapshotWhen. Such deletes are only triggered by snapshots matching thenumberOfEventsin theRetentionCriteria. -
withRetention
Criteria for retention/deletion of snapshots and events. By default, retention is disabled and snapshots are not saved and deleted automatically. -
withTagger
EventSourcedBehavior<Command,Event, withTaggerState> (scala.Function1<Event, scala.collection.immutable.Set<String>> tagger) Thetaggerfunction should give event tags, which will be used in persistence query -
eventAdapter
Transform the event to another type before giving to the journal. Can be used to wrap events in types Journals understand but is of a different type thanEvent. -
snapshotAdapter
Transform the state to another type before giving to the journal. Can be used to transform older state types into the current state type e.g. when migrating from Persistent FSM to Typed EventSourcedBehavior. -
onPersistFailure
EventSourcedBehavior<Command,Event, onPersistFailureState> (BackoffSupervisorStrategy backoffStrategy) Back off strategy for persist failures.Specifically BackOff to prevent resume being used. Resume is not allowed as it will be unknown if the event has been persisted.
This supervision is only around the event sourced behavior not any outer setup/withTimers block. If using restart, any actions e.g. scheduling timers, can be done on the PreRestart
If not specified the actor will be stopped on failure.
-
withRecovery
Change the recovery strategy. By default, snapshots and events are recovered. -
withEventPublishing
Publish events to the system event stream aspekko.persistence.typed.PublishedEventafter they have been persisted -
withStashCapacity
Define a custom stash capacity per entity. If not defined, the defaultpekko.persistence.typed.stash-capacitywill be used.- Since:
- 1.3.0
-
withReplication
EventSourcedBehavior<Command,Event, withReplicationState> (org.apache.pekko.persistence.typed.internal.ReplicationContextImpl context) INTERNAL API
-