我是使用 akka.net 的新手,但我认为您可以使用 Akka.Net Cluster + SingletonActor。我在这里进行了一些测试,它似乎工作得很好。
样本:
private void Start() {
var system = ActorSystem.Create("SingletonActorSystem");
var cluster = Cluster.Get(system);
cluster.RegisterOnMemberRemoved(() => MemberRemoved(system));
var actor = system.ActorOf(ClusterSingletonManager.Props(
singletonProps: Props.Create<ProcessorCoordinatorActor>(),
terminationMessage: PoisonPill.Instance,
settings: ClusterSingletonManagerSettings.Create(system)),
name: "processorCoordinator");
Console.ReadLine();
cluster.Leave(cluster.SelfAddress);
_leaveClusterEvent.WaitOne();
}
private async void MemberRemoved(ActorSystem actorSystem) {
await actorSystem.Terminate();
_leaveClusterEvent.Set();
}
配置:
akka {
suppress-json-serializer-warning = on
actor {
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
}
remote {
helios.tcp {
port = 0
hostname = localhost
}
}
cluster {
auto-down-unreachable-after = 5s
down-removal-margin = 5s
seed-nodes = [ "akka.tcp://SingletonActorSystem@127.0.0.1:4053" ]
roles = [worker]
singleton {
singleton-name = "processorCoordinator"
role = "worker"
hand-over-retry-interval = 5s
}
}
}