Pekko Classic

Apache Pekko Projections can be used with the new Actor API or the classic Actor API. The documentation samples show the new Actor API, and this page highlights how to use it with the classic Actor API.

Actor System

The ActorSystem is a parameter in several places of the Projections API. That is the org.apache.pekko.actor.typed.ActorSystem. Given a classic org.apache.pekko.actor.ActorSystem it can be adapted to an org.apache.pekko.actor.typed.ActorSystem like this:

Scala
sourceimport org.apache.pekko
import pekko.actor.typed.scaladsl.adapter._

private val system = pekko.actor.ActorSystem("Example")
private val typedSystem: pekko.actor.typed.ActorSystem[_] = system.toTyped
Java
sourceimport org.apache.pekko.actor.typed.javadsl.Adapter;

org.apache.pekko.actor.ActorSystem system =
    org.apache.pekko.actor.ActorSystem.create("Example");
ActorSystem<Void> typedSystem = Adapter.toTyped(system);

PersistentActor

Events from Pekko Classic Persistence can be emitted from PersistentActor and consumed by a Projection with the EventSourcedProviderEventSourcedProvider. The events from the PersistentActor must be tagged by wrapping them in org.apache.pekko.persistence.journal.Tagged, which can be done in the PersistentActor or by using Event Adapters.

Running

As described in Running a Projection the Projection is typically run with a Sharded Daemon Process. ShardedDaemonProcess can be used in the same way with a classic org.apache.pekko.actor.ActorSystem, after adapting it to org.apache.pekko.actor.typed.ActorSystem as described above.

To run with a local actor the ProjectionBehavior can be spawned from the classic ActorSystem or a classic Actor:

Scala
sourceimport org.apache.pekko.actor.typed.scaladsl.adapter._

system.spawn(ProjectionBehavior(projection), "theProjection")
Java
sourceimport org.apache.pekko.actor.typed.javadsl.Adapter;

Adapter.spawn(system, ProjectionBehavior.create(projection), "theProjection");