client package provides a standalone client for interacting with a GoAkt cluster from outside the actor system.
Use it when your application (CLI, API server, batch job, etc.) needs to send messages to actors or grains, spawn
actors, or query cluster state without running an actor system itself.
Requirements
- Cluster with remoting: Target nodes must run GoAkt with clustering and remoting enabled.
- At least one node:
client.Newrequires a non-empty slice of nodes; it fails with “nodes are required” otherwise. - Node addresses: Each node is specified as
host:port(remoting host and port, e.g.127.0.0.1:8080). Addresses are validated as TCP addresses. - Serialization: The client must use the same serializers and compression as the cluster. Pass
remote.ConfigviaWithRemoteConfigwhen creating nodes. Without it, the node uses default remoting settings, which may not match the cluster.
Creating a client
Creating a client
Node represents a cluster node. Call Close() when done to release connection pools. The client uses a load
balancer to distribute requests across nodes. The remote.Config must match the cluster (compression, serializers).
Node options
- WithRemoteConfig: Set remoting config (compression, serializers, timeouts, TLS). Required for correct serialization.
- WithWeight: Set initial node weight for load balancing (used by
LeastLoadStrategy).
Connecting to a TLS-enabled cluster
TLS travels with theremote.Config, like every other must-match wire setting. Pass a config whose tls.Info
ClientConfig trusts the cluster’s root CA and, when the cluster enforces mutual TLS, presents a certificate that
chains to it (see TLS):
Connecting to a TLS-enabled cluster
ServerConfig field is ignored. A client without TLS settings cannot talk to a
TLS-enabled cluster; the first operation fails with a network error.
Messaging
- Tell: Fire-and-forget to an actor.
messagemust beproto.Message. ReturnsErrActorNotFoundif the actor is not found. - Ask: Request-response to an actor. Blocks until reply or timeout.
messageacceptsany(must be serializable). ReturnsErrActorNotFoundif the actor is not found. - TellGrain: Tell a grain.
messagemust beproto.Message. The grain kind must be registered on the cluster viaRegisterGrainKind. By default the call returns once the hosting node has processed the message and surfaces the error the handler reported; passclient.WithOneWay()to return once that node has enqueued the message, without waiting for the grain to process it. See one-way tells. - AskGrain: Request-response to a grain.
messageacceptsany. The grain kind must be registered on the cluster.
remote.GrainRequest{Name: "id", Kind: "MyGrain"}. Name and Kind are required and are trimmed of
whitespace.
Spawning and lifecycle
- Spawn: Spawn an actor on a node (uses default balancer). Returns error only; does not return the actor address.
- SpawnBalanced: Spawn with a specific balancing strategy for that call.
- ReSpawn: Restart an actor (stop and spawn again). If the actor is not found, returns
nil(no error). - Stop: Stop an actor. If the actor is not found, returns
nil(no error). - Reinstate: Reinstate a suspended actor. If the actor is not found, returns
nil(no error).
WithKinds when creating the actor system. SpawnRequest requires
Name and Kind; optional fields include Singleton, Relocatable, PassivationStrategy, Supervisor,
Dependencies, EnableStashing, Role, and Reentrancy.
Discovery and inspection
- Exists: Check if an actor is registered in the cluster. Returns
(false, nil)when the actor does not exist; returns an error only on lookup failure (e.g. network). - Kinds: List registered actor kinds. Queries one node (via balancer) and returns kinds from the cluster.
Options
- WithBalancerStrategy: Set load-balancing strategy (default: round-robin).
- WithRefresh: Periodically refresh node weights by querying each node’s load. Used by
LeastLoadStrategyto prefer the least-loaded node.
Balancer strategies
- RoundRobinStrategy: Cycle through nodes in order.
- RandomStrategy: Pick a node at random.
- LeastLoadStrategy: Prefer the node with the lowest load. Requires
WithRefreshto update weights; otherwise weights stay at initial values.
Thread safety
The client is safe for concurrent use by multiple goroutines.Errors
- ErrActorNotFound:
TellorAskwhen the actor is not found in the cluster. - “nodes are required”:
Newwhen the nodes slice is nil or empty. - Proto errors: Various errors from the remote layer (e.g.
CODE_UNAVAILABLE,CODE_DEADLINE_EXCEEDED). - Network errors: Connection failures, timeouts, etc.
See also
- Remoting: Cluster remoting configuration
- Serialization: Message serialization (client must match cluster)
- Code Map:
client/package overview