static void Main(string[] args) { Console.WriteLine("*********************************************"); Console.WriteLine("***************** Akka Demo! ****************"); Console.WriteLine("*********************************************"); // Create the Actor System ActorSystem demoSystem = ActorSystem.Create("DemoSystem", getConfiguration()); // Create an actor wihtin that system IActorRef DemoSupervisor = demoSystem.ActorOf(Props.Create <DemoSupervisor>(), name: "DemoSupervisor"); // Add monitoring to the system ActorMonitoringExtension.RegisterMonitor(demoSystem, new ActorStatsDMonitor(host: "localhost", port: 8125, prefix: "akka-demo")); // Send messages, asynchronously /* Example #1) Simple message */ //DemoSupervisor.Tell(new SayHello("Hello!")); /* Example #2) Command resulting in events which are persisted */ //DemoSupervisor.Tell(new PersistThisMessage(message: "This is very cool!")); /* Examples #3 & #4) Processes */ //DemoSupervisor.Tell(new WorkXTimes(10)); Console.ReadLine(); }
private static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Starting up actor system..."); var system = ActorSystem.Create("akka-performance-demo"); var didMonitorRegister = ActorMonitoringExtension.RegisterMonitor(system, new ActorNewRelicMonitor()); Console.WriteLine(didMonitorRegister ? "Successfully registered NewRelic monitor" : "Failed to register New Relic monitor"); // Start up three sets of Pluto and Charon (reference to I'm Your Moon by Jonathan Coulton) for (var i = 0; i < 3; i++) { var pluto = system.ActorOf <PlutoActor>(); var charon = system.ActorOf <CharonActor>(); charon.Tell(pluto); } Console.WriteLine("Waiting 60 seconds so the New Relic agent has time to harvest metrics"); Thread.Sleep(TimeSpan.FromSeconds(60)); Console.WriteLine("Shutting down..."); system.Terminate().Wait(); Console.WriteLine("Shutdown complete"); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
protected override void OnStart(ActorSystem actorSystem) { base.OnStart(actorSystem); this.telemetry.Run(); this.monitor = ActorMonitoringExtension.Monitors(actorSystem); this.monitor.RegisterMonitor(new ActorAppInsightsMonitor(this.telemetry.CreateTelemetryClient())); }
public async Task Start() { Container = new UnityContainer(); Systems = _actorSystemFactory.Invoke(); System = Systems.First(); System.InitDomainEventsSerialization(EventsAdaptersCatalog); _transportMode = Systems.Length > 1 ? TransportMode.Cluster : TransportMode.Standalone; System.RegisterOnTermination(OnSystemTermination); System.AddDependencyResolver(new UnityDependencyResolver(Container, System)); ConfigureContainer(Container, _quartzConfig, System); Transport = Container.Resolve <IActorTransport>(); _quartzScheduler = Container.Resolve <Quartz.IScheduler>(); _commandExecutor = Container.Resolve <ICommandExecutor>(); _waiterFactory = Container.Resolve <IMessageWaiterFactory>(); _commandWaiterFactory = Container.Resolve <ICommandWaiterFactory>(); EventBusForwarder = System.ActorOf(Props.Create(() => new EventBusForwarder(Transport)), nameof(EventBusForwarder)); var appInsightsConfig = Container.Resolve <IAppInsightsConfiguration>(); var perfCountersConfig = Container.Resolve <IPerformanceCountersConfiguration>(); var factories = Container.ResolveAll(typeof(IConstructAggregates)) .Select(o => new { Type = o.GetType(), Obj = (IConstructAggregates)o }) .Where(o => o.Type.IsGenericType && o.Type.GetGenericTypeDefinition() == typeof(AggregateSnapshottingFactory <>)) .Select(o => new { AggregateType = o.Type.GetGenericArguments().First(), Constructor = o.Obj }) .ToArray(); foreach (var factory in factories) { AggregateFromSnapshotsFactory.Register(factory.AggregateType, m => factory.Constructor.Build(factory.GetType(), Guid.Empty, m)); } if (appInsightsConfig.IsEnabled) { var monitor = new ActorAppInsightsMonitor(appInsightsConfig.Key); ActorMonitoringExtension.RegisterMonitor(System, monitor); } if (perfCountersConfig.IsEnabled) { ActorMonitoringExtension.RegisterMonitor(System, new ActorPerformanceCountersMonitor()); } _stopping = false; _log.Debug("Launching GridDomain node {Id}", Id); var props = System.DI().Props <GridNodeController>(); var nodeController = System.ActorOf(props, nameof(GridNodeController)); await nodeController.Ask <GridNodeController.Started>(new GridNodeController.Start { RoutingActorType = RoutingActorType[_transportMode] }); _log.Debug("GridDomain node {Id} started at home {Home}", Id, System.Settings.Home); }
public static void Start(string systemName) { /* * Initialize ActorSystem and essential system actors */ System = ActorSystem.Create(systemName); var monitor = new AkkaMonitoringPublisher(System); ActorMonitoringExtension.RegisterMonitor(System, monitor); }
static void Main(string[] args) { _system = ActorSystem.Create("akka-performance-demo"); var registeredMonitor = ActorMonitoringExtension.RegisterMonitor(_system, new ActorPerformanceCountersMonitor( new CustomMetrics { Counters = { "akka.custom.metric1", "akka.custom.metric2" }, Gauges = { "akka.messageboxsize" }, Timers = { "akka.handlertime" } })); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Starting up actor system..."); var goodbye = _system.ActorOf <GoodbyeActor>(); var hello = _system.ActorOf <HelloActor>(); for (int i = 0; i < 11; i++) { _system.ActorOf <HelloActor>(); } _system.ActorOf <WorkerActor>(); if (registeredMonitor) { Console.WriteLine("Successfully registered Performance Counters monitor"); } else { Console.WriteLine("Failed to register Performance Counters monitor"); } Console.WriteLine("Incrementing debug log once every 10 ms for 2 seconds..."); var count = 20; while (count >= 0) { ActorMonitoringExtension.Monitors(_system).IncrementDebugsLogged(); Console.WriteLine("Logging debug..."); Thread.Sleep(2000); count--; } Console.WriteLine("Starting a conversation between actors"); goodbye.Tell(new Tuple <IActorRef, string>(hello, "Start")); while (ManualResetEvent.WaitOne()) { Console.WriteLine("Shutting down..."); _system.Shutdown(); Console.WriteLine("Shutdown complete"); Console.WriteLine("Press any key to exit"); Console.ReadKey(); return; } }
protected override void OnStart(ActorSystem actorSystem) { base.OnStart(actorSystem); var instrumentationKey = this.Config.Get <AppSettings>().ApplicationInsights.InstrumentationKey; Log.Info($"AppInsights key is {instrumentationKey}"); if (!string.IsNullOrWhiteSpace(instrumentationKey)) { this.monitor = ActorMonitoringExtension.Monitors(actorSystem); this.monitor.RegisterMonitor(new ActorAppInsightsMonitor(instrumentationKey)); } }
static void Main(string[] args) { _system = ActorSystem.Create("akka-performance-demo"); var registeredMonitor = ActorMonitoringExtension.RegisterMonitor( _system, new ActorAppInsightsMonitor( "<INSERT YOUR KEY>", true)); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Starting up actor system..."); var goodbye = _system.ActorOf <GoodbyeActor>(); var hello = _system.ActorOf <HelloActor>(); var goodbye1 = _system.ActorOf <GoodbyeActor>(); var hello1 = _system.ActorOf <HelloActor>(); if (registeredMonitor) { Console.WriteLine("Successfully registered AppInsights monitor"); } else { Console.WriteLine("Failed to register AppInsights monitor"); } Console.WriteLine("Incrementing debug log once every 10 ms for 2 seconds..."); var count = 20; while (count >= 0) { ActorMonitoringExtension.Monitors(_system).IncrementDebugsLogged(); Console.WriteLine("Logging debug..."); Thread.Sleep(100); count--; } Console.WriteLine("Starting a conversation between actors"); goodbye.Tell(new Tuple <IActorRef, string>(hello, "Start")); goodbye1.Tell(new Tuple <IActorRef, string>(hello1, "Start")); Thread.Sleep(5000); while (ManualResetEvent.WaitOne()) { Console.WriteLine("Shutting down..."); _system.Shutdown(); Console.WriteLine("Shutdown complete"); Console.WriteLine("Press any key to exit"); Console.ReadKey(); return; } }
static void Main(string[] args) { _system = ActorSystem.Create("akka-datadog-demo"); var statsdConfig = new StatsdConfig { StatsdServerName = "127.0.0.1" }; var registeredMonitor = ActorMonitoringExtension.RegisterMonitor(_system, new ActorDatadogMonitor(statsdConfig)); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Starting up actor system..."); var goodbye = _system.ActorOf <GoodbyeActor>(); var hello = _system.ActorOf <HelloActor>(); Console.WriteLine(registeredMonitor ? "Successfully registered StatsD monitor" : "Failed to register StatsD monitor"); Console.WriteLine("Incrementing debug log once every 10 ms for 2 seconds..."); for (var i = 0; i < 20; i++) { ActorMonitoringExtension.Monitors(_system).IncrementDebugsLogged(); Console.WriteLine("Logging debug..."); Thread.Sleep(10); } Console.WriteLine("Starting a conversation between actors"); goodbye.Tell(new Tuple <IActorRef, string>(hello, "Start")); while (ManualResetEvent.WaitOne()) { Console.WriteLine("Shutting down..."); _system.Terminate(); Console.WriteLine("Shutdown complete"); Console.WriteLine("Press any key to exit"); Console.ReadKey(); return; } }
static void Main(string[] args) { using (system = ActorSystem.Create("akka-performance-demo")) { var registeredMonitor = ActorMonitoringExtension.RegisterMonitor(system, new Monitor()); IWindsorContainer container = new WindsorContainer(); container.Register(Component.For <IInterceptor>(). ImplementedBy <MonitorInterceptor>(). Named("monitorInterceptor"), Component.For <HelloActor>(). LifestyleTransient(). Interceptors(InterceptorReference.ForKey("monitorInterceptor")). Anywhere); WindsorDependencyResolver propsResolver = new WindsorDependencyResolver(container, system); var hello = system.ActorOf(propsResolver.Create <HelloActor>(), "Worker1"); hello.Tell("What's Up"); hello.Tell("Goodbye"); var count = 20; while (count >= 0) { ActorMonitoringExtension.Monitors(system).IncrementDebugsLogged(); Console.WriteLine("Logging debug..."); Thread.Sleep(100); count--; } while (ManualResetEvent.WaitOne()) { Console.WriteLine("Shutting down..."); system.Shutdown(); Console.WriteLine("Shutdown complete"); Console.WriteLine("Press any key to exit"); Console.ReadKey(); return; } } }
public CqrsExtension(ExtendedActorSystem system) { var config = ConfigurationFactory.FromResource <CqrsExtension>("AkkaCQRS.Core.akka-cqrs.conf"); system.Settings.InjectTopLevelFallback(config); ActorMonitoringExtension.RegisterMonitor(system, new ActorStatsDMonitor()); var usersCoordinator = system.ActorOf(Props.Create(() => new UserCoordinator()), "users"); var accountCoordinator = system.ActorOf(Props.Create(() => new AccountCoordinator()), "accounts"); var usersIndex = system.ActorOf(Props.Create(() => new UserIndex()).WithRouter(new RoundRobinPool(4)), "users-index"); var addressBook = system.ActorOf(Props.Create(() => new AddressBook(new Dictionary <Type, ICanTell> { { typeof(UserCoordinator), usersCoordinator }, { typeof(AccountCoordinator), accountCoordinator }, { typeof(UserIndex), usersIndex }, })), AddressBook.Name); }
public static async Task Run(int howMany) { var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); ConsoleUtils.PrintBeginHeader("AkkaProcessing", howMany); myLotteryActorSystem = ActorSystem.Create("MyLotteryActorSystem"); var registeredMonitor = ActorMonitoringExtension.RegisterMonitor(myLotteryActorSystem, new ActorPerformanceCountersMonitor()); //new ActorAppInsightsMonitor(), new ActorPerformanceCountersMonitor (); var propsOrchestrator = Props.Create <OrchestratorActor>(howMany); var orchestratorActor = myLotteryActorSystem.ActorOf(propsOrchestrator, "orchestrator"); orchestratorActor.Tell(new Start()); await myLotteryActorSystem.WhenTerminated; stopwatch.Stop(); ConsoleUtils.PrintEndHeader("AkkaProcessing", howMany, stopwatch); }
private void ConfigureActorSystem(Config config) { DemoActorSystem = ActorSystem.Create("demoSystem", config); DemoSystemSupervisor = DemoActorSystem.ActorOf(Props.Create <SystemSupervisor>(), "demoSupervisor"); var statsDServer = config.GetString("Akka.StatsDServer"); var statsDPort = Convert.ToInt32(config.GetString("Akka.StatsDPort")); var statsDPrefix = config.GetString("Akka.StatsDPrefix"); BusinessRulesFilename = config.GetString("Akka.BusinessRulesFilename"); CommandsToRulesFilename = config.GetString("Akka.CommandsToRulesFilename"); Console.WriteLine($"(StatsD) Server: {statsDServer}"); Console.WriteLine($"(StatsD) Port: {statsDPort}"); Console.WriteLine($"(StatsD) Prefix: {statsDPrefix}"); ActorMonitoringExtension.RegisterMonitor(DemoActorSystem, new ActorStatsDMonitor(statsDServer , statsDPort , statsDPrefix )); DemoSystemSupervisor.Tell(new BootUp("Starting Up")); Console.WriteLine($"(Business Rules) BusinessRulesFilename: {BusinessRulesFilename}"); Console.WriteLine($"(Business Rules) CommandsToRulesFilename: {CommandsToRulesFilename}"); AccountBusinessRulesMapperRouter = DemoActorSystem.ActorOf(Props.Create <AccountBusinessRulesMapper>(), "AccountBusinessRulesMapperRouter"); AccountBusinessRulesMapperRouter.Tell(new BootUp("Get up!")); Console.WriteLine($"(Business Rules) AccountBusinessRulesMapperRouter spun up"); AccountBusinessRulesHandlerRouter = DemoActorSystem.ActorOf(Props.Create <AccountBusinessRulesHandler>(), "AccountBusinessRulesHandlerRouter"); AccountBusinessRulesHandlerRouter.Tell(new BootUp("Get up!")); Console.WriteLine($"(Business Rules) AccountBusinessRulesHandlerRouter spun up"); }
private static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; var metricServer = new MetricServer(10250); metricServer.Start(); Console.WriteLine("Started metric server at localhost:10250 (http://localhost:10250/metrics)"); Console.WriteLine("Starting up actor system..."); var system = ActorSystem.Create("akka-performance-demo"); var didMonitorRegister = ActorMonitoringExtension.RegisterMonitor(system, new ActorPrometheusMonitor(system)); Console.WriteLine(didMonitorRegister ? "Successfully registered Prometheus monitor" : "Failed to register Prometheus monitor"); // Start up three sets of Pluto and Charon (reference to I'm Your Moon by Jonathan Coulton) for (var i = 0; i < 3; i++) { var pluto = system.ActorOf <PlutoActor>(); var charon = system.ActorOf <CharonActor>(); charon.Tell(pluto); } Thread.Sleep(TimeSpan.FromSeconds(15)); Console.WriteLine("Shutting down..."); system.Terminate().Wait(); Console.WriteLine("Shutdown complete"); Console.WriteLine("Press any key to exit"); Console.ReadKey(); metricServer.Stop(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApplicationLifetime lifetime) { app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); MetricServer metricServer = null; var appConfig = app.ApplicationServices.GetService <AppSettings>(); AppSettings = appConfig; //APP Life Cycle lifetime.ApplicationStarted.Register(() => { app.ApplicationServices.GetService <ILogger>(); var actorSystem = app.ApplicationServices.GetService <ActorSystem>(); // start Akka.NET ActorSystem = actorSystem; //싱글톤 클러스터 액터 actorSystem.BootstrapSingleton <SingleToneActor>("SingleToneActor", "akkanet"); var singleToneActor = actorSystem.BootstrapSingletonProxy("SingleToneActor", "akkanet", "/user/SingleToneActor", "singleToneActorProxy"); AkkaLoad.RegisterActor("SingleToneActor", singleToneActor); // ########### 로드 테스트 전용 // 클러스터내 싱글톤은 하나만 존재할수있음 : akka.cluster.singleton - akka.conf참고 //액터 선택 : AkkaLoad.ActorSelect("ClusterWorkerPoolActor") var worker = AkkaLoad.RegisterActor( "ClusterWorkerPoolActor", actorSystem.ActorOf(Props.Create <ClusterWorkerPoolActor>() .WithDispatcher("fast-dispatcher") .WithRouter(FromConfig.Instance), "cluster-workerpool" )); //커멘드 액터( 로드테스트용) //액터생성 AkkaLoad.RegisterActor( "TPSCommandActor", actorSystem.ActorOf(Props.Create <TPSCommandActor>(worker), "TPSCommandActor" )); // ########### 로드 테스트 전용 //액터생성 AkkaLoad.RegisterActor( "basic", actorSystem.ActorOf(Props.Create <BasicActor>(), "basic" )); // DI 연동 AkkaLoad.RegisterActor( "toner", actorSystem.ActorOf(actorSystem.DI().Props <TonerActor>() .WithRouter(new RoundRobinPool(1)), "toner" )); AkkaLoad.RegisterActor( "printer", actorSystem.ActorOf(actorSystem.DI().Props <PrinterActor>() .WithDispatcher("custom-dispatcher") .WithRouter(FromConfig.Instance).WithDispatcher("custom-task-dispatcher"), "printer-pool" )); // DI 미연동 AkkaLoad.RegisterActor( "highpass", actorSystem.ActorOf(Props.Create <HighPassGateActor>() .WithDispatcher("fast-dispatcher") .WithRouter(FromConfig.Instance), "highpass-gate-pool" )); AkkaLoad.RegisterActor( "cashpass", actorSystem.ActorOf(Props.Create <CashGateActor>() .WithDispatcher("slow-dispatcher") .WithRouter(FromConfig.Instance), "cashpass-gate-pool" )); AkkaLoad.RegisterActor( "clusterRoundRobin", actorSystem.ActorOf(Props.Create <ClusterPoolActor>() .WithDispatcher("fast-dispatcher") .WithRouter(FromConfig.Instance), "cluster-roundrobin" )); // 스트림 - 밸브조절액터 int timeSec = 1; var throttleActor = AkkaLoad.RegisterActor( "throttleActor", actorSystem.ActorOf(Props.Create <ThrottleActor>(timeSec) )); var throttleWork = actorSystem.ActorOf(Props.Create <ThrottleWork>(5, 1)); throttleActor.Tell(new SetTarget(throttleWork)); try { var MonitorTool = Environment.GetEnvironmentVariable("MonitorTool"); var MonitorToolCon = Environment.GetEnvironmentVariable("MonitorToolCon"); var MonitorToolCons = MonitorToolCon.Split(":"); string StatsdServerName = MonitorToolCons[0]; int StatsdPort = 8125; if (MonitorToolCons.Length > 1 && 10 > MonitorToolCons.Length) { StatsdPort = int.Parse(MonitorToolCons[1]); } switch (MonitorTool) { case "win": var win = ActorMonitoringExtension.RegisterMonitor(actorSystem, new ActorPerformanceCountersMonitor( new CustomMetrics { Counters = { "akka.custom.metric1", "akka.custom.metric2", "akka.custom.metric3", "akka.custom.received1", "akka.custom.received2" }, Gauges = { "akka.gauge.msg10", "akka.gauge.msg100", "akka.gauge.msg1000", "akka.gauge.msg10000" }, Timers = { "akka.handlertime" } })); // 윈도우 성능 모니터링 수집대상항목은 최초 Admin권한으로 akka항목으로 레지스트리에 프로그램실행시 자동 등록되며 // 커스텀항목 결정및 최초 1번 작동후 변경되지 않음으로 // 수집 항목 변경시 아래 Register 삭제후 다시 최초 Admin권한으로 작동 // Actor명으로 매트릭스가 분류됨으로 기능단위의 네이밍이 권장됨 // HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Akka\Performance break; case "azure": var azure = ActorMonitoringExtension.RegisterMonitor(actorSystem, new ActorAppInsightsMonitor(appConfig.MonitorToolCon)); break; case "prometheus": // prometheusMonotor 를 사용하기위해서, MerticServer를 켠다...(수집형 모니터) // http://localhost:10250/metrics metricServer = new MetricServer(10250); metricServer.Start(); var prometheus = ActorMonitoringExtension.RegisterMonitor(actorSystem, new ActorPrometheusMonitor(actorSystem)); break; case "datadog": var statsdConfig = new StatsdConfig { StatsdServerName = StatsdServerName, StatsdPort = StatsdPort }; var dataDog = ActorMonitoringExtension. RegisterMonitor(actorSystem, new ActorDatadogMonitor(statsdConfig)); break; } } catch (Exception e) { Console.WriteLine("=============== Not Suport Window Monitor Tools ==============="); } ActorMonitoringExtension.Monitors(actorSystem).IncrementDebugsLogged(); }); lifetime.ApplicationStopping.Register(() => { Console.WriteLine("=============== Start Graceful Down ==============="); var actorSystem = app.ApplicationServices.GetService <ActorSystem>(); if (appConfig.MonitorTool == "prometheus") { metricServer.Stop(); } // Graceful Down Test,Using CashGateActor Actor AkkaLoad.ActorSelect("cashpass").Ask(new StopActor()).Wait(); var cluster = Akka.Cluster.Cluster.Get(actorSystem); cluster.RegisterOnMemberRemoved(() => MemberRemoved(actorSystem)); cluster.Leave(cluster.SelfAddress); asTerminatedEvent.WaitOne(); Console.WriteLine($"=============== Completed Graceful Down : {cluster.SelfAddress} ==============="); }); }