Class: EventSourcedEntity

akkaserverless. EventSourcedEntity

An event sourced entity.


new EventSourcedEntity(desc, serviceName, entityType [, options])

Create a new event sourced entity.

Parameters:
Name Type Argument Description
desc string | Array.<string>

A descriptor or list of descriptors to parse, containing the service to serve.

serviceName string

The fully qualified name of the service that provides this entities interface.

entityType string

The entity type name for all event source entities of this type. This will be prefixed onto the entityId when storing the events for this entity. Be aware that the chosen name must be stable through the entity lifecycle. Never change it after deploying a service that stored data of this type

options module:akkaserverless.EventSourcedEntity~options <optional>

The options for this event sourced entity

Implements:

Members


behavior :module:akkaserverless.EventSourcedEntity~behaviorCallback

The behavior callback.

Type:

initial :module:akkaserverless.EventSourcedEntity~initialCallback

The initial state callback.

Type:

options :module:akkaserverless.EventSourcedEntity~options

Type:

service :protobuf.Service

Type:
  • protobuf.Service

serviceName :string

Type:
  • string

Methods


componentType()

Returns:

event sourced entity component type.

Type
string

lookupType(messageType)

Lookup a protobuf message type.

This is provided as a convenience to lookup protobuf message types for use with events and snapshots.

Parameters:
Name Type Description
messageType string

The fully qualified name of the type to lookup.

Returns:

The protobuf message type.

Type
protobuf.Type

setBehavior(callback)

Set the behavior callback.

Parameters:
Name Type Description
callback module:akkaserverless.EventSourcedEntity~behaviorCallback

The behavior callback.

Returns:

This entity.

Type
module:akkaserverless.EventSourcedEntity

setInitial(callback)

Set the initial state callback.

Parameters:
Name Type Description
callback module:akkaserverless.EventSourcedEntity~initialCallback

The initial state callback.

Returns:

This entity.

Type
module:akkaserverless.EventSourcedEntity

Type Definitions


behavior

An event sourced entity behavior.

Properties:
Name Type Description
commandHandlers Object.<string, module:akkaserverless.EventSourcedEntity~commandHandler>

The command handlers.

The names of the properties must match the names of the service calls specified in the gRPC descriptor for this event sourced entities service.

eventHandlers Object.<string, module:akkaserverless.EventSourcedEntity~eventHandler>

The event handlers.

The names of the properties must match the short names of the events.


behaviorCallback(state)

An event sourced entity behavior callback.

This callback takes the current entity state, and returns a set of handlers to handle commands and events for it.

Parameters:
Name Type Description
state module:akkaserverless.Serializable

The entity state.

Returns:

The new entity state.

Type
module:akkaserverless.EventSourcedEntity~behavior

commandHandler(command, state, context)

An event sourced entity command handler.

Parameters:
Name Type Description
command Object

The command message, this will be of the type of the gRPC service call input type.

state module:akkaserverless.Serializable

The entity state.

context module:akkaserverless.EventSourcedEntity.EventSourcedEntityCommandContext

The command context.

Returns:

The message to reply with, it must match the gRPC service call output type for this command, or if a Reply is returned, contain an object that matches the output type.

Type
undefined | Object | module:akkaserverless.replies.Reply

entityPassivationStrategy

Entity passivation strategy for an event sourced entity.

Properties:
Name Type Argument Description
timeout number <optional>

Passivation timeout (in milliseconds).


eventHandler(event, state)

An event sourced entity event handler.

Parameters:
Name Type Description
event module:akkaserverless.Serializable

The event.

state module:akkaserverless.Serializable

The entity state.

Returns:

The new entity state.

Type
module:akkaserverless.Serializable

initialCallback(entityId)

Initial state callback.

This is invoked if the entity is started with no snapshot.

Parameters:
Name Type Description
entityId string

The entity id.

Returns:

The entity state.

Type
module:akkaserverless.Serializable

options

Options for an event sourced entity.

Properties:
Name Type Argument Default Description
snapshotEvery number <optional>
100

A snapshot will be persisted every time this many events are emitted. It is strongly recommended to not disable snapshotting unless it is known that event sourced entities will never have more than 100 events (in which case the default will anyway not trigger any snapshots)

includeDirs array.<string> <optional>
["."]

The directories to include when looking up imported protobuf files.

serializeAllowPrimitives boolean <optional>
false

Whether serialization of primitives should be supported when serializing events and snapshots.

serializeFallbackToJson boolean <optional>
false

Whether serialization should fallback to using JSON if an event or snapshot can't be serialized as a protobuf.

forwardHeaders array.<string> <optional>
[]

request headers to be forwarded as metadata to the event sourced entity

entityPassivationStrategy module:akkaserverless.EventSourcedEntity~entityPassivationStrategy <optional>

Entity passivation strategy to use.