Esempio n. 1
0
        static int Main(string[] args)
        {
            var config = File.ReadAllText("app.conf");
            var conf   = ConfigurationFactory.ParseString(config).BoostrapApplication(new AppBootstrapConfig(true, true));

            var actorSystem = ActorSystem.Create("AkkaTrader", conf);

            Cluster.Cluster.Get(actorSystem).RegisterOnMemberUp(() =>
            {
                var sharding = ClusterSharding.Get(actorSystem);

                var shardRegion = sharding.Start("orderBook", s => OrderBookActor.PropsFor(s), ClusterShardingSettings.Create(actorSystem),
                                                 new StockShardMsgRouter());
            });

            // 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);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var config = ConfigurationFactory.ParseString(File.ReadAllText("Akka.conf"));

            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);

            var cmd = PetabridgeCmd.Get(system);

            cmd.RegisterCommandPalette(ClusterCommands.Instance);
            cmd.Start();

            var actor = system.ActorOf(FooActor.Props(), nameof(FooActor));

            system.Scheduler.ScheduleTellRepeatedly(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(1), actor, "hello", ActorRefs.NoSender);

            Console.WriteLine();
            Console.WriteLine("NonSeedNode1 is running...");
            Console.WriteLine();

            Console.ReadLine();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var         config = ConfigurationFactory.ParseString(File.ReadAllText("App.Akka.conf"));
            ActorSystem system = ActorSystem.Create("ClusterLab", config);

            var cmd = PetabridgeCmd.Get(system);

            cmd.RegisterCommandPalette(ClusterCommands.Instance);
            cmd.Start();

            Console.WriteLine();
            Console.WriteLine("SeedNode1 is running...");
            Console.WriteLine();

            // register actor type as a sharded entity
            var region = ClusterSharding.Get(system).Start(
                typeName: "my-actor",
                entityProps: Props.Create <MyActor>(),
                settings: ClusterShardingSettings.Create(system),
                messageExtractor: new MessageExtractor());

            // send message to entity through shard region
            region.Tell(new Envelope(shardId: 1, entityId: 1, message: "hello"));

            while (true)
            {
                Thread.Sleep(1000);
            }

            Console.ReadLine();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var         config = ConfigurationFactory.ParseString(File.ReadAllText("App.Akka.conf"));
            ActorSystem system = ActorSystem.Create("WarmupForClusterRouting", config);

            var cmd = PetabridgeCmd.Get(system);

            cmd.Start();

            system.ActorOf(ParentActor.Props(), nameof(ParentActor));

            var roundRobinGroupActor = system.ActorOf(Props.Empty
                                                      .WithRouter(FromConfig.Instance)
                                                      .WithSupervisorStrategy(new OneForOneStrategy(ex =>
            {
                //
                // 그룹 Routee 예외가 발생될 때 호출되지 않는다.
                //
                system.Log.Info($">>> It is not called when exceptions are raised from group-routees");
                return(Directive.Restart);
            })),
                                                      "MyGroupRouterActor");

            roundRobinGroupActor.Tell(0);
            roundRobinGroupActor.Tell(1);
            roundRobinGroupActor.Tell(2);
            roundRobinGroupActor.Tell(3);

            Console.ReadLine();
        }
Esempio n. 5
0
        static async Task Main(string[] args)
        {
            /*
             * Simple demo illustrating the monitoring of local TCP endpoints
             * that are currently running on the system somewhere. Shuts itself down
             * if a port leak is detected.
             */
            var actorSystem = ActorSystem.Create("PortDetector", "akka.loglevel = DEBUG");
            var supervisor  = actorSystem.ActorOf(Props.Create(() => new TcpPortUseSupervisor()), "tcpPorts");

            var cmd = PetabridgeCmd.Get(actorSystem);

            cmd.Start();
            //IEnumerable<IPAddress>

            SocketLeakDetectorSettings settings = new SocketLeakDetectorSettings {
            };

            var tcp      = actorSystem.ActorOf(Props.Create(() => new TcpHostActor()), "tcp");
            var endpoint = await tcp.Ask <EndPoint>(TcpHostActor.GetInboundEndpoint.Instance, TimeSpan.FromSeconds(3));

            var spawner = actorSystem.ActorOf(Props.Create(() => new TcpPortActor(endpoint)), "leaker");

            await actorSystem.WhenTerminated;
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        private static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration().WriteTo.LiterateConsole().CreateLogger();

            Log.Information("Ah, there you are!");

            using (var system = ActorSystem.Create("ClusterSystem", ConfigurationFactory.ParseString(GetConfig())))

            {
                var cmd = PetabridgeCmd.Get(system);
                cmd.RegisterCommandPalette(ClusterCommands.Instance);
                cmd.Start();
                var task = new Task(
                    () =>
                {
                    while (true)
                    {
                        Thread.Sleep(10 * 1000);
                        var hostname2 = Dns.GetHostName();
                        Console.WriteLine($" hostname: {hostname2} is alive {DateTime.Now.ToString("o")}!");
                    }
                });

                system.WhenTerminated.Wait();
            }
        }
Esempio n. 8
0
        public static async Task Main(string[] args)
        {
            var config      = ConfigurationFactory.ParseString(File.ReadAllText("app.conf")).BootstrapFromDocker();
            var actorSystem = ActorSystem.Create("ClusterSys", config);

            var pbm = PetabridgeCmd.Get(actorSystem);

            pbm.RegisterCommandPalette(ClusterCommands.Instance);
            pbm.RegisterCommandPalette(RemoteCommands.Instance);
            pbm.Start(); // begin listening for PBM management commands

            var persistentActor = actorSystem.ActorOf(Props.Create(() => new PersistentCountingActor("foo")), "foo");

            var serializer = actorSystem.Serialization.FindSerializerForType(typeof(object));

            actorSystem.Log.Info("Found serializer of type [{0}, Id={1}] for msg of type {2}", serializer, serializer.Identifier, typeof(object));

            actorSystem.Scheduler.ScheduleTellRepeatedly(TimeSpan.FromSeconds(0.5),
                                                         TimeSpan.FromSeconds(2), persistentActor,
                                                         new PersistentCountingActor.MyVal(1), ActorRefs.NoSender);


            actorSystem.Scheduler.Advanced.ScheduleRepeatedlyCancelable(TimeSpan.FromSeconds(3),
                                                                        TimeSpan.FromSeconds(5), () =>
            {
                persistentActor.Ask <int>(PersistentCountingActor.GetSum.Instance)
                .ContinueWith(tr => Console.WriteLine(tr.Result));
            });

            await actorSystem.WhenTerminated;
        }
Esempio n. 9
0
        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();
            }
        }
Esempio n. 10
0
        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(config.GetString("akka.system.actorsystem-name"), config);

            var cmd = PetabridgeCmd.Get(system);

            cmd.RegisterCommandPalette(ClusterCommands.Instance);
            cmd.Start();

            system.ActorOf(ClusterClientListenActor.Props(), nameof(ClusterClientListenActor));

            Console.WriteLine();
            Console.WriteLine("SeedNode1 is running...");
            Console.WriteLine();

            Console.ReadLine();

            system.Terminate().Wait();
        }
Esempio n. 11
0
        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(config.GetString("akka.system.actorsystem-name"), config);

            var cmd = PetabridgeCmd.Get(system);

            cmd.Start();

            //
            // Cluster 접속하기
            //
            system.ActorOf(
                ClusterClient
                .Props(ClusterClientSettings.Create(system)),
                "ClusterClientActor");

            Console.WriteLine();
            Console.WriteLine("ClusterClientApp1 is running...");
            Console.WriteLine();

            Console.ReadLine();
        }
        /// <summary>
        /// Start Petabridge.Cmd
        /// </summary>
        /// <param name="system">The <see cref="ActorSystem"/> that will run Petabridge.Cmd</param>
        /// <returns>The same <see cref="ActorSystem"/></returns>
        public static ActorSystem StartPbm(this ActorSystem system)
        {
            var pbm = PetabridgeCmd.Get(system);

            pbm.RegisterCommandPalette(ClusterCommands.Instance); // enable cluster management commands
            pbm.Start();
            return(system);
        }
