Skip to content

Instantly share code, notes, and snippets.

@Danthar
Created May 26, 2017 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Danthar/e29493c7ed58eb9e3518df1bd7b3c0a3 to your computer and use it in GitHub Desktop.
Save Danthar/e29493c7ed58eb9e3518df1bd7b3c0a3 to your computer and use it in GitHub Desktop.
Akka.net cluster singleton example
cluster {
seed-nodes = ["akka.tcp://TradingRoomActors@localhost:8083"]
roles = ["traderworker"]
singleton {
singleton-name = "TraderActor"
role = "traderworker"
hand-over-retry-interval = 1s
}
singleton-proxy {
singleton-name = "TradesActor"
role = "tradesworker"
singleton-identification-interval = 1s
buffer-size = 100
}
}
cluster {
seed-nodes = ["akka.tcp://TradingRoomActors@localhost:8083"]
roles = ["tradesworker"]
singleton {
singleton-name = "TradesActor"
role = "tradesworker"
hand-over-retry-interval = 1s
}
singleton-proxy {
singleton-name = "TraderActor"
role = "traderworker"
singleton-identification-interval = 1s
buffer-size = 100
}
}
@Danthar
Copy link
Author

Danthar commented May 26, 2017

@Greatsamps Adding these configs should make your sample work OOB.

Alternatively you can change your Boostrap method to something like this:

   public static IActorRef BootstrapSingleton<T>(this ActorSystem system, string name, string role = null) where T : ActorBase
        {
            var props = ClusterSingletonManager.Props(
                singletonProps: Props.Create<T>(),
                settings: new ClusterSingletonManagerSettings(name, role, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(3)));
            return system.ActorOf(props, typeof(T).Name);
        }

        public static IActorRef BootstrapSingletonProxy(this ActorSystem system, string name, string role, string path, string proxyname)
        {
            var props = ClusterSingletonProxy.Props(
                singletonManagerPath: path,
                settings: new ClusterSingletonProxySettings(name, role, TimeSpan.FromSeconds(1), 100));

            return system.ActorOf(props, proxyname);
        }

With for example when creating a proxy for the TradesActor:

var proxy = tradingRoomActors.BootstrapSingletonProxy("TradesActor","tradesworker","/user/TradesActor", "tradesActorProxy");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment