Akka Classic

Akka 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 akka.actor.typed.ActorSystem. Given a classic akka.actor.ActorSystem it can be adapted to an akka.actor.typed.ActorSystem like this:

Scala
sourceimport akka.actor.typed.scaladsl.adapter._

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

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

PersistentActor

Events from Akka 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 akka.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 akka.actor.ActorSystem, after adapting it to akka.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 akka.actor.typed.scaladsl.adapter._

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

Adapter.spawn(system, ProjectionBehavior.create(projection), "theProjection");
Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.