Esempio n. 13
0
        public void Start()
        {
            this.lighthouseSystem = LighthouseHostFactory.LaunchLighthouse(this.ipAddress, this.port);
            var cmd = PetabridgeCmd.Get(lighthouseSystem);

            cmd.RegisterCommandPalette(ClusterCommands.Instance);
            cmd.Start();
        }
Esempio n. 14
0
        public void Start()
        {
            _lighthouseSystem = LighthouseHostFactory.LaunchLighthouse(_ipAddress, _port, _actorSystemName);
            var pbm = PetabridgeCmd.Get(_lighthouseSystem);

            pbm.RegisterCommandPalette(ClusterCommands.Instance); // enable cluster management commands
            pbm.Start();
        }
        public void Start()
        {
            lighthouseSystem = LighthouseHostFactory.LaunchLighthouse();
            PetabridgeCmd pbm = PetabridgeCmd.Get(lighthouseSystem);

            pbm.RegisterCommandPalette(ClusterCommands.Instance); // enable cluster management commands
            pbm.Start();
        }
Esempio n. 16
0
        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);
        }
        static int Main(string[] args)
        {
            var config = File.ReadAllText("app.conf");
            var conf   = ConfigurationFactory.ParseString(config);

            var actorSystem = ActorSystem.Create("AkkaTrader", conf.BoostrapApplication(new AppBootstrapConfig(true, true)));

            var sharding = ClusterSharding.Get(actorSystem);


            var shardRegion = sharding.Start("priceAggregator",
                                             s => Props.Create(() => new MatchAggregator(s)),
                                             ClusterShardingSettings.Create(actorSystem),
                                             new StockShardMsgRouter());

            var priceInitiatorActor = actorSystem.ActorOf(ClusterSingletonManager.Props(Props.Create(() => new PriceInitiatorActor(shardRegion)),
                                                                                        ClusterSingletonManagerSettings.Create(actorSystem).WithRole("pricing-engine").WithSingletonName("priceInitiator")), "priceInitiator");

            var clientHandler =
                actorSystem.ActorOf(Props.Create(() => new ClientHandlerActor(shardRegion)), "subscriptions");

            // make ourselves available to ClusterClient at /user/subscriptions
            ClusterClientReceptionist.Get(actorSystem).RegisterService(clientHandler);

            Cluster.Cluster.Get(actorSystem).RegisterOnMemberUp(() =>
            {
                foreach (var ticker in AvailableTickerSymbols.Symbols)
                {
                    shardRegion.Tell(new Ping(ticker));
                }
            });

            // start Petabridge.Cmd (for external monitoring / supervision)
            var pbm = PetabridgeCmd.Get(actorSystem);

            void RegisterPalette(CommandPaletteHandler h)
            {
                if (pbm.RegisterCommandPalette(h))
                {
                    Console.WriteLine("Petabridge.Cmd - Registered {0}", h.Palette.ModuleName);
                }
                else
                {
                    Console.WriteLine("Petabridge.Cmd - DID NOT REGISTER {0}", h.Palette.ModuleName);
                }
            }

            RegisterPalette(ClusterCommands.Instance);
            RegisterPalette(RemoteCommands.Instance);
            RegisterPalette(ClusterShardingCommands.Instance);
            RegisterPalette(new PriceCommands(shardRegion));
            pbm.Start();

            actorSystem.WhenTerminated.Wait();
            return(0);
        }
Esempio n. 18
0
        private static ActorSystem StartPbm(this ActorSystem actorSystem)
        {
            var pbm = PetabridgeCmd.Get(actorSystem);

            pbm.RegisterCommandPalette(ClusterCommands.Instance);
            pbm.RegisterCommandPalette(RemoteCommands.Instance);
            pbm.RegisterCommandPalette(Petabridge.Cmd.Cluster.Sharding.ClusterShardingCommands.Instance);
            pbm.Start();
            return(actorSystem);
        }
