Dependencies
Overview
A Dependency is a pluggable and serialisable interface that can be injected into an Actor to extend its functionality with custom or domain-specific behaviour. It provides a flexible mechanism for augmenting actors with capabilities beyond the core runtime—for example:
Event sourcing support
Metrics collection
External service integrations
Custom configuration or logging
Dependencies are serialisable, allowing them to be safely persisted and restored at runtime. This enables seamless recovery and continuity during critical system events such as:
Actor redeployment or restart
Node failover
Cross-node actor migration
All dependencies must be registered with the actor system’s dependency registry. Registration ensures that the system can reconstruct and manage dependencies correctly across the actor’s lifecycle.
By using the Dependency interface, you can build reusable, composable, and runtime-safe extensions for your actor system.
Get Started
Implement the
Dependencyinterface:
type Dependency interface {
Serializable
// ID returns the unique identifier for the extension.
//
// The identifier must:
// - Be no more than 255 characters long.
// - Start with an alphanumeric character [a-zA-Z0-9].
// - Contain only alphanumeric characters, hyphens (-), or underscores (_) thereafter.
//
// Identifiers that do not meet these constraints are considered invalid.
ID() string
}
type Serializable interface {
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
}Register the
Dependencyduring the creation of anActorusing theSpawnOption.Register the
Dependencywith the givenActorSystemusing theInjectmethod. This will allow the actor system to magically restore the dependencies of a given actor during cluster topology changes or when creating an actor on a remote host.
Last updated