If I have an actor to represent a shopping cart:
class ShoppingCartActor extends PersistentActor with ActorLogging {
override def persistenceId: String = "shopping-cart-actor"
override def receiveCommand: Receive = ???
override def receiveRecover: Receive = ???
}
val system = ActorSystem("PersistenceActors")
for(i <- 1 to 100) {
val carts = system.actorOf(Props[ShoppingCartActor], s"shopping-cart-actor-$i"
}
If I create a new shopping cart actor for every visitor to a ecommerce store, will all event messages be stored in the same journal/table in the storage engine? e.g. postgres or cassandra
If it is the same journal/table, how does it reload the events for the correct shopping cart actor since each visitor/customer will have their own shopping cart actor.
The
persistenceId
should be unique perPersistentActor
. That is how persistence retrieves the events per specific actor (in postgres or cassandra it will be stored in its own column). So you'd want something likeAnd then:
EDIT to clarify:
The Postgres schema for the event journal is:
i.e. each event is one row in the journal table with a column corresponding to the
persistenceId
. Akka Persistence Cassandra also uses a single journal table.