protected ClusterSingletonManagerStartupSpec() : base(new ClusterSingletonManagerStartupConfig()) { EchoProxy = new Lazy <IActorRef>(() => Sys.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: "/user/echo", settings: ClusterSingletonProxySettings.Create(Sys)), name: "echoProxy")); }
/// <summary> /// Creates a proxy to communicate with cluster singleton initialized by the seed. /// </summary> static void RunClusterSingletonClient(ActorSystem system) { var proxyRef = system.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: "/user/manager", settings: ClusterSingletonProxySettings.Create(system).WithRole("worker")), name: "managerProxy"); }
private void CreateSingletonProxy() { Sys.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: "/user/consumer", settings: ClusterSingletonProxySettings.Create(Sys).WithRole("worker")), name: "consumerProxy"); }
private static async Task Main() { Console.WriteLine("Starting sender system..."); var system = ActorSystem.Create("ClusterSys", ConfigurationFactory.ParseString(File.ReadAllText("Akka.hocon"))); Console.ReadKey(); system.ActorOf(ClusterSingletonManager.Props( Props.Create <SingletonActor>(), PoisonPill.Instance, ClusterSingletonManagerSettings.Create(system).WithRole("b") ), "single"); system.ActorOf(ClusterSingletonProxy.Props("/user/single", ClusterSingletonProxySettings.Create(system).WithRole("b")), "singleProxy").Tell("Hello to singletone!"); var message = "initial message"; var mediator = DistributedPubSub.Get(system).Mediator; mediator.Tell(new Send("/user/invoker", "Remote hello to singleton!")); while (!message.Equals("Stop")) { Console.WriteLine("New message:"); message = Console.ReadLine(); mediator.Tell(new Send("/user/ping", message, false)); } Console.WriteLine("Terminating system."); await system.Terminate(); Console.WriteLine("Bye..."); }
public ClusterSingletonManagerLeaseSpecConfig() { Controller = Role("controller"); First = Role("first"); Second = Role("second"); Third = Role("third"); Fourth = Role("fourth"); CommonConfig = ConfigurationFactory.ParseString(@" akka.loglevel = DEBUG akka.actor.provider = ""cluster"" akka.remote.log-remote-lifecycle-events = off #akka.cluster.auto-down-unreachable-after = off #akka.cluster.downing-provider-class = akka.cluster.testkit.AutoDowning akka.cluster.auto-down-unreachable-after = 0s akka.cluster.testkit.auto-down-unreachable-after = 0s test-lease { lease-class = ""Akka.Cluster.Tools.Tests.MultiNode.TestLeaseActorClient, Akka.Cluster.Tools.Tests.MultiNode"" heartbeat-interval = 1s heartbeat-timeout = 120s lease-operation-timeout = 3s } akka.cluster.singleton { use-lease = ""test-lease"" } ") .WithFallback(ClusterSingletonManager.DefaultConfig()) .WithFallback(ClusterSingletonProxy.DefaultConfig()) .WithFallback(MultiNodeClusterSpec.ClusterConfig()); NodeConfig(new[] { First, Second, Third, Fourth }, new[] { ConfigurationFactory.ParseString(@" akka.cluster.roles = [worker] ") }); }
public static ClusterStartupTask Apply( ActorSystem system, string taskName, Func <Task <Done> > task, TimeSpan taskTimeout, Option <string> role, TimeSpan minBackoff, TimeSpan maxBackoff, double randomBackoffFactor) { var startupTaskProps = Akka.Actor.Props.Create( () => new ClusterStartupTaskActor( task, taskTimeout ) ); var backoffProps = BackoffSupervisor.PropsWithSupervisorStrategy( startupTaskProps, taskName, minBackoff, maxBackoff, randomBackoffFactor, SupervisorStrategy.StoppingStrategy ); var singletonProps = ClusterSingletonManager.Props( backoffProps, PoisonPill.Instance, ClusterSingletonManagerSettings.Create(system) ); var singleton = system.ActorOf(singletonProps, $"{taskName}-singleton"); var singletonProxy = system.ActorOf( ClusterSingletonProxy.Props( singletonManagerPath: singleton.Path.ToStringWithoutAddress(), settings: ClusterSingletonProxySettings.Create(system).WithRole(role.Value) ), $"{taskName}-singletonProxy" ); return(new ClusterStartupTask(singletonProxy)); }
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)); }
protected ClusterSingletonManagerLeaveSpec(ClusterSingletonManagerLeaveSpecConfig config) : base(config, typeof(ClusterSingletonManagerLeaveSpec)) { _config = config; _echoProxy = new Lazy <IActorRef>(() => Watch(Sys.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: "/user/echo", settings: ClusterSingletonProxySettings.Create(Sys)), name: "echoProxy"))); }
IActorRef GetClusterSingletonProxy(ActorSystem ActorSystem) { Props clusterSingletonProxyProps = ClusterSingletonProxy.Props( singletonManagerPath: "/user/singletonManager", settings: ClusterSingletonProxySettings.Create(ActorSystem)); var proxy = ActorSystem.ActorOf(clusterSingletonProxyProps, name: "consumerProxy"); return(proxy); }
public static void AddSystemActor(this IServiceCollection services) { var sc = services.BuildServiceProvider(); services.AddSingleton <ActorSystem>(s => { var serilogger = s.GetService <ILogger>(); var fs = sc.GetService <IBaseFileFactory>(); var conf = ConfigurationFactory.ParseString(fs.ReadRelative("web.hocon")); var system = ActorSystem.Create("sbk", conf); // Create actors var playerMgr = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "player-managers"); var playerHub = s.GetService <IHubContext <PlayerHub> >(); // local hub actor var webHub = system.ActorOf(WebHub.Props(playerHub), "web-hub"); // cluster-enabled hub router system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "hub"); var logger = system.Log; logger.Info($"Player Manager: ------->>> {playerMgr}"); logger.Info($"{system.Name}"); return(system); }); services.AddTransient <Startup.PlayerManagerProvider>(s => { var sys = s.GetService <ActorSystem>(); return(() => sys.ActorSelection("/user/player-managers")); }); services.AddTransient <Startup.PlayerBookProxyProvider>(s => { var sys = s.GetService <ActorSystem>(); var logger = sys.Log; var playerBook = sys.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: "/user/playerbook", settings: ClusterSingletonProxySettings.Create(sys) .WithRole("player-manager")), name: "playerbook-proxy"); logger.Info($"Playerbook ----->> {playerBook}"); return(() => playerBook); }); services.AddTransient <Startup.WebHubProvider>(s => { var sys = s.GetService <ActorSystem>(); return(() => sys.ActorSelection("/user/web-hub")); }); }
public void Restarting_cluster_node_during_hand_over_must_restart_singletons_in_restarted_node() { Join(_sys1, _sys1); Join(_sys2, _sys1); Join(_sys3, _sys1); var proxy3 = _sys3.ActorOf( ClusterSingletonProxy.Props("user/echo", ClusterSingletonProxySettings.Create(_sys3).WithRole("singleton")), "proxy3"); Within(TimeSpan.FromSeconds(5), () => { AwaitAssert(() => { var probe = CreateTestProbe(_sys3); proxy3.Tell("hello", probe.Ref); probe.ExpectMsg <UniqueAddress>(TimeSpan.FromSeconds(1)) .Should() .Be(Cluster.Get(_sys1).SelfUniqueAddress); }); }); Cluster.Get(_sys1).Leave(Cluster.Get(_sys1).SelfAddress); // at the same time, shutdown sys2, which would be the expected next singleton node Shutdown(_sys2); // it will be downed by the join attempts of the new incarnation // then restart it // ReSharper disable once PossibleInvalidOperationException var sys2Port = Cluster.Get(_sys2).SelfAddress.Port.Value; var sys4Config = ConfigurationFactory.ParseString(@"akka.remote.dot-netty.tcp.port=" + sys2Port) .WithFallback(_sys1.Settings.Config); _sys4 = ActorSystem.Create(_sys1.Name, sys4Config); Join(_sys4, _sys3); // let it stabilize Task.Delay(TimeSpan.FromSeconds(5)).Wait(); Within(TimeSpan.FromSeconds(10), () => { AwaitAssert(() => { var probe = CreateTestProbe(_sys3); proxy3.Tell("hello2", probe.Ref); // note that sys3 doesn't have the required singleton role, so singleton instance should be // on the restarted node probe.ExpectMsg <UniqueAddress>(TimeSpan.FromSeconds(1)) .Should() .Be(Cluster.Get(_sys4).SelfUniqueAddress); }); }); }
public static IActorRef StartSingletonSubscriberProxy(ActorSystem actorSystem, string roleName) { var name = typeof(TDomainEventSubscriber).Name; var proxy = actorSystem.ActorOf(ClusterSingletonProxy.Props( $"/user/{name}", ClusterSingletonProxySettings.Create(actorSystem).WithRole(roleName).WithSingletonName(name)), $"{name}Proxy"); return(proxy); }
protected ClusterSingletonManagerLeaveSpec(ClusterSingletonManagerLeaveSpecConfig config) : base(config) { _first = config.First; _second = config.Second; _third = config.Third; _echoProxy = new Lazy <IActorRef>(() => Sys.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: "/user/echo", settings: ClusterSingletonProxySettings.Create(Sys)), "echoProxy")); }
static void Main(string[] args) { var config = ConfigurationFactory.ParseString(File.ReadAllText("App.Akka.conf")); // // "{app-name} - akka.tcp://{actorysystem-name}@{hostname}:{port}" // Console.Title = $"{config.GetString("akka.system.app-name")}" + $" - akka.tcp://{config.GetString("akka.system.actorsystem-name")}" + $"@{config.GetString("akka.remote.dot-netty.tcp.hostname")}" + $":{config.GetString("akka.remote.dot-netty.tcp.port")}"; ActorSystem system = ActorSystem.Create("ClusterLab", config); system.ActorOf(ClusterSingletonManager .Props( singletonProps: MySingletonActor.Props(), terminationMessage: PoisonPill.Instance, settings: ClusterSingletonManagerSettings.Create(system) .WithRole("Provider")), name: "ConsumerSingleton"); IActorRef singletonProxyActor = system.ActorOf(ClusterSingletonProxy .Props( singletonManagerPath: "/user/ConsumerSingleton", settings: ClusterSingletonProxySettings.Create(system) .WithRole("Provider")), name: "ConsumerProxy"); system.Scheduler.ScheduleTellRepeatedly( TimeSpan.Zero, TimeSpan.FromSeconds(4), singletonProxyActor, $"Message from process {Process.GetCurrentProcess().Id}", Nobody.Instance); // // TODO ClusterSingletonManagerSettings 세부 설정 // - WithHandOverRetryInterval // - WithRemovalMargin // - WithRole // - WithSingletonName // Console.WriteLine(); Console.WriteLine("NonSeedNode1 is running..."); Console.WriteLine(); Console.ReadLine(); }
public ClusterSingletonManagerStartupConfig() { First = Role("first"); Second = Role("second"); Third = Role("third"); CommonConfig = ConfigurationFactory.ParseString(@" akka.loglevel = INFO akka.actor.provider = ""Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"" akka.remote.log-remote-lifecycle-events = off akka.cluster.auto-down-unreachable-after = 0s") .WithFallback(ClusterSingletonManager.DefaultConfig()) .WithFallback(ClusterSingletonProxy.DefaultConfig()) .WithFallback(MultiNodeClusterSpec.ClusterConfig()); }
private static Config GetConfig() { return(ConfigurationFactory.ParseString(@" akka.actor.provider = cluster akka.remote.dot-netty.tcp.port = 0 akka.remote.dot-netty.tcp.hostname = 127.0.0.1 # ping often/start fast for test akka.cluster.sharded-daemon-process.keep-alive-interval = 1s akka.coordinated-shutdown.terminate-actor-system = off akka.coordinated-shutdown.run-by-actor-system-terminate = off") .WithFallback(ClusterSharding.DefaultConfig()) .WithFallback(ClusterSingletonProxy.DefaultConfig())); }
public Task StartAsync(CancellationToken cancellationToken) { var config = ConfigurationFactory.ParseString(File.ReadAllText("app.conf")).BootstrapFromDocker(); var bootstrap = BootstrapSetup.Create() .WithConfig(config) // load HOCON .WithActorRefProvider(ProviderSelection.Cluster.Instance); // launch Akka.Cluster // N.B. `WithActorRefProvider` isn't actually needed here - the HOCON file already specifies Akka.Cluster // enable DI support inside this ActorSystem, if needed var diSetup = ServiceProviderSetup.Create(_serviceProvider); // merge this setup (and any others) together into ActorSystemSetup var actorSystemSetup = bootstrap.And(diSetup); ThreadPool.GetMinThreads(out var workerThreads, out var completionThreads); Console.WriteLine("Min threads: {0}, Min I/O threads: {1}", workerThreads, completionThreads); ThreadPool.SetMinThreads(0, 0); // start ActorSystem _clusterSystem = ActorSystem.Create("ClusterSys", actorSystemSetup); DebugConfigurator("akka.actor.default-dispatcher", _clusterSystem); DebugConfigurator("akka.actor.internal-dispatcher", _clusterSystem); DebugConfigurator("akka.remote.default-remote-dispatcher", _clusterSystem); DebugConfigurator("akka.remote.backoff-remote-dispatcher", _clusterSystem); // instantiate actors BenchmarkHostRouter = _clusterSystem.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "host-router"); BenchmarkCoordinatorManager = _clusterSystem.ActorOf(ClusterSingletonManager.Props( singletonProps: Props.Create(() => new BenchmarkCoordinator(2, 6, BenchmarkHostRouter)), terminationMessage: PoisonPill.Instance, settings: ClusterSingletonManagerSettings.Create(_clusterSystem)), "coordinator"); BenchmarkCoordinator = _clusterSystem.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: "/user/coordinator", settings: ClusterSingletonProxySettings.Create(_clusterSystem)), "coordinator-proxy"); BenchmarkHost = _clusterSystem.ActorOf(Props.Create(() => new BenchmarkHost(BenchmarkCoordinator)), "host"); Akka.Cluster.Cluster.Get(_clusterSystem).RegisterOnMemberRemoved(() => { _lifetime.StopApplication(); // when the ActorSystem terminates, terminate the process }); return(Task.CompletedTask); }
static void Main(string[] args) { Console.WriteLine("Hello from MemoryWallet!"); var system = DI.Provider.GetService <ActorSystem>(); var logger = system.Log; logger.Info($"Joining cluster {system.Name}"); // Singleton actor that keeps book of record of a player system.ActorOf(ClusterSingletonManager.Props( singletonProps: PlayerBook.Props(), terminationMessage: PoisonPill.Instance, settings: ClusterSingletonManagerSettings.Create(system).WithRole("player-manager") ), "playerbook"); system.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: "/user/playerbook", settings: ClusterSingletonProxySettings.Create(system) .WithRole("player-manager")), name: "playerbook-proxy"); // Register web hub across cluster var hub = system.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "hub"); // create local player manager instances with router. var pm = system.ActorOf(PlayerManagerActor.Props(), "player-manager"); // var pm = system.ActorOf( // PlayerManagerActor.Props().WithRouter(FromConfig.Instance), // "player-manager"); hub.Tell("dsadsada"); pm.Tell(new PlayerManagerActor.HelloWorld("hello world")); logger.Info($"{pm.Path} created."); Console.ReadLine(); CoordinatedShutdown.Get(system) .Run(CoordinatedShutdown.ClrExitReason.Instance) .Wait(); }
public IActorRef Start() { var dispatcher = _system.ActorOf(ClusterSingletonManager.Props( Props.Create <ReportingActor>(), PoisonPill.Instance, ClusterSingletonManagerSettings.Create(_system).WithRole(KnownRoles.Projection) ), name: "reporting"); ReportingActor = _system.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: "/user/reporting", settings: ClusterSingletonProxySettings.Create(_system).WithRole(KnownRoles.Projection)), name: "reportingProxy"); ReportingActor.Tell(Reports.ReportingActor.Start.Instance); return(ReportingActor); }
private void BecomeReady() { Become(Ready); _logger.Info("JobMaster is becoming ready."); var proxy = Context.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: "/user/jobmanager", settings: ClusterSingletonProxySettings.Create(Context.System).WithRole("worker")), name: "managerProxy"); _workerRouter = Context.ActorOf(new ClusterRouterPool( local: new RandomPool(1), settings: new ClusterRouterPoolSettings(30, 1, true, "worker") ).Props(Props.Create(() => new Worker(proxy)))); Context.ActorOf(Props.Create(() => new JobTasker(Self)), "jobtasker"); _workItem = 0; }
static void Main(string[] args) { var config = ConfigurationFactory.ParseString(configString).WithFallback(ClusterSingletonManager.DefaultConfig()); var system = ActorSystem.Create("cluster-system", config); var client = system .ActorOf( ClusterSingletonProxy.Props("/user/consumer", ClusterSingletonProxySettings.Create(system).WithRole("worker"))); while (true) { Thread.Sleep(1000); client.Tell(DateTime.Now.ToLongTimeString()); } Console.ReadKey(); }
internal static async Task Main() { Console.WriteLine("Starting Akka System..."); var system = ActorSystem.Create("ClusterSys", ConfigurationFactory.ParseString(File.ReadAllText("Akka.hocon"))); system.ActorOf(Props.Create <AMediatorReceiver>(), "ping"); system.ActorOf(Props.Create <AClusterInvoker>(), "invoker"); // singleton proxy system.ActorOf(ClusterSingletonProxy.Props("/user/single", ClusterSingletonProxySettings.Create(system).WithRole("b")), "singletonProxy"); Console.WriteLine("System started. Press Enter to terminate..."); Console.ReadLine(); await system.Terminate(); Console.WriteLine("Cluster is terminated. Bye..."); }
public ActorSys(string name = "ClusterSingletonProxySystem", Address joinTo = null) : base(ActorSystem.Create(name, ConfigurationFactory.ParseString(_cfg).WithFallback(TestKit.Configs.TestConfigs.DefaultConfig))) { Cluster = Cluster.Get(Sys); if (joinTo != null) { Cluster.Join(joinTo); } Cluster.RegisterOnMemberUp(() => { Sys.ActorOf(ClusterSingletonManager.Props(Props.Create(() => new Singleton()), PoisonPill.Instance, ClusterSingletonManagerSettings.Create(Sys) .WithRemovalMargin(TimeSpan.FromSeconds(5))), "singletonmanager"); }); Proxy = Sys.ActorOf(ClusterSingletonProxy.Props("user/singletonmanager", ClusterSingletonProxySettings.Create(Sys)), $"singletonProxy-{Cluster.SelfAddress.Port ?? 0}"); }
public ClusterSingletonManagerChaosConfig() { Controller = Role("controller"); First = Role("_config.First"); Second = Role("second"); Third = Role("third"); Fourth = Role("fourth"); Fifth = Role("fifth"); Sixth = Role("sixth"); CommonConfig = ConfigurationFactory.ParseString(@" akka.loglevel = DEBUG akka.actor.provider = ""Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"" akka.remote.log-remote-lifecycle-events = off akka.cluster.auto-down-unreachable-after = 0s ") .WithFallback(ClusterSingletonManager.DefaultConfig()) .WithFallback(ClusterSingletonProxy.DefaultConfig()) .WithFallback(MultiNodeClusterSpec.ClusterConfig()); }
public static async Task Main(string[] args) { var config = ConfigurationFactory.ParseString(AtmHocon); var actorSystem = ActorSystem.Create(ClusterName, config); var clusterSystem = Cluster.Get(actorSystem); clusterSystem.RegisterOnMemberUp(() => { var atm = actorSystem.ActorOf(Props.Create(() => new AtmV3Actor()), "atm-terry-avenue"); var bankProxy = actorSystem.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: $"/user/{BankActorName}", settings: ClusterSingletonProxySettings.Create(actorSystem).WithRole(BankRoleName)), name: $"{BankActorName}-proxy"); atm.Tell(new BasicBank.Messages.Bank.SetBank(bankProxy)); }); while (true) { await Task.Delay(10); } }
public void Cluster_singleton_manager_with_lease_should_Start_singleton_and_ping_from_all_nodes() { RunOn(() => { Sys.ActorOf( ClusterSingletonManager.Props( ClusterSingletonManagerLeaseSpecConfig.ImportantSingleton.Props, PoisonPill.Instance, ClusterSingletonManagerSettings.Create(Sys).WithRole("worker")), "important"); }, _config.First, _config.Second, _config.Third, _config.Fourth); EnterBarrier("singleton-started"); var proxy = Sys.ActorOf( ClusterSingletonProxy.Props( singletonManagerPath: "/user/important", settings: ClusterSingletonProxySettings.Create(Sys).WithRole("worker"))); RunOn(() => { proxy.Tell("Ping"); // lease has not been granted so now allowed to come up ExpectNoMsg(TimeSpan.FromSeconds(2)); }, _config.First, _config.Second, _config.Third, _config.Fourth); EnterBarrier("singleton-pending"); RunOn(() => { TestLeaseActorClientExt.Get(Sys).GetLeaseActor().Tell(TestLeaseActor.GetRequests.Instance); ExpectMsg <TestLeaseActor.LeaseRequests>(msg => msg.Requests.Should().BeEquivalentTo(new TestLeaseActor.Acquire(GetAddress(_config.First).HostPort()))); TestLeaseActorClientExt.Get(Sys).GetLeaseActor().Tell(new TestLeaseActor.ActionRequest(new TestLeaseActor.Acquire(GetAddress(_config.First).HostPort()), true)); }, _config.Controller); EnterBarrier("lease-acquired"); RunOn(() => { ExpectMsg(new ClusterSingletonManagerLeaseSpecConfig.ImportantSingleton.Response("Ping", GetAddress(_config.First))); }, _config.First, _config.Second, _config.Third, _config.Fourth); EnterBarrier("pinged"); }
public ClusterSingletonManagerSpecConfig() { Controller = Role("controller"); Observer = Role("observer"); First = Role("first"); Second = Role("second"); Third = Role("third"); Fourth = Role("fourth"); Fifth = Role("fifth"); Sixth = Role("sixth"); CommonConfig = ConfigurationFactory.ParseString(@" akka.loglevel = INFO akka.actor.provider = ""Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"" akka.remote.log-remote-lifecycle-events = off akka.cluster.auto-down-unreachable-after = 0s ") .WithFallback(ClusterSingletonManager.DefaultConfig()) .WithFallback(ClusterSingletonProxy.DefaultConfig()) .WithFallback(MultiNodeClusterSpec.ClusterConfig()); NodeConfig(new[] { First, Second, Third, Fourth, Fifth, Sixth }, new[] { ConfigurationFactory.ParseString(@"akka.cluster.roles = [worker]") }); }
public static async Task Main(string[] args) { var config = ConfigurationFactory.ParseString(BankHocon); var actorSystem = ActorSystem.Create(ClusterName, config); var clusterSystem = Cluster.Get(actorSystem); clusterSystem.RegisterOnMemberUp(() => { actorSystem.ActorOf(ClusterSingletonManager.Props( Props.Create(() => new BasicBank.Actors.BankV2Actor()), settings: ClusterSingletonManagerSettings.Create(actorSystem).WithRole(BankRoleName)), BankActorName); var bankProxy = actorSystem.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: $"/user/{BankActorName}", settings: ClusterSingletonProxySettings.Create(actorSystem).WithRole(BankRoleName)), name: $"{BankActorName}-proxy"); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("BANK NODE UP!"); Console.WriteLine("ADD Billy White."); bankProxy.Tell(new CreateCustomerRequest(new Customer(123, "Billy White"))); Console.WriteLine("ADD Sally Brown."); bankProxy.Tell(new CreateCustomerRequest(new Customer(456, "Sally Brown"))); Console.WriteLine("ADD Wally Green."); bankProxy.Tell(new CreateCustomerRequest(new Customer(789, "Wally Green"))); Console.ResetColor(); }); while (true) { await Task.Delay(10); } }
public void Restarting_cluster_node_with_same_hostname_and_port_must_handover_to_next_oldest() { Join(_sys1, _sys1); Join(_sys2, _sys1); var proxy2 = _sys2.ActorOf( ClusterSingletonProxy.Props("user/echo", ClusterSingletonProxySettings.Create(_sys2)), "proxy2"); Within(TimeSpan.FromSeconds(5), () => { AwaitAssert(() => { var probe = CreateTestProbe(_sys2); proxy2.Tell("hello", probe.Ref); probe.ExpectMsg("hello", TimeSpan.FromSeconds(1)); }); }); Shutdown(_sys1); // it will be downed by the join attempts of the new incarnation // ReSharper disable once PossibleInvalidOperationException var sys1Port = Cluster.Get(_sys1).SelfAddress.Port.Value; var sys3Config = ConfigurationFactory.ParseString(@"akka.remote.dot-netty.tcp.port=" + sys1Port) .WithFallback(_sys1.Settings.Config); _sys3 = ActorSystem.Create(_sys1.Name, sys3Config); Join(_sys3, _sys2); Within(TimeSpan.FromSeconds(5), () => { AwaitAssert(() => { var probe = CreateTestProbe(_sys2); proxy2.Tell("hello2", probe.Ref); probe.ExpectMsg("hello2", TimeSpan.FromSeconds(1)); }); }); Cluster.Get(_sys2).Leave(Cluster.Get(_sys2).SelfAddress); Within(TimeSpan.FromSeconds(15), () => { AwaitAssert(() => { Cluster.Get(_sys3) .State.Members.Select(x => x.UniqueAddress) .Should() .Equal(Cluster.Get(_sys3).SelfUniqueAddress); }); }); var proxy3 = _sys3.ActorOf(ClusterSingletonProxy.Props("user/echo", ClusterSingletonProxySettings.Create(_sys3)), "proxy3"); Within(TimeSpan.FromSeconds(5), () => { AwaitAssert(() => { var probe = CreateTestProbe(_sys3); proxy3.Tell("hello3", probe.Ref); probe.ExpectMsg("hello3", TimeSpan.FromSeconds(1)); }); }); }
public void Start() { SystemActors.ClusterSystem = SystemHostFactory.Launch(); // Create and build the container var container = new Ninject.StandardKernel(); container.Bind <IFileProcessorRepository>().To(typeof(FileProcessorRepository)).InTransientScope(); container.Bind <DistributedPubSub>().ToConstant(DistributedPubSub.Get(SystemActors.ClusterSystem)); // Create the dependency resolver for the actor system IDependencyResolver resolver = new NinjectDependencyResolver(container, SystemActors.ClusterSystem); var pbm = PetabridgeCmd.Get(SystemActors.ClusterSystem); pbm.RegisterCommandPalette(ClusterCommands.Instance); // enable cluster management commands pbm.Start(); SystemActors.SettingsWatcherRef = SystemActors.ClusterSystem.ActorOf(SystemActors.ClusterSystem.DI().Props <DatabaseWatcherActor>(), "DatabaseWatcher"); SystemActors.Mediator = DistributedPubSub.Get(SystemActors.ClusterSystem).Mediator; SystemActors.LocationManagerActorRef = SystemActors.ClusterSystem.ActorOf(ClusterSingletonManager.Props( singletonProps: Props.Create(() => new LocationManagerActor()), // Props used to create actor singleton terminationMessage: PoisonPill.Instance, // message used to stop actor gracefully settings: ClusterSingletonManagerSettings.Create(SystemActors.ClusterSystem).WithRole(StaticMethods.GetServiceWorkerRole())), // cluster singleton manager settings name: ActorPaths.SingletonManagerActor.Name); SystemActors.LocationManagerProxyRef = SystemActors.ClusterSystem.ActorOf(ClusterSingletonProxy.Props( singletonManagerPath: ActorPaths.SingletonManagerActor.Path, settings: ClusterSingletonProxySettings.Create(SystemActors.ClusterSystem).WithRole(StaticMethods.GetServiceWorkerRole())), name: ActorPaths.SingletonManagerProxy.Name); }