public async Task StartAsync(CancellationToken cancellationToken) { var hocon = ConfigurationFactory.ParseString(await File.ReadAllTextAsync("app.conf", cancellationToken)); var bootstrap = BootstrapSetup.Create().WithConfig(hocon); var di = DependencyResolverSetup.Create(_sp); var actorSystemSetup = bootstrap.And(di); _actorSystem = ActorSystem.Create("AspNetDemo", actorSystemSetup); // </AkkaServiceSetup> // <ServiceProviderFor> // props created via IServiceProvider dependency injection var hasherProps = DependencyResolver.For(_actorSystem).Props <HasherActor>(); RouterActor = _actorSystem.ActorOf(hasherProps.WithRouter(FromConfig.Instance), "hasher"); // </ServiceProviderFor> await Task.CompletedTask; }
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 = DependencyResolverSetup.Create(_serviceProvider); // merge this setup (and any others) together into ActorSystemSetup var actorSystemSetup = bootstrap.And(diSetup); // start ActorSystem ClusterSystem = ActorSystem.Create("ClusterSys", actorSystemSetup); // start Petabridge.Cmd (https://cmd.petabridge.com/) var pbm = PetabridgeCmd.Get(ClusterSystem); pbm.RegisterCommandPalette(ClusterCommands.Instance); pbm.RegisterCommandPalette(new RemoteCommands()); pbm.Start(); // begin listening for PBM management commands // instantiate actors // use the ServiceProvider ActorSystem Extension to start DI'd actors var sp = DependencyResolver.For(ClusterSystem);; ConsoleActor = ClusterSystem.ActorOf(Props.Create(() => new ConsoleActor()), "console"); // add a continuation task that will guarantee // shutdown of application if ActorSystem terminates first ClusterSystem.WhenTerminated.ContinueWith(tr => { _applicationLifetime.StopApplication(); }); return(Task.CompletedTask); }
public ActorServiceProviderPropsWithScopesSpecs(AkkaDiFixture fixture, ITestOutputHelper output) : base(DependencyResolverSetup.Create(fixture.Provider) .And(BootstrapSetup.Create().WithConfig(TestKitBase.DefaultConfig)), output) { }
public Task StartAsync(CancellationToken cancellationToken) { Config config; switch (Environment.GetEnvironmentVariable("DEPLOY_TYPE")) { case "config": var hostName = Environment.GetEnvironmentVariable("CLUSTER_IP"); config = ConfigurationFactory.ParseString($"akka.management.http.hostname = {hostName}"). WithFallback(ConfigurationFactory.ParseString(File.ReadAllText("app.conf"))); break; case "dynamic": config = ConfigurationFactory.ParseString(File.ReadAllText("app-dynamic.conf")); break; default: throw new Exception( "Unknown 'DEPLOY_TYPE' environment variable value. Valid values are 'config' and 'dynamic'"); } config = config .WithFallback(ClusterBootstrap.DefaultConfiguration()) .WithFallback(AkkaManagementProvider.DefaultConfiguration()) .BootstrapFromDocker(); var bootstrap = BootstrapSetup.Create() .WithConfig(config) // load HOCON .WithActorRefProvider(ProviderSelection.Cluster.Instance); // launch Akka.Cluster // enable DI support inside this ActorSystem, if needed var diSetup = DependencyResolverSetup.Create(_serviceProvider); // merge this setup (and any others) together into ActorSystemSetup var actorSystemSetup = bootstrap.And(diSetup); var systemName = Environment.GetEnvironmentVariable("ACTORSYSTEM")?.Trim(); _system = ActorSystem.Create(systemName, actorSystemSetup); var chaos = _system.ActorOf(Props.Create <ChaosActor>(), "chaos"); var subscriber = _system.ActorOf(Props.Create(() => new Subscriber()), "subscriber"); // start https://cmd.petabridge.com/ for diagnostics and profit var pbm = PetabridgeCmd.Get(_system); // start Pbm pbm.RegisterCommandPalette(ClusterCommands.Instance); pbm.RegisterCommandPalette(new RemoteCommands()); pbm.Start(); // begin listening for PBM management commands ClusterListener = _system.ActorOf(Akka.Cluster.Bootstrap.ClusterListener.Props(), "listener"); _system.WhenTerminated.ContinueWith(tr => { _lifetime.StopApplication(); // when the ActorSystem terminates, terminate the process }); var mediator = DistributedPubSub.Get(_system).Mediator; _system.Scheduler.Advanced.ScheduleRepeatedly(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), () => { // mediator.Tell(new Publish("content", ThreadLocalRandom.Current.Next(0,10))); chaos.Tell(ThreadLocalRandom.Current.Next(0, 100)); }); return(Task.CompletedTask); }