Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("How to use: ShardingNode [port]");
                return;
            }

            if (!int.TryParse(args[0], out var port))
            {
                Console.WriteLine("How to use: ShardingNode [port]");
                return;
            }

            var config = ConfigurationFactory.ParseString($@"
akka.remote.dot-netty.tcp.hostname = localhost
akka.remote.dot-netty.tcp.port = {port}")
                         .WithFallback(ClusterSharding.DefaultConfig());

            var system = ActorSystem.Create("ClusterSharding");

            var counterRegion = ClusterSharding.Get(system).Start(
                typeName: "Counter",
                entityProps: Props.Create <CounterPersistentActor>(),
                settings: ClusterShardingSettings.Create(system),
                extractEntityId: ExtractEntityId,
                extractShardId: ExtractShardId);
        }
Ejemplo n.º 2
0
 public static Config GetConfig()
 {
     return(ConfigurationFactory.ParseString(@"akka.actor.provider = cluster
         akka.remote.dot-netty.tcp.port = 0")
            .WithFallback(ClusterSharding.DefaultConfig())
            .WithFallback(ClusterSingletonManager.DefaultConfig()));
 }
 static CoordinatedShutdownShardingSpec()
 {
     SpecConfig = ConfigurationFactory.ParseString(@"
         akka.loglevel = DEBUG
         akka.actor.provider = cluster
         akka.remote.dot-netty.tcp.port = 0")
                  .WithFallback(ClusterSingletonManager.DefaultConfig()
                                .WithFallback(ClusterSharding.DefaultConfig()));
 }
Ejemplo n.º 4
0
        public static ActorSystem Start(string[] args)
        {
            var config = ConfigurationFactory.ParseString(File.ReadAllText("node.hocon"))
                         .WithFallback(ClusterSharding.DefaultConfig())
                         .BootstrapFromDocker();

            actorSystem = ActorSystem.Create("xTreamCacheSystem", config);
            return(actorSystem);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
 static PersistentShardSpec()
 {
     SpecConfig = ConfigurationFactory.ParseString(@"
         akka.loglevel = DEBUG
         akka.actor.provider = cluster
         akka.persistence.journal.plugin = ""akka.persistence.journal.inmem""
         akka.remote.dot-netty.tcp.port = 0")
                  .WithFallback(ClusterSingletonManager.DefaultConfig()
                                .WithFallback(ClusterSharding.DefaultConfig()));
 }
Ejemplo n.º 7
0
        public static Actors Build()
        {
            var hocon = File.ReadAllText("api.hocon");

            var config = ConfigurationFactory
                         .ParseString(hocon)
                         .WithFallback(ClusterSharding.DefaultConfig())
                         .BootstrapFromDocker();

            Instance = new Actors(config);

            return(Instance);
        }
Ejemplo n.º 8
0
        public static ActorSystem CreateShardedActorSystem()
        {
            if (Debugger.IsAttached) // If we're launching running from visual studio, set CLUSTER_IP
            {
                Environment.SetEnvironmentVariable("CLUSTER_IP", "localhost");
            }

            var config = HoconLoader.FromFile("akka-config.hocon");

            return(ActorSystem.Create("amazing",
                                      config
                                      .WithFallback(ClusterSharding.DefaultConfig())
                                      .BootstrapFromDocker()));
        }
Ejemplo n.º 9
0
        private static Config GetConfig()
        {
            return(ConfigurationFactory.ParseString(@"
                akka.actor.provider = cluster
                akka.remote.dot-netty.tcp.port = 0
                akka.remote.dot-netty.tcp.hostname = 127.0.0.1

                # ping often/start fast for test
                akka.cluster.sharded-daemon-process.keep-alive-interval = 1s

                akka.coordinated-shutdown.terminate-actor-system = off
                akka.coordinated-shutdown.run-by-actor-system-terminate = off")
                   .WithFallback(ClusterSharding.DefaultConfig())
                   .WithFallback(ClusterSingletonProxy.DefaultConfig()));
        }
Ejemplo n.º 10
0
        static ShardSpec()
        {
            SpecConfig = ConfigurationFactory.ParseString(@"

                akka.loglevel = INFO
                akka.actor.provider = ""cluster""
                akka.remote.dot-netty.tcp.port = 0
                test-lease {
                    lease-class = ""Akka.Coordination.Tests.TestLease, Akka.Coordination.Tests""
                    heartbeat-interval = 1s
                    heartbeat-timeout = 120s
                    lease-operation-timeout = 3s
                }")
                         .WithFallback(ClusterSingletonManager.DefaultConfig()
                                       .WithFallback(ClusterSharding.DefaultConfig()));
        }
Ejemplo n.º 11
0
        static int Main(string[] args)
        {
            var config = File.ReadAllText("app.conf");
            var conf   = ConfigurationFactory.ParseString(config)
                         .WithFallback(OpsConfig.GetOpsConfig())
                         .WithFallback(ClusterSharding.DefaultConfig())
                         .WithFallback(DistributedPubSub.DefaultConfig());

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

            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, 2)))
                    {
                        actorSystem.ActorOf(Props.Create(() => new BidderActor(stock, range, shardRegionProxy)));
                    }

                    // start askers
                    foreach (var i in Enumerable.Repeat(1, ThreadLocalRandom.Current.Next(1, 2)))
                    {
                        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);
        }
Ejemplo n.º 12
0
        public static Config BoostrapApplication(this Config c, AppBootstrapConfig appConfig)
        {
            var config = c;

            if (appConfig.NeedPersistence)
            {
                var mongoConnectionString = Environment.GetEnvironmentVariable("MONGO_CONNECTION_STR")?.Trim();
                if (string.IsNullOrEmpty(mongoConnectionString))
                {
                    Console.WriteLine("ERROR! MongoDb connection string not provided. Can't start.");
                    throw new ConfigurationException("ERROR! MongoDb connection string not provided. Can't start.");
                }
                else
                {
                    Console.WriteLine("Connecting to MongoDb at {0}", mongoConnectionString);
                }

                config = c.WithFallback(GetMongoHocon(mongoConnectionString));
            }

            config = config
                     .WithFallback(GetOpsConfig())
                     .WithFallback(TradeEventSerializer.Config)
                     .WithFallback(ClusterSharding.DefaultConfig())
                     .WithFallback(DistributedData.DistributedData.DefaultConfig()) // needed for DData sharding
                     .WithFallback(ClusterClientReceptionist.DefaultConfig())
                     .WithFallback(DistributedPubSub.DefaultConfig())
                     .BootstrapFromDocker();


#if PHOBOS
            return(config.BootstrapPhobos(appConfig));
#else
            if (!appConfig.NeedClustering)
            {
                return(ConfigurationFactory.ParseString("akka.actor.provider = remote").WithFallback(config));
            }


            return(config);
#endif
        }
 public static Config GetConfig()
 {
     return(ConfigurationFactory.ParseString(@"
         akka.loglevel = DEBUG
         #akka.loggers = [""akka.testkit.SilenceAllTestEventListener""]
         akka.loggers = [Akka.Event.DefaultLogger]
         akka.actor.provider = ""cluster""
         akka.remote.dot-netty.tcp.port = 0
         akka.cluster.sharding {
             use-lease = ""test-lease""
             lease-retry-interval = 200ms
             distributed-data.durable {
                 keys = []
             }
         }
         ")
            .WithFallback(ClusterSharding.DefaultConfig())
            .WithFallback(ClusterSingletonManager.DefaultConfig())
            .WithFallback(TestLease.Configuration));
 }
Ejemplo n.º 14
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(OpsConfig.GetOpsConfig())
                         .WithFallback(ClusterSharding.DefaultConfig())
                         .WithFallback(DistributedPubSub.DefaultConfig());

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

            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);
        }
        public ShardedDaemonProcessSpecConfig()
        {
            First  = Role("first");
            Second = Role("second");
            Third  = Role("third");

            CommonConfig = DebugConfig(false)
                           .WithFallback(ConfigurationFactory.ParseString(@"
                    akka.loglevel = INFO
                    akka.cluster.sharded-daemon-process {{
                      sharding {{
                        # First is likely to be ignored as shard coordinator not ready
                        retry-interval = 0.2s
                      }}
                      # quick ping to make test swift
                      keep-alive-interval = 1s
                    }}
                "))
                           .WithFallback(ClusterSharding.DefaultConfig())
                           .WithFallback(ClusterSingletonManager.DefaultConfig())
                           .WithFallback(MultiNodeClusterSpec.ClusterConfig());
        }
 static ClusterShardingMessageSerializerSpec()
 {
     SpecConfig = ClusterSingletonManager.DefaultConfig().WithFallback(ClusterSharding.DefaultConfig());
 }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        public static ActorSystem LaunchLighthouse(string ipAddress = null, int?specifiedPort = null, string systemName = null)
        {
            systemName = systemName ?? Environment.GetEnvironmentVariable("ACTORSYSTEM")?.Trim();
            ipAddress  = ipAddress ?? Environment.GetEnvironmentVariable("CLUSTER_IP")?.Trim();
            if (specifiedPort == null)
            {
                var envPort = Environment.GetEnvironmentVariable("CLUSTER_PORT")?.Trim();
                if (!string.IsNullOrEmpty(envPort) && int.TryParse(envPort, out var actualPort))
                {
                    specifiedPort = actualPort;
                }
            }

            var clusterConfig = ConfigurationFactory.ParseString(File.ReadAllText("lighthouse.hocon"));

            var lighthouseConfig = clusterConfig.GetConfig("lighthouse");

            if (lighthouseConfig != null && string.IsNullOrEmpty(systemName))
            {
                systemName = lighthouseConfig.GetString("actorsystem", systemName);
            }

            var remoteConfig = clusterConfig.GetConfig("akka.remote");

            if (string.IsNullOrEmpty(ipAddress))
            {
                ipAddress = remoteConfig.GetString("dot-netty.tcp.public-hostname") ??
                            "127.0.0.1"; //localhost as a final default
            }

            int port = specifiedPort ?? remoteConfig.GetInt("dot-netty.tcp.port");

            if (port == 0)
            {
                throw new ConfigurationException("Need to specify an explicit port for Lighthouse. Found an undefined port or a port value of 0 in App.config.");
            }

            var selfAddress = $"akka.tcp://{systemName}@{ipAddress}:{port}";

            /*
             * Sanity check
             */
            Console.WriteLine($"[Lighthouse] ActorSystem: {systemName}; IP: {ipAddress}; PORT: {port}");
            Console.WriteLine("[Lighthouse] Performing pre-boot sanity check. Should be able to parse address [{0}]", selfAddress);
            selfAddress = new Address("akka.tcp", systemName, ipAddress.Trim(), port).ToString();
            Console.WriteLine("[Lighthouse] Parse successful.");

            var clusterSeeds = Environment.GetEnvironmentVariable("CLUSTER_SEEDS")?.Trim();

            var seeds = clusterConfig.GetStringList("akka.cluster.seed-nodes");

            if (!string.IsNullOrEmpty(clusterSeeds))
            {
                var tempSeeds = clusterSeeds.Trim('[', ']').Split(',');
                if (tempSeeds.Any())
                {
                    seeds = tempSeeds;
                }
            }


            if (!seeds.Contains(selfAddress))
            {
                seeds.Add(selfAddress);
            }

            var injectedClusterConfigString = seeds.Aggregate("akka.cluster.seed-nodes = [", (current, seed) => current + (@"""" + seed + @""", "));

            injectedClusterConfigString += "]";

            var finalConfig = ConfigurationFactory.ParseString(
                string.Format(@"akka.remote.dot-netty.tcp.public-hostname = {0} 
akka.remote.dot-netty.tcp.port = {1}", ipAddress, port))
                              .WithFallback(ConfigurationFactory.ParseString(injectedClusterConfigString))
                              .WithFallback(ClusterSharding.DefaultConfig())
                              .WithFallback(clusterConfig)
                              .BootstrapFromDocker();

            return(ActorSystem.Create(systemName, finalConfig));
        }
        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(OpsConfig.GetOpsConfig())
                         .WithFallback(ClusterSharding.DefaultConfig())
                         .WithFallback(DistributedPubSub.DefaultConfig());

            var actorSystem     = ActorSystem.Create("AkkaPricing", conf.BootstrapFromDocker());
            var readJournal     = actorSystem.ReadJournalFor <MongoDbReadJournal>(MongoDbReadJournal.Identifier);
            var priceViewMaster = actorSystem.ActorOf(Props.Create(() => new PriceViewMaster()), "prices");

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

                // start the creation of the pricing views
                priceViewMaster.Tell(new PriceViewMaster.BeginTrackPrices(shardRegion));
            });

            // 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(priceViewMaster));
            pbm.Start();

            actorSystem.WhenTerminated.Wait();
            return(0);
        }