Purpose
The framework publishes lifecycle and cluster events so that external components (monitoring, logging, dashboards) can observe the actor system without coupling to internal implementation. Subscribers receive events as they occurβactor started, actor stopped, node joined, dead letter, and so on.API
| Method | Purpose |
|---|---|
ActorSystem.Subscribe() | Create a subscriber. Subscribes to the internal events topic. Returns eventstream.Subscriber. |
ActorSystem.Unsubscribe(subscriber) | Release the subscriber. Call to avoid leaks. |
eventstream.Subscriber interface:
| Method | Purpose |
|---|---|
ID() | Unique subscriber identifier |
Topics() | Topics this subscriber is subscribed to (includes the internal topic) |
Iterator() | Channel of buffered messages; drains and closes. Messages are *eventstream.Message. |
Shutdown() | Mark subscriber inactive |
Message structure
Each message has:- Topic β
msg.Topic()returns the topic (e.g.topic.events, the internal topic). - Payload β
msg.Payload()returns the event. Use a type assertion to handle specific events.
Event types
The system publishes these events to the event stream:| Event | When |
|---|---|
ActorStarted | Actor has started |
ActorStopped | Actor has stopped |
ActorChildCreated | A child actor was spawned |
ActorPassivated | Actor was passivated (idle timeout) |
ActorRestarted | Actor was restarted by supervisor |
ActorSuspended | Actor was suspended after a failure |
ActorReinstated | Actor was reinstated by supervisor |
Deadletter | Message could not be delivered (non-existent or stopped actor) |
NodeJoined | A node joined the cluster (cluster mode only) |
NodeLeft | A node left the cluster (cluster mode only) |
Usage
Iterator() returns a channel that drains buffered messages and then closes. Messages enqueued concurrently with (or after) the call may not be included. For continuous observation, loop over Iterator() or use a dedicated goroutine that reads from the channel.
Implementation notes
- The event stream is backed by the
eventstreampackage. The actor system creates anEventsStreamat startup and subscribes callers to the internal topictopic.events. - Lifecycle events (ActorStarted, ActorStopped, etc.) are published by the PID and death-watch logic. Cluster events (NodeJoined, NodeLeft) are published by the cluster events loop when membership changes.
- Dead letters are published by the dead-letter actor when messages cannot be delivered.
- The event stream is always present; no option is required. It is independent of
WithPubSub()and cluster mode.
Related
- Observability β Metrics and dead letters
- PubSub β Application-level topic-based pub/sub (separate mechanism)