Esempio n. 19
0
        static int Main(string[] args)
        {
            var sqlConnectionString = Environment.GetEnvironmentVariable("SQL_CONNECTION_STR");
            var sqlHostName         = Environment.GetEnvironmentVariable("SQL_HOSTNAME");

            if (string.IsNullOrEmpty(sqlConnectionString) || string.IsNullOrEmpty(sqlHostName))
            {
                Console.WriteLine("ERROR! No SQL Connection String specified. Exiting with code -1");
                return(-1);
            }

            //var hostIp = Dns.GetHostEntry(sqlHostName);
            //sqlConnectionString = sqlConnectionString.Replace("{HOSTNAME}", hostIp.AddressList.First().ToString());
            Console.WriteLine("Connecting to SQL Server via {0}", sqlConnectionString);

            var config = ConfigurationFactory.ParseString(File.ReadAllText("sharding.hocon"));

            var sqlHocon = "akka.persistence.journal.sql-server.connection-string = \"" + sqlConnectionString + "\"" +
                           Environment.NewLine +
                           "akka.persistence.snapshot-store.sql-server.connection-string = \"" + sqlConnectionString +
                           "\"";

            Console.WriteLine("Using SQL Hocon:" + Environment.NewLine + " {0}", sqlHocon);

            var sqlConnectionConfig = ConfigurationFactory.ParseString(sqlHocon)
                                      .WithFallback(config);

            var actorSystem = ActorSystem.Create("ShardFight", sqlConnectionConfig.BootstrapFromDocker().WithFallback(ClusterSharding.DefaultConfig()));

            ICancelable shardTask = null;

            Cluster.Get(actorSystem).RegisterOnMemberUp(() =>
            {
                var sharding            = ClusterSharding.Get(actorSystem);
                IActorRef myShardRegion = sharding.Start("entities", str => Props.Create(() => new PersistentEntityActor(str)),
                                                         ClusterShardingSettings.Create(actorSystem).WithRole("shard"), new FuberMessageExtractor());

                shardTask = actorSystem.Scheduler.Advanced.ScheduleRepeatedlyCancelable(TimeSpan.FromMilliseconds(250),
                                                                                        TimeSpan.FromMilliseconds(250),
                                                                                        () =>
                {
                    myShardRegion.Tell(new FuberEnvelope(ThreadLocalRandom.Current.Next(0, 100000).ToString(), ThreadLocalRandom.Current.Next().ToString()));
                });
            });

            var pbm = PetabridgeCmd.Get(actorSystem);

            pbm.RegisterCommandPalette(ClusterCommands.Instance);         // enable cluster management commands
            pbm.RegisterCommandPalette(ClusterShardingCommands.Instance); //enable cluster.sharding management commands
            pbm.Start();

            actorSystem.WhenTerminated.Wait();
            shardTask?.Cancel(); // should already be cancelled
            return(0);
        }
Esempio n. 20
0
        private static void Main(string[] args)
        {
            using (var actorSys = ActorSystem.Create("MyActorSystem"))
            {
                var pbm = PetabridgeCmd.Get(actorSys);                      // creates the Petabridge.Cmd.Host
                pbm.RegisterCommandPalette(new MsgCommandPaletteHandler()); // register custom command palette
                pbm.Start();                                                // begins listening for incoming connections on Petabridge.Cmd.Host

                actorSys.WhenTerminated.Wait();
            }
        }
