Пример #1
0
        static void Main(string[] args)
        {
            var loggerFactory = new ElasticSearchLoggerFactory(new Uri("http://localhost:9200"));
            var consoleSwitch = loggerFactory.ConsoleSwitch;
            var elasticSwitch = loggerFactory.ElasticsearchSwitch;

            Log.Logger = loggerFactory.GetLogger();

            var logger = loggerFactory.GetLogger().ForContext(LoggingExtensions.Identity, "Hub", true);

            logger.Information("Cluster Hub started");

            HubService hubService = null;

            // If there are no arguments the just uses the hub.hocon file as it is.
            // Asks if the user is ok with that.
            if (args.Length == 0)
            {
                Console.WriteLine("No arguments specified. Should the Hub use the 'hub.hocon' file?");

                var shouldUse = GetResponse();
                if (shouldUse)
                {
                    Console.WriteLine("Using 'hub.hocon'...");
                    if (!File.Exists("hub.hocon"))
                    {
                        Console.WriteLine($"Could not find 'hub.hocon' in {Directory.GetCurrentDirectory()}");
                        return;
                    }
                    hubService = new HubService();
                }
                else
                {
                    Console.WriteLine("Stopping...");
                    Console.WriteLine("Usage: <Actor System Name> <IP Address> <port != 0>");
                    return;
                }
            }
            // No arguments or 3 arguments specifying the three configurables.
            else if (args.Length != 3)
            {
                Console.WriteLine($"Expected three arguments only. Received {string.Join(",", args)}");
                Console.WriteLine("Usage: <Actor System Name> <IP Address> <port != 0>");
                return;
            }
            else
            {
                var systemName = args[0];
                var ipAddress  = args[1];
                if (!int.TryParse(args[2], out var portValue))
                {
                    Console.WriteLine("Could not parse the port {args[2]} as an integer");
                    return;
                }

                hubService = new HubService(ipAddress, portValue, systemName);
            }

            // Start the actor system
            if (!(hubService?.Start() ?? false))
            {
                Console.WriteLine("Failed to create actor system. Exiting.");
                return;
            }

            Console.WriteLine("Starting Cluster Hub.");
            Console.WriteLine("Press Ctrl+C to stop...");

            // Stop on escape sequence key press
            Console.CancelKeyPress += async(sender, eventArgs) =>
            {
                Log.Information("Stopping Hub Service...");
                await hubService.StopAsync();
            };

            // Waits until service is terminated and then exits the program
            hubService.TerminationHandle.Wait();
            Log.CloseAndFlush();
        }
Пример #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();
        }
Пример #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();
        }