Example #1
0
        public void LoggingConfiguration()
        {
            var level        = LogLevelEnum.WARNING;
            var loggerName   = "Name";
            var loggerBinary = "Binary";

            var mock = new Mock <ILoggingConfig>();

            mock.Setup(x => x.LogLevel).Returns(level);
            mock.Setup(x => x.LoggerClassName).Returns(loggerName);
            mock.Setup(x => x.LoggerBinaryName).Returns(loggerBinary);

            var cfg = CommonConfigs.CreateLoggingConfig(mock.Object);

            cfg.GetString("akka.loglevel").Should().Be(level.ToString());
            cfg.GetStringList("akka.loggers").Should().BeEquivalentTo(new[] { $"{loggerName}, {loggerBinary}" });
        }
Example #2
0
        static void Main(string[] args)
        {
            var numArgs = 2;

            if (args.Length < numArgs)
            {
                Log.Fatal("Cluster Bootstrapper does not have the correct number of arguments. Expected at least {ExpectedArguments} but received {NumberOfArguments}", numArgs, args.Length);
                var count = 1;
                foreach (var arg in args)
                {
                    Log.Information("Arg[{ArgumentIndex}]:{Argument}", count, arg);
                    Log.CloseAndFlush();
                }
                return;
            }

            var loggerFactory = new ElasticSearchLoggerFactory(new Uri("http://*****:*****@{hostname}:4053";

            // Create the system and actors
            var cfg = CommonConfigs.BasicConfig()                         // Supress JSON warning
                      .WithFallback(ClusterNodeConstants.DefaultConfig()) // With default actor props factory
                      .WithFallback(
                ClusterConfigs.CreateClusterConfig(
                    new DefaultClusterConfig(
                        hostname, 0,
                        seedNodes: new[] { seedNode },
                        roles: roles.Select(x => (Key: x, Value: 0)).ToDictionary(x => x.Key, x => x.Value)
                        )
                    )
                )
                      .WithFallback(CommonConfigs.CreateLoggingConfig(new SerilogConfig())); // Serilog logging

            var system       = ActorSystem.Create(systemName, cfg);
            var configurator = system.ActorOf(Props.Create(() => new NodeConfigurator()), "configurator");

            Console.CancelKeyPress += async(sender, eventArgs) =>
            {
                Console.WriteLine("Stopping Cluster Worker...");
                await CoordinatedShutdown.Get(system).Run();
            };

            // Waits until service is terminated and then exits the program
            system.WhenTerminated.Wait();

            logger.Information("Cluster Worker stopped");

            Log.CloseAndFlush();
        }
Example #3
0
        static void Main()
        {
            var loggerFactory = new ElasticSearchLoggerFactory(new Uri("http://*****:*****@{hostname}:{port}";

            // Create the system and actors
            var cfg = CommonConfigs.BasicConfig()                         // Supress JSON warning
                      .WithFallback(ClusterNodeConstants.DefaultConfig()) // With default actor props factory
                      .WithFallback(
                ClusterConfigs.CreateClusterConfig(
                    new DefaultClusterConfig(
                        hostname, port,                     // hostname and any port
                        seedNodes: new [] { selfSeedNode }, // Seed nodes
                        roles: roles
                        )
                    )
                )
                      .WithFallback(CommonConfigs.CreateLoggingConfig(new SerilogConfig())); // Serilog logging

            var system = ActorSystem.Create(systemName, cfg);                                //

            // Create configurations
            var workerNodeConfig = new SystemConfiguration(
                new RandomLoggerActorConfiguration("LoggerOne", TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(3), "Logs"),
                new RandomLoggerActorConfiguration("LoggerTwo", TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(3), "Logs"),
                new RandomLoggerActorConfiguration("LoggerThree", TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(3), "Logs"),
                new RandomLoggerActorConfiguration("LoggerFour", TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(3), "Logs"),
                new RandomLoggerActorConfiguration("LoggerFive", TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(3), "Logs")
                );

            var listenerNodeConfig = new SystemConfiguration(new LogConfirmationActorConfiguration("ListenerPlugin", "Logs"));



            var targetNode     = $"akka.tcp://{ClusterNodeConstants.DefaultSystemName}@{hostname}:4053";
            var clientSettings = ClusterClientSettings.Create(system)
                                 .WithInitialContacts(
                new[]
            {
                ActorPath.Parse(targetNode + "/system/receptionist")
            }.ToImmutableHashSet()
                );

            var clusterClient = system.ActorOf(ClusterClient.Props(clientSettings), "cluster-client");

            // Publishes to given topic
            clusterClient.Tell(new ClusterClient.Publish("client-messages", new ConfigureRoles(workerNodeConfig, "worker")));
            clusterClient.Tell(new ClusterClient.Publish("client-messages", new ConfigureRoles(listenerNodeConfig, "listener")));

            // // Sends direct to known singleton proxy
            // clusterClient.Tell(new ClusterClient.Send("/user/manager", new ConfigureRoles(workerNodeConfig, "worker")));
            // clusterClient.Tell(new ClusterClient.Send("/user/manager", new ConfigureRoles(listenerNodeConfig, "listener")));

            Console.CancelKeyPress += async(sender, eventArgs) =>
            {
                Console.WriteLine("Stopping Cluster Bootstrapper...");
                await CoordinatedShutdown.Get(system).Run();
            };

            // Waits until service is terminated and then exits the program
            system.WhenTerminated.Wait();

            logger.Information("Cluster Bootstrapper stopped");
            Log.CloseAndFlush();
        }