Esempio n. 21
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            // start https://cmd.petabridge.com/ for diagnostics and profit
            var pbm = PetabridgeCmd.Get(_actors.Sys); // start Pbm

            pbm.RegisterCommandPalette(ClusterCommands.Instance);
            pbm.RegisterCommandPalette(new RemoteCommands());
            pbm.Start(); // begin listening for PBM management commands

            return(Task.CompletedTask);
        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            var         config = ConfigurationFactory.ParseString(File.ReadAllText("App.Akka.conf"));
            ActorSystem system = ActorSystem.Create("WarmupForClusterRouting", config);

            var cmd = PetabridgeCmd.Get(system);

            cmd.Start();

            system.ActorOf(ParentActor.Props(), nameof(ParentActor));

            Console.ReadLine();
        }
        public static async Task Main(string[] args)
        {
            var config      = ConfigurationFactory.ParseString(File.ReadAllText("app.conf")).BootstrapFromDocker();
            var actorSystem = ActorSystem.Create("ClusterSys", config);

            var pbm = PetabridgeCmd.Get(actorSystem);

            pbm.RegisterCommandPalette(ClusterCommands.Instance);
            pbm.RegisterCommandPalette(RemoteCommands.Instance);
            pbm.Start(); // begin listening for PBM management commands

            await actorSystem.WhenTerminated;
        }
Esempio n. 24
0
        public static void Main(string[] args)
        {
            var actorSystem = Bootstrap.CreateActorSystem();

            var mainActor = actorSystem.CreateShardedOrderSystem();

            var pbm = PetabridgeCmd.Get(actorSystem);

            pbm.RegisterCommandPalette(ClusterCommands.Instance);
            pbm.RegisterCommandPalette(RemoteCommands.Instance);
            pbm.Start();

            actorSystem.WhenTerminated.Wait();
        }
        static int Main(string[] args)
        {
            var config = File.ReadAllText("app.conf");
            var conf   = ConfigurationFactory.ParseString(config).BoostrapApplication(new AppBootstrapConfig(false, true));

            var actorSystem = ActorSystem.Create("AkkaTrader", conf);

            var tradeRouter = actorSystem.ActorOf(
                Props.Empty.WithRouter(new ClusterRouterGroup(
                                           new ConsistentHashingGroup(new[] { "/user/orderbooks" },
                                                                      TradeEventConsistentHashMapping.TradeEventMapping),
                                           new ClusterRouterGroupSettings(10000, new [] { "/user/orderbooks" }, true, useRole: "trade-processor"))), "tradesRouter");

            Cluster.Cluster.Get(actorSystem).RegisterOnMemberUp(() =>
            {
                var sharding = ClusterSharding.Get(actorSystem);

                var shardRegionProxy = sharding.StartProxy("orderBook", "trade-processor", new StockShardMsgRouter());
                foreach (var stock in AvailableTickerSymbols.Symbols)
                {
                    var max   = (decimal)ThreadLocalRandom.Current.Next(20, 45);
                    var min   = (decimal)ThreadLocalRandom.Current.Next(10, 15);
                    var range = new PriceRange(min, 0.0m, max);

                    // start bidders
                    foreach (var i in Enumerable.Repeat(1, ThreadLocalRandom.Current.Next(1, 6)))
                    {
                        actorSystem.ActorOf(Props.Create(() => new BidderActor(stock, range, shardRegionProxy)));
                    }

                    // start askers
                    foreach (var i in Enumerable.Repeat(1, ThreadLocalRandom.Current.Next(1, 6)))
                    {
                        actorSystem.ActorOf(Props.Create(() => new AskerActor(stock, range, shardRegionProxy)));
                    }
                }
            });

            // 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);
        }
