public Task StartAsync(CancellationToken cancellationToken) { var config = HoconLoader.ParseConfig("web.hocon"); var bootstrap = BootstrapSetup.Create() .WithConfig(config.ApplyOpsConfig()) // load HOCON and apply extension methods to inject environment variables .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); // start ActorSystem _clusterSystem = ActorSystem.Create("webcrawler", actorSystemSetup); _clusterSystem.StartPbm(); // start Petabridge.Cmd (https://cmd.petabridge.com/) // instantiate actors var router = _clusterSystem.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "tasker"); var processor = _clusterSystem.ActorOf( Props.Create(() => new CommandProcessor(router)), "commands"); var signalRProps = ServiceProvider.For(_clusterSystem).Props <SignalRActor>(processor); _signalRActor = _clusterSystem.ActorOf(signalRProps, "signalr"); return(Task.CompletedTask); }
public Task StartAsync(CancellationToken cancellationToken) { var config = HoconLoader.ParseConfig("tracker.hocon"); var bootstrap = BootstrapSetup.Create() .WithConfig(config.ApplyOpsConfig()) // load HOCON and apply extension methods to inject environment variables .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); // start ActorSystem ClusterSystem = ActorSystem.Create("webcrawler", actorSystemSetup); ClusterSystem.StartPbm(); // start Petabridge.Cmd (https://cmd.petabridge.com/) // instantiate actors _apiMaster = ClusterSystem.ActorOf(Props.Create(() => new ApiMaster()), "api"); _downloadMaster = ClusterSystem.ActorOf(Props.Create(() => new DownloadsMaster()), "downloads"); return(Task.CompletedTask); }
public async Task RunAsync() { var config = ConfigurationFactory.ParseString(@" akka.actor.default-dispatcher = { executor = channel-executor fork-join-executor { #channelexecutor will re-use these settings parallelism-min = 2 parallelism-factor = 1 parallelism-max = 64 } } akka.actor.internal-dispatcher = { executor = channel-executor throughput = 5 fork-join-executor { parallelism-min = 4 parallelism-factor = 1.0 parallelism-max = 64 } } akka.remote.default-remote-dispatcher { type = Dispatcher executor = channel-executor fork-join-executor { parallelism-min = 2 parallelism-factor = 0.5 parallelism-max = 16 } } akka.remote.backoff-remote-dispatcher { executor = channel-executor fork-join-executor { parallelism-min = 2 parallelism-max = 2 } } "); var bootstrap = BootstrapSetup.Create().WithConfig(config); var serviceProviderSetup = ServiceProviderSetup.Create(_serviceProvider); var actorSystemSetup = bootstrap.And(serviceProviderSetup); _actorSystem = ActorSystem.Create("StatsSys", actorSystemSetup); var marketingCoordinator = _actorSystem.ActorOf(Props.Create(() => new MarketingCoordinator()), "marketing"); var actors = new[] { marketingCoordinator }; // start the work coordinator _workCoordinator = _actorSystem.ActorOf(Props.Create(() => new WorkCoordinator(actors)), "work"); await _actorSystem.WhenTerminated.ConfigureAwait(false); }
public async Task StartAsync(CancellationToken cancellationToken) { var hocon = ConfigurationLoader.Load(); var bootstrap = BootstrapSetup.Create().WithConfig(hocon); var di = ServiceProviderSetup.Create(_serviceProvider); var actorSystemSetup = bootstrap.And(di); _actorSystem = ActorSystem.Create("shop", actorSystemSetup); ClientActor = _actorSystem.ActorOf(Props.Create <ClientActor>()); }
internal static IServiceCollection AddAkka(this IServiceCollection services, string actorSystemName, string hocon, Func <Config, Config> hoconFunc, Action <IServiceProvider, ActorSystem> startAction = null) => services.AddSingleton(sp => BootstrapSetup.Create() .WithConfig(hoconFunc(ConfigurationFactory.ParseString(hocon))) .And(ServiceProviderSetup.Create(sp))) .AddSingleton <AkkaHostedServiceStart>(sp => sys => startAction?.Invoke(sp, sys)) .AddSingleton(typeof(IPropsFactory <>), typeof(PropsFactory <>)) .AddHostedService <AkkaHostedService>() .AddSingleton(sp => ActorSystem.Create(actorSystemName, sp.GetService <ActorSystemSetup>()));
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); }
public static IServiceCollection AddAkkaService(this IServiceCollection services, string configfile, bool isdocker = false) { var config = HoconLoader.ParseConfig(configfile); if (isdocker) { config = config.BootstrapFromDocker(); } services.AddSingleton(provider => { var bootstrap = BootstrapSetup.Create().WithConfig(config); var di = ServiceProviderSetup.Create(provider); var actorSystemSetup = bootstrap.And(di); return(ActorSystem.Create(config.GetString("akka.MaserServer"), actorSystemSetup).StartPbm()); }); return(services); }
public async Task StartAsync(CancellationToken cancellationToken) { var hocon = ConfigurationFactory.ParseString(await File.ReadAllTextAsync("app.conf", cancellationToken)); var bootstrap = BootstrapSetup.Create().WithConfig(hocon); var di = ServiceProviderSetup.Create(_sp); var actorSystemSetup = bootstrap.And(di); _actorSystem = ActorSystem.Create("AspNetDemo", actorSystemSetup); // </AkkaServiceSetup> // <ServiceProviderFor> // props created via IServiceProvider dependency injection var hasherProps = ServiceProvider.For(_actorSystem).Props <HasherActor>(); RouterActor = _actorSystem.ActorOf(hasherProps.WithRouter(FromConfig.Instance), "hasher"); // </ServiceProviderFor> await Task.CompletedTask; }
protected void changeRevocationList(object sender, EventArgs e) { Session.Remove("revocationCheckType"); var revocationCheckType = Request["revocationCheckType"]; if ("full".Equals(revocationCheckType)) { ServiceProviderSetup.SetFullCrlRevocationChecker(); Session.Add("revocationCheckType", "full"); } else if ("ocsp".Equals(revocationCheckType)) { ServiceProviderSetup.SetOcspRevocationChecker(); Session.Add("revocationCheckType", "ocsp"); } else { ServiceProviderSetup.SetPartitionedCrlRevocationChecker(); Session.Add("revocationCheckType", "partitioned"); } Response.Redirect("/extras/"); }
public ServiceProviderSetupSpecs(AkkaDiFixture fixture, ITestOutputHelper output) : base(ServiceProviderSetup.Create(fixture.Provider) .And(BootstrapSetup.Create().WithConfig(TestKitBase.DefaultConfig)), output) { }
public async Task TestWithAkka() { const string topicName = "rmq.test.akka"; var host = Host.CreateDefaultBuilder() .ConfigureHostConfiguration(config => { config.AddHoconFile("test.hocon"); }) .ConfigureServices((context, services) => { services.AddSingleton(sp => new Akka.TestKit.Xunit2.TestKit(BootstrapSetup.Create() .And(ServiceProviderSetup.Create(sp)))); services.AddSingleton(sp => sp.GetService <Akka.TestKit.Xunit2.TestKit>().Sys); services.AddRabbitMQ(context.Configuration, model => { model.QueueDelete(topicName, false, false); model.QueueDeclare(topicName, false, false, false, null); }); }) .UseAkka(sys => { }) .Build(); await host.StartAsync(); var testKit = host.Services.GetService <Akka.TestKit.Xunit2.TestKit>(); var receiverActor = testKit.ActorOf(testKit.Sys.PropsFactory <MQReceiverActor>().Create(topicName, testKit.TestActor), "ReceiverActor"); var senderActor = testKit.ActorOf(testKit.Sys.PropsFactory <MQPublisherActor>().Create(topicName), "SenderActor"); senderActor.Tell("1"); senderActor.Tell(new Hello()); senderActor.Tell(new[] { 3 }); senderActor.Tell("4"); senderActor.Tell(new[] { "5" }); testKit.ExpectMsg <MQReceiverActor.Received>((m, s) => { m.Message.As <string>().Should().Be("1"); s.Tell(new MQReceiverActor.Ack()); }, 5.Seconds()); testKit.ExpectMsg <MQReceiverActor.Received>((m, s) => { m.Message.As <Hello>(); s.Tell(new MQReceiverActor.Ack()); }); testKit.ExpectMsg <MQReceiverActor.Received>((m, s) => { m.Message.As <IEnumerable <int> >() .Should() .BeSubsetOf(new[] { 3 }); s.Tell(new MQReceiverActor.Nack()); }); testKit.ExpectMsg <MQReceiverActor.Received>((m, s) => { m.Message.As <IEnumerable <int> >() .Should() .BeSubsetOf(new[] { 3 }); s.Tell(new MQReceiverActor.Ack()); }); await host.StopAsync(); }