public static void Main(string[] args) { if (!int.TryParse(args[0], out var nodeId)) { Console.Error.WriteLine("Please supply a node ID"); return; } var config = GetAkkaConfig(nodeId); using (var system = ActorSystem.Create("demo-cluster", config)) { var cmd = PetabridgeCmd.Get(system); cmd.RegisterCommandPalette(ClusterCommands.Instance); cmd.Start(); system.ActorOf(ClusterSingletonManager.Props( singletonProps: Props.Create <SenderActor>(), terminationMessage: PoisonPill.Instance, settings: ClusterSingletonManagerSettings.Create(system)), name: "sender"); var props = Props.Create <ReceiverActor>().WithRouter(FromConfig.Instance); system.ActorOf(props, "receivers"); Console.ReadLine(); } }
private void CreateCoordinator() { var typeNames = new[] { "counter", "rebalancingCounter", "PersistentCounterEntities", "AnotherPersistentCounter", "PersistentCounter", "RebalancingPersistentCounter", "AutoMigrateRegionTest" }; foreach (var typeName in typeNames) { var rebalanceEnabled = string.Equals(typeName, "rebalancing", StringComparison.InvariantCultureIgnoreCase); var singletonProps = Props.Create(() => new BackoffSupervisor( CoordinatorProps(typeName, rebalanceEnabled), "coordinator", TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), 0.1)).WithDeploy(Deploy.Local); Sys.ActorOf(ClusterSingletonManager.Props( singletonProps, PoisonPill.Instance, ClusterSingletonManagerSettings.Create(Sys)), typeName + "Coordinator"); } }
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)); }
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..."); }
/// <summary> /// TBD /// </summary> /// <param name="coordinatorSingletonSettings">TBD</param> /// <exception cref="ArgumentNullException"> /// This exception is thrown when the specified <paramref name="coordinatorSingletonSettings"/> is undefined. /// </exception> /// <returns>TBD</returns> public ClusterShardingSettings WithCoordinatorSingletonSettings(ClusterSingletonManagerSettings coordinatorSingletonSettings) { if (coordinatorSingletonSettings == null) throw new ArgumentNullException(nameof(coordinatorSingletonSettings), $"ClusterShardingSettings requires {nameof(coordinatorSingletonSettings)} to be provided"); return Copy(coordinatorSingletonSettings: coordinatorSingletonSettings); }
private void CreateCoordinator() { var typeNames = new[] { "counter", "rebalancingCounter", "RememberCounterEntities", "AnotherRememberCounter", "RememberCounter", "RebalancingRememberCounter", "AutoMigrateRememberRegionTest" }; foreach (var typeName in typeNames) { var rebalanceEnabled = typeName.ToLowerInvariant().StartsWith("rebalancing"); var rememberEnabled = typeName.ToLowerInvariant().Contains("remember"); var singletonProps = BackoffSupervisor.Props( CoordinatorProps(typeName, rebalanceEnabled, rememberEnabled), "coordinator", TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), 0.1).WithDeploy(Deploy.Local); Sys.ActorOf(ClusterSingletonManager.Props( singletonProps, PoisonPill.Instance, ClusterSingletonManagerSettings.Create(Sys)), typeName + "Coordinator"); } }
/// <summary> /// TBD /// </summary> /// <param name="config">TBD</param> /// <param name="singletonConfig">TBD</param> /// <returns>TBD</returns> public static ClusterShardingSettings Create(Config config, Config singletonConfig) { var tuningParameters = new TunningParameters( coordinatorFailureBackoff: config.GetTimeSpan("coordinator-failure-backoff"), retryInterval: config.GetTimeSpan("retry-interval"), bufferSize: config.GetInt("buffer-size"), handOffTimeout: config.GetTimeSpan("handoff-timeout"), shardStartTimeout: config.GetTimeSpan("shard-start-timeout"), shardFailureBackoff: config.GetTimeSpan("shard-failure-backoff"), entityRestartBackoff: config.GetTimeSpan("entity-restart-backoff"), rebalanceInterval: config.GetTimeSpan("rebalance-interval"), snapshotAfter: config.GetInt("snapshot-after"), keepNrOfBatches: config.GetInt("keep-nr-of-batches"), leastShardAllocationRebalanceThreshold: config.GetInt("least-shard-allocation-strategy.rebalance-threshold"), leastShardAllocationMaxSimultaneousRebalance: config.GetInt("least-shard-allocation-strategy.max-simultaneous-rebalance"), waitingForStateTimeout: config.GetTimeSpan("waiting-for-state-timeout"), updatingStateTimeout: config.GetTimeSpan("updating-state-timeout"), entityRecoveryStrategy: config.GetString("entity-recovery-strategy"), entityRecoveryConstantRateStrategyFrequency: config.GetTimeSpan("entity-recovery-constant-rate-strategy.frequency"), entityRecoveryConstantRateStrategyNumberOfEntities: config.GetInt("entity-recovery-constant-rate-strategy.number-of-entities")); var coordinatorSingletonSettings = ClusterSingletonManagerSettings.Create(singletonConfig); var role = config.GetString("role"); if (role == string.Empty) role = null; return new ClusterShardingSettings( role: role, rememberEntities: config.GetBoolean("remember-entities"), journalPluginId: config.GetString("journal-plugin-id"), snapshotPluginId: config.GetString("snapshot-plugin-id"), stateStoreMode: (StateStoreMode)Enum.Parse(typeof(StateStoreMode), config.GetString("state-store-mode"), ignoreCase: true), tunningParameters: tuningParameters, coordinatorSingletonSettings: coordinatorSingletonSettings); }
public static DeploymentManager InitDeploymentManager(ActorSystem actorSystem, IMongoClient client, DataTransferManager manager, RepositoryApi api) { var repo = ClusterSingletonManager.Props(Props.Create(() => new DeploymentServerImpl(client, manager, api)), ClusterSingletonManagerSettings.Create(actorSystem).WithRole("UpdateSystem")); return(new DeploymentManager(actorSystem.ActorOf(repo, DeploymentApi.DeploymentPath))); }
public static RepositoryManager InitRepositoryManager(ActorSystem actorSystem, IMongoClient client, DataTransferManager tranferManager) { var repo = ClusterSingletonManager.Props(Props.Create(() => new RepositoryManagerImpl(client, tranferManager)), ClusterSingletonManagerSettings.Create(actorSystem).WithRole("UpdateSystem")); return(new RepositoryManager(actorSystem.ActorOf(repo, RepositoryApi.RepositoryPath))); }
/// <summary> /// Static factory method for creating the a singleton manager and proxy /// of the <see cref="ClusterCommandActor"/> /// </summary> /// <param name="system">The <see cref="ActorSystem"/>within which to create the singleton</param> /// <returns>A tuple containing <see cref="Props"/> for the proxy and manager in a given system</returns> public static (Props proxy, Props manager) CreateSingleton(ActorSystem system, string role) { var managerSettings = ClusterSingletonManagerSettings .Create(system) .WithSingletonName("cluster-command") .WithRemovalMargin(TimeSpan.FromSeconds(2)) .WithHandOverRetryInterval(TimeSpan.FromMilliseconds(200)); managerSettings = role != null?managerSettings.WithRole(role) : managerSettings; var proxySettings = ClusterSingletonProxySettings .Create(system) .WithSingletonName("cluster-command-proxy") .WithBufferSize(1000); proxySettings = role != null?proxySettings.WithRole(role) : proxySettings; var manager = ClusterSingletonManager.Props( Props.Create(() => new ClusterCommandActor()), PoisonPill.Instance, managerSettings ); var proxy = ClusterSingletonProxy.Props( "/user/cluster-command", proxySettings ); return(proxy : proxy, manager : manager); }
public static ClusterShardingSettings Create(Config config, Config singletonConfig) { var tuningParameters = new TunningParameters( coordinatorFailureBackoff: config.GetTimeSpan("coordinator-failure-backoff"), retryInterval: config.GetTimeSpan("retry-interval"), bufferSize: config.GetInt("buffer-size"), handOffTimeout: config.GetTimeSpan("handoff-timeout"), shardStartTimeout: config.GetTimeSpan("shard-start-timeout"), shardFailureBackoff: config.GetTimeSpan("shard-failure-backoff"), entityRestartBackoff: config.GetTimeSpan("entity-restart-backoff"), rebalanceInterval: config.GetTimeSpan("rebalance-interval"), snapshotAfter: config.GetInt("snapshot-after"), leastShardAllocationRebalanceThreshold: config.GetInt("least-shard-allocation-strategy.rebalance-threshold"), leastShardAllocationMaxSimultaneousRebalance: config.GetInt("least-shard-allocation-strategy.max-simultaneous-rebalance")); var coordinatorSingletonSettings = ClusterSingletonManagerSettings.Create(singletonConfig); var role = config.GetString("role"); if (role == string.Empty) { role = null; } return(new ClusterShardingSettings( role: role, rememberEntities: config.GetBoolean("remember-entities"), journalPluginId: config.GetString("journal-plugin-id"), snapshotPluginId: config.GetString("snapshot-plugin-id"), tunningParameters: tuningParameters, coordinatorSingletonSettings: coordinatorSingletonSettings)); }
public static IActorRef BootstrapSingleton <T>(this ActorSystem system, string role = null) where T : ActorBase { var props = ClusterSingletonManager.Props( singletonProps: Props.Create <T>(), settings: ClusterSingletonManagerSettings.Create(system).WithRole(role)); return(system.ActorOf(props, typeof(T).Name)); }
private IActorRef CreateSingleton() { return(Sys.ActorOf(ClusterSingletonManager.Props( singletonProps: ClusterSingletonManagerLeaveSpecConfig.Echo.Props(TestActor), terminationMessage: "stop", settings: ClusterSingletonManagerSettings.Create(Sys)), name: "echo")); }
/// <summary> /// Initializes cluster singleton of the <see cref="WorkerManager"/> actor. /// </summary> /// <param name="system"></param> static void RunClusterSingletonSeed(ActorSystem system) { var aref = system.ActorOf(ClusterSingletonManager.Props( singletonProps: Props.Create(() => new WorkerManager()), terminationMessage: PoisonPill.Instance, settings: ClusterSingletonManagerSettings.Create(system)), name: "manager"); }
private IActorRef CreateSingleton() { return(Sys.ActorOf(ClusterSingletonManager.Props( singletonProps: ClusterSingletonManagerDownedSpecConfig.Echo.Props(TestActor), terminationMessage: PoisonPill.Instance, settings: ClusterSingletonManagerSettings.Create(Sys)), name: "echo")); }
protected override void ConfigImpl() { Context.ActorOf(ClusterSingletonManager.Props(ConfigurationManagerActor.New(CurrentState.Repository), ClusterSingletonManagerSettings.Create(Context.System) .WithRole(RoleName)), "ConfigurationManager"); SupervisorStrategy = SupervisorStrategy.DefaultStrategy; }
private IActorRef CreateSingleton() { return(Sys.ActorOf(ClusterSingletonManager.Props( singletonProps: Props.Create(() => new EchoActor(TestActor)), terminationMessage: PoisonPill.Instance, settings: ClusterSingletonManagerSettings.Create(Sys)), name: "echo")); }
private void CreateSingleton() { Sys.ActorOf(ClusterSingletonManager.Props( singletonProps: Props.Create(() => new Consumer(Queue, TestActor)), terminationMessage: Consumer.End.Instance, settings: ClusterSingletonManagerSettings.Create(Sys).WithRole("worker")), name: "consumer"); }
public ClusterShardingSettings WithCoordinatorSingletonSettings(ClusterSingletonManagerSettings coordinatorSingletonSettings) { if (coordinatorSingletonSettings == null) { throw new ArgumentNullException("coordinatorSingletonSettings"); } return(Copy(coordinatorSingletonSettings: coordinatorSingletonSettings)); }
static int Main(string[] args) { var mongoConnectionString = Environment.GetEnvironmentVariable("MONGO_CONNECTION_STR")?.Trim(); if (string.IsNullOrEmpty(mongoConnectionString)) { Console.WriteLine("ERROR! MongoDb connection string not provided. Can't start."); return(-1); } else { Console.WriteLine("Connecting to MongoDb at {0}", mongoConnectionString); } var config = File.ReadAllText("app.conf"); var conf = ConfigurationFactory.ParseString(config).WithFallback(GetMongoHocon(mongoConnectionString)) .WithFallback(ClusterSharding.DefaultConfig()) .WithFallback(DistributedPubSub.DefaultConfig()); var actorSystem = ActorSystem.Create("AkkaPricing", conf.BootstrapFromDocker()); var readJournal = actorSystem.ReadJournalFor <MongoDbReadJournal>(MongoDbReadJournal.Identifier); Cluster.Cluster.Get(actorSystem).RegisterOnMemberUp(() => { var sharding = ClusterSharding.Get(actorSystem); var shardRegion = sharding.Start("priceAggregator", s => Props.Create(() => new MatchAggregator(s, readJournal)), ClusterShardingSettings.Create(actorSystem), new StockShardMsgRouter()); // used to seed pricing data var singleton = ClusterSingletonManager.Props( Props.Create(() => new PriceInitiatorActor(readJournal, shardRegion)), ClusterSingletonManagerSettings.Create( actorSystem.Settings.Config.GetConfig("akka.cluster.price-singleton"))); var mediator = DistributedPubSub.Get(actorSystem).Mediator; foreach (var stock in AvailableTickerSymbols.Symbols) { actorSystem.ActorOf(Props.Create(() => new PriceVolumeViewActor(stock, shardRegion, mediator)), stock + "-view"); } }); // start Petabridge.Cmd (for external monitoring / supervision) var pbm = PetabridgeCmd.Get(actorSystem); pbm.RegisterCommandPalette(ClusterCommands.Instance); pbm.RegisterCommandPalette(ClusterShardingCommands.Instance); pbm.RegisterCommandPalette(RemoteCommands.Instance); pbm.Start(); actorSystem.WhenTerminated.Wait(); return(0); }
/// <summary> /// TBD /// </summary> /// <param name="role">TBD</param> /// <param name="rememberEntities">TBD</param> /// <param name="journalPluginId">TBD</param> /// <param name="snapshotPluginId">TBD</param> /// <param name="passivateIdleEntityAfter">TBD</param> /// <param name="stateStoreMode">TBD</param> /// <param name="tuningParameters">TBD</param> /// <param name="coordinatorSingletonSettings">TBD</param> public ClusterShardingSettings( string role, bool rememberEntities, string journalPluginId, string snapshotPluginId, TimeSpan passivateIdleEntityAfter, StateStoreMode stateStoreMode, TuningParameters tuningParameters, ClusterSingletonManagerSettings coordinatorSingletonSettings) : this(role, rememberEntities, journalPluginId, snapshotPluginId, passivateIdleEntityAfter, stateStoreMode, tuningParameters, coordinatorSingletonSettings, null) { }
static void Main() { var config = ConfigurationFactory.ParseString(configString).WithFallback(ClusterSingletonManager.DefaultConfig()); var system = ActorSystem.Create("cluster-system", config); var server = system.ActorOf(ClusterSingletonManager.Props( singletonProps: Props.Create <Server>(), terminationMessage: PoisonPill.Instance, settings: ClusterSingletonManagerSettings.Create(system).WithRole("worker")), name: "consumer"); Console.ReadKey(); }
public void RegisterOnMemberUp() { Console.WriteLine(cluster.SelfAddress + "上线....."); var clusterSingletonManagerProps = ClusterSingletonManager.Props( singletonProps: SingleActor.CreateProps(this.actorSystem).WithRouter(new Akka.Routing.RoundRobinPool(5)), terminationMessage: PoisonPill.Instance, settings: ClusterSingletonManagerSettings.Create(ActorSystem)); var singlet = ActorSystem.ActorOf(clusterSingletonManagerProps, name: "singletonManager"); Console.WriteLine("singletonManager:{0}", singlet.Path.ToString()); }
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 void ClusterSingletonManagerSettings_must_have_default_config() { var clusterSingletonManagerSettings = ClusterSingletonManagerSettings.Create(Sys); clusterSingletonManagerSettings.ShouldNotBe(null); clusterSingletonManagerSettings.SingletonName.ShouldBe("singleton"); clusterSingletonManagerSettings.Role.ShouldBe(null); clusterSingletonManagerSettings.HandOverRetryInterval.TotalSeconds.ShouldBe(1); clusterSingletonManagerSettings.RemovalMargin.TotalSeconds.ShouldBe(0); var config = Sys.Settings.Config.GetConfig("akka.cluster.singleton"); config.GetInt("min-number-of-hand-over-retries").ShouldBe(10); }
public void InitializeClusterSystem() { Program.ClusterSystem = ActorSystemFactory.LaunchClusterManager(); GlobalContext.Properties["ipaddress"] = AppSettings.GetIpAddressFromConfig(); Program.ClusterHelper = Program.ClusterSystem.ActorOf(Props.Create(() => new ClusterHelper()), ActorPaths.ClusterHelperActor.Name); Program.ClusterSystem.ActorOf(ClusterSingletonManager.Props( singletonProps: Props.Create(() => new JobManager()), // Props used to create actor singleton terminationMessage: PoisonPill.Instance, // message used to stop actor gracefully settings: ClusterSingletonManagerSettings.Create(Program.ClusterSystem).WithRole("worker")), // cluster singleton manager settings name: "jobmanager"); }
private IActorRef CreateSingleton() { /** * system.actorOf(ClusterSingletonManager.props( * singletonProps = Props(classOf[Echo], testActor), * terminationMessage = PoisonPill, * settings = ClusterSingletonManagerSettings(system)), * name = "echo") */ return(Sys.ActorOf(ClusterSingletonManager.Props( singletonProps: Props.Create(() => new Echo(TestActor)), terminationMessage: PoisonPill.Instance, settings: ClusterSingletonManagerSettings.Create(Sys)), name: "echo")); }
public ClusterShardingSettings( string role, bool rememberEntities, string journalPluginId, string snapshotPluginId, TunningParameters tunningParameters, ClusterSingletonManagerSettings coordinatorSingletonSettings) { Role = role; RememberEntities = rememberEntities; JournalPluginId = journalPluginId; SnapshotPluginId = snapshotPluginId; TunningParameters = tunningParameters; CoordinatorSingletonSettings = coordinatorSingletonSettings; }
private ClusterShardingSettings Copy( string role = null, bool?rememberEntities = null, string journalPluginId = null, string snapshotPluginId = null, TunningParameters tunningParameters = null, ClusterSingletonManagerSettings coordinatorSingletonSettings = null) { return(new ClusterShardingSettings( role: role ?? Role, rememberEntities: rememberEntities ?? RememberEntities, journalPluginId: journalPluginId ?? JournalPluginId, snapshotPluginId: snapshotPluginId ?? SnapshotPluginId, tunningParameters: tunningParameters ?? TunningParameters, coordinatorSingletonSettings: coordinatorSingletonSettings ?? CoordinatorSingletonSettings)); }
static void Main() { var config = ConfigurationFactory.ParseString(configString).WithFallback(ClusterSingletonManager.DefaultConfig()); var system = ActorSystem.Create("cluster-system", config); var server = system.ActorOf(ClusterSingletonManager.Props( singletonProps: Props.Create <Server>(), terminationMessage: PoisonPill.Instance, settings: ClusterSingletonManagerSettings.Create(system).WithRole("worker")), name: "consumer"); Thread.Sleep(10000); var s = Address.Parse("akka.tcp://cluster-system@localhost:5001/"); Cluster.Get(system).Leave(s); Console.ReadKey(); }