Exemple #1
0
        public void RemotingConfiguration()
        {
            var hostname = "my-host";
            var port     = 1234;
            var provider = "remote";

            var mock = new Mock <IRemotingConfig>();

            mock.Setup(x => x.Hostname).Returns(hostname);
            mock.Setup(x => x.Port).Returns(port);
            mock.Setup(x => x.Provider).Returns(provider);

            var cfg = ClusterConfigs.CreateRemotingConfig(mock.Object);

            cfg.GetString("akka.actor.provider").Should().Be(provider);
            cfg.GetString("akka.remote.dot-netty.tcp.hostname").Should().Be(hostname);
            cfg.GetInt("akka.remote.dot-netty.tcp.port").Should().Be(port);
        }
Exemple #2
0
        public void ClusterConfiguration()
        {
            var hostname   = "my-host";
            var port       = 1234;
            var provider   = "cluster";
            var systemName = "System";
            var seedNodes  = new[] { $"akka.tcp://{systemName}@{hostname}:{port}" };

            var roles = new Dictionary <string, int>
            {
                { "Worker", 1 },
                { "Server", 2 }
            };

            var mock = new Mock <IClusterConfig>();

            mock.Setup(x => x.Hostname).Returns(hostname);
            mock.Setup(x => x.Port).Returns(port);
            mock.Setup(x => x.Provider).Returns(provider);

            mock.Setup(x => x.SeedNodePaths).Returns(seedNodes);
            mock.Setup(x => x.MinNodeNumberForUp).Returns(1);
            mock.Setup(x => x.Roles).Returns(roles);

            var cfg = ClusterConfigs.CreateClusterConfig(mock.Object);

            cfg.GetString("akka.actor.provider").Should().Be(provider);
            cfg.GetString("akka.remote.dot-netty.tcp.hostname").Should().Be(hostname);
            cfg.GetInt("akka.remote.dot-netty.tcp.port").Should().Be(port);

            cfg.GetInt("akka.cluster.min-nr-of-members").Should().Be(1);
            cfg.GetStringList("akka.cluster.seed-nodes").Should().BeEquivalentTo(seedNodes);
            cfg.GetStringList("akka.cluster.roles").Should().BeEquivalentTo(roles.Keys);
            cfg.GetInt("akka.cluster.role.Worker.min-nr-of-members").Should().Be(1);
            cfg.GetInt("akka.cluster.role.Server.min-nr-of-members").Should().Be(2);
        }
Exemple #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();
        }