Esempio n. 26
0
        static void Main(string[] args)
        {
            var         config = ConfigurationFactory.ParseString(File.ReadAllText("App.Akka.conf"));
            ActorSystem system = ActorSystem.Create("Deployer", config);

            var cmd = PetabridgeCmd.Get(system);

            cmd.Start();

            Console.WriteLine();
            Console.WriteLine("Deployer is running...");
            Console.WriteLine();

            //
            // 환경 설정으로 배포 설정하기
            //actor {
            //    provider = remote
            //    deployment {
            //        /DeployedEchoActor1 {
            //            remote = "akka.tcp://DeployerTarget@localhost:8091"
            //        }
            //    }
            //}
            //

            //
            // 1. 배포된 액터에서 예외가 발생하면 배포한 액터에게 전달된다.
            // 2. 예외가 발생한 소스 라인 정보까지 제공한다.
            //
            // [ERROR]
            // [2019-04-25 오전 11:46:35]
            // [Thread 0003]
            // [akka.tcp://DeployerTarget@localhost:8091/remote/akka.tcp/Deployer@localhost:8081/user/DeployedEchoActor] Attempted to divide by zero.
            // Cause: System.DivideByZeroException: Attempted to divide by zero.
            //    at DeployerShared.DeployedEchoActor.Handle(Int32 msg) in C:\Labs\Akka.NET-Labs\ClusterLab\04. Warm-up For Cluster Routing\04. Deploy - Hanlde Exceptions Raised by Deployed Actors\DeployerShared\DeployedEchoActor.cs:line 41
            //    at DeployerShared.DeployedEchoActor.<.ctor>b__2_0(Int32 _) in C:\Labs\Akka.NET-Labs\ClusterLab\04. Warm-up For Cluster Routing\04. Deploy - Hanlde Exceptions Raised by Deployed Actors\DeployerShared\DeployedEchoActor.cs:line 34
            //    at lambda_method(Closure, Object, Action`1)
            //    at Akka.Actor.ReceiveActor.ExecutePartialMessageHandler(Object message, PartialAction`1 partialAction)
            //    at Akka.Actor.UntypedActor.Receive(Object message)
            //    at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)
            //    at Akka.Actor.ActorCell.ReceiveMessage(Object message)
            //    at Akka.Actor.ActorCell.Invoke(Envelope envelope)
            //
            var deployedEchoActor = system.ActorOf(DeployedEchoActor.Props(), nameof(DeployedEchoActor));

            deployedEchoActor.Tell(0);

            Console.ReadLine();
        }
Esempio n. 27
0
        static void Main(string[] args)
        {
            //
            // Deploy될 Actor 클래스를 참조해야 한다.
            // 참조하지 않은 Actor는 Deployed되어 생성할 수 없다.
            //

            var         config = ConfigurationFactory.ParseString(File.ReadAllText("App.Akka.conf"));
            ActorSystem system = ActorSystem.Create("DeployerTarget", config);

            var cmd = PetabridgeCmd.Get(system);

            cmd.Start();

            Console.ReadLine();
        }
Esempio n. 28
0
        static void Main(string[] args)
        {
            var         config = ConfigurationFactory.ParseString(File.ReadAllText("App.Akka.conf"));
            ActorSystem system = ActorSystem.Create("ClusterLab", config);

            var cmd = PetabridgeCmd.Get(system);

            cmd.RegisterCommandPalette(ClusterCommands.Instance);
            cmd.Start();

            Console.WriteLine();
            Console.WriteLine("SeedNode1 is running...");
            Console.WriteLine();

            Console.ReadLine();
        }
Esempio n. 29
0
        static void Main(string[] args)
        {
            Console.WriteLine("CLIENT");

            system = ActorSystem.Create("calculation");

            var clientActor = system.ActorOf(Props.Create <CliClientActor>(), "cliClient");
            var cmd         = PetabridgeCmd.Get(system);

            cmd.RegisterCommandPalette(ClusterCommands.Instance);
            cmd.Start();

            clientActor.Tell(new AskUserForInputCommandMessage("Frage.."));

            system.WhenTerminated.Wait();
        }
Esempio n. 30
0
        //Creating a new WorkerService creates a new ActorSystem.
        public void Start(CancellationToken token)
        {
            _system = ActorSystem.Create(_actorSystemName, _akkaConfig);

            var cmd = PetabridgeCmd.Get(_system);

            cmd.RegisterCommandPalette(Petabridge.Cmd.Cluster.ClusterCommands.Instance);
            cmd.RegisterCommandPalette(Petabridge.Cmd.Cluster.Sharding.ClusterShardingCommands.Instance);
            // Register custom cmd commands here
            cmd.Start();

            DistributedPubSub.Get(_system);

            StartActors();

            token.Register(StopAsync);
        }