dactor-discover-aws
AWS node discovery for the dactor distributed actor framework.
Discovery mechanisms
| Strategy | Struct | How it works |
|---|---|---|
| Auto Scaling Group | AutoScalingDiscovery |
Lists instances in a named ASG, filters for InService + Healthy, and returns their IP addresses. |
| EC2 Tags | Ec2TagDiscovery |
Queries DescribeInstances with a tag key/value filter and returns IPs of running instances. |
Both strategies implement the dactor::ClusterDiscovery trait.
How dactor uses discovery
The ClusterDiscovery trait provides a discover() method that returns peer node addresses. The dactor runtime uses this as follows:
- On startup: The runtime calls
discover()to find initial peers and connects to them viaAdapterCluster::connect(). - Periodic polling: The application is responsible for calling
discover()periodically (e.g., via a timer) to detect topology changes — new nodes joining or leaving the ASG/cluster. - Diff and reconcile: Compare discovered peers with currently connected nodes. Connect to new peers, optionally disconnect removed ones.
- Events: The
ClusterEventEmitterfiresNodeJoined/NodeLeftevents that actors can subscribe to viaClusterEvents.
Example: polling loop
use HashSet;
use Duration;
let discovery = builder
.asg_name
.port
.build;
let mut known_peers: = new;
loop
Note: The current
ClusterDiscoverytrait is synchronous and one-shot. PUB4 (planned) will make it async and returnResultfor proper error handling. A built-in polling/reconciliation loop may be added to the dactor core in a future release.
Usage
Auto Scaling Group discovery
use AutoScalingDiscovery;
use ClusterDiscovery;
let discovery = builder
.asg_name
.port
.region
.build;
// Synchronous (requires a tokio runtime on the current thread)
let peers = discovery.discover;
// Async
// let peers = discovery.discover_async().await?;
EC2 tag discovery
use Ec2TagDiscovery;
use ClusterDiscovery;
let discovery = builder
.tag_key
.tag_value
.port
.build;
let peers = discovery.discover;
IAM policy (least privilege)
Environment variables
| Variable | Description |
|---|---|
DACTOR_INSTANCE_IP |
Override the current instance's private IP. |
DACTOR_INSTANCE_ID |
Override the current instance's ID. |
AWS_REGION |
AWS region (also used by the AWS SDK). |
AWS_DEFAULT_REGION |
Fallback region when AWS_REGION is not set. |
Helper functions instance_private_ip(), instance_id(), and current_region() read these variables.
License
MIT