A declarative description of a read model A built from events: which sources to listen to, how to route their events, and what each kind of event does to A.
A Projection is immutable data and does nothing by itself. Every builder call returns a new Projection, and an engine (such as ProjectionEngine) later reads it to process events. Handlers only describe changes as ProjectionActions, so they cannot perform effects.
Create one with Projection[A](name) (one row per entity) or Projection.global[A](name) (shared totals), then chain from, a routing call, and on:
val greetings = Projection[Greeting]("greetings")
.from("people")
.routeToSelf
.on[PersonGreeted]
.insert((e, ctx) => Greeting(ctx.entityId, s"Hello, ${e.name}!"))
Further from(...) calls add more sources, and further on[...] calls add more handlers to the latest source. An on[...] with no from(...) before it creates a default source named "_default" that routes to the entity itself.
Call validate before starting an engine to catch an empty projection.
Value parameters
- bindings
-
the sources with their routing and handlers, in the order they were added
- entityPath
-
where the store lives and which field of
Ais its ID. It isNonefor global projections - isGlobal
-
whether this is a global projection
- name
-
the projection's name, which also names its store file
- schema
-
the schema of the projected type
A
Attributes
- Companion
- object
- Source
- Projection.scala
- Graph
-
- Supertypes
Members list
Value members
Concrete methods
All handlers of all sources, in binding order.
Same as handle. Kept for binary compatibility.
Starts a new source binding. Follow it with routeToSelf, routeToAll, routedBy or routedByField to choose how the source's events are routed.
Starts a new source binding. Follow it with routeToSelf, routeToAll, routedBy or routedByField to choose how the source's events are routed.
Value parameters
- sourceName
-
the name of the event source
Attributes
- Source
- Projection.scala
Finds the handler for event and runs it, returning the action to apply, or None if no handler matches the event's class.
Finds the handler for event and runs it, returning the action to apply, or None if no handler matches the event's class.
When source is given, only the handlers of the first binding with that name are considered. Otherwise all handlers are searched in binding order, and the first match wins, even across sources. Pass source when the projection has several sources, so that an event is not handled by another source's handler.
Value parameters
- ctx
-
the metadata of the event
- event
-
the event to handle
- source
-
restricts the search to this source
Attributes
- Source
- Projection.scala
Starts a handler for events of type E and attaches it to the most recently added source. Follow it with insert, delete, aggregate or another HandlerBuilder method to say what the event does.
Starts a handler for events of type E and attaches it to the most recently added source. Follow it with insert, delete, aggregate or another HandlerBuilder method to say what the event does.
If no source has been added yet, a source named "_default" that routes to the entity itself is created first.
Attributes
- Source
- Projection.scala
The routing key of event for the named source: ctx.entityId for routeToSelf, the extracted key for routedBy, and None for routeToAll or when there is no source with that name.
The routing key of event for the named source: ctx.entityId for routeToSelf, the extracted key for routedBy, and None for routeToAll or when there is no source with that name.
Attributes
- Source
- Projection.scala
The routing key of event using the most recently added source, or ctx.entityId if there are no sources. The result follows the same rules as routingKey.
The routing key of event using the most recently added source, or ctx.entityId if there are no sources. The result follows the same rules as routingKey.
Attributes
- Source
- Projection.scala
The projection's ProjectionScope, derived from how it was built:
The projection's ProjectionScope, derived from how it was built:
- ProjectionScope.Global if it was created with
Projection.global - otherwise ProjectionScope.CrossEntity if any source uses
routedBy, taking the key from the first such source - otherwise ProjectionScope.PerEntity
Note that routeToAll alone does not make a projection global.
Attributes
- Source
- Projection.scala
The names of the sources this projection listens to.
The source bindings, same as bindings.
Returns a string representation of the object.
Returns a string representation of the object.
The default representation is platform dependent.
Attributes
- Returns
-
a string representation of the object.
- Definition Classes
-
Any
- Source
- Projection.scala
Checks the projection for problems that would stop it from doing anything, and returns a message for each. The list is empty if none are found.
Checks the projection for problems that would stop it from doing anything, and returns a message for each. The list is empty if none are found.
It reports a projection with no sources, one with no handlers, a source with an empty name, and a handler with a null event class.
Attributes
- Source
- Projection.scala
Concrete fields
Attributes
- Source
- Projection.scala
Attributes
- Source
- Projection.scala
Attributes
- Source
- Projection.scala
Attributes
- Source
- Projection.scala
Attributes
- Source
- Projection.scala