Interface EventSourcedBehavior<Command,Event,State>


public interface EventSourcedBehavior<Command,Event,State>
Further customization of the EventSourcedBehavior can be done with the methods defined here.

Not for user extension

  • Method Details

    • persistenceId

      PersistenceId persistenceId()
    • receiveSignal

      EventSourcedBehavior<Command,Event,State> receiveSignal(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

      scala.PartialFunction<scala.Tuple2<State,Signal>,scala.runtime.BoxedUnit> signalHandler()
      Returns:
      The currently defined signal handler or an empty handler if no custom handler previously defined
    • withJournalPluginId

      EventSourcedBehavior<Command,Event,State> withJournalPluginId(String id)
      Change the journal plugin id that this actor should use.
    • withSnapshotPluginId

      EventSourcedBehavior<Command,Event,State> withSnapshotPluginId(String id)
      Change the snapshot store plugin id that this actor should use.
    • withJournalPluginConfig

      EventSourcedBehavior<Command,Event,State> withJournalPluginConfig(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,State> withSnapshotPluginConfig(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,State> snapshotWhen(scala.Function3<State,Event,Object,Object> predicate)
      Initiates a snapshot if the given predicate evaluates 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 snapshotWhen will not trigger deletes of old snapshots and events if EventSourcedBehavior.withRetention with RetentionCriteria.snapshotEvery is used together with snapshotWhen. Such deletes are only triggered by snapshots matching the numberOfEvents in the RetentionCriteria.

    • 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,State> withTagger(scala.Function1<Event,scala.collection.immutable.Set<String>> tagger)
      The tagger function 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 than Event.
    • 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

      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

      EventSourcedBehavior<Command,Event,State> withRecovery(Recovery recovery)
      Change the recovery strategy. By default, snapshots and events are recovered.
    • withEventPublishing

      EventSourcedBehavior<Command,Event,State> withEventPublishing(boolean enabled)
      Publish events to the system event stream as pekko.persistence.typed.PublishedEvent after they have been persisted
    • withStashCapacity

      EventSourcedBehavior<Command,Event,State> withStashCapacity(int size)
      Define a custom stash capacity per entity. If not defined, the default pekko.persistence.typed.stash-capacity will be used.
      Since:
      1.3.0
    • withReplication

      EventSourcedBehavior<Command,Event,State> withReplication(org.apache.pekko.persistence.typed.internal.ReplicationContextImpl context)
      INTERNAL API