简体   繁体   中英

Akka.Net ClusterClientReceptionist multinode crash

I'm trying to create a sample that create a cluster able to process an order and a client that send order.

To do so i use the ClusterClientReceptionist and ClusterClient to communicate between an client and a cluster network.

Cluster Node code :

namespace ClusterNode
{
    class Program
    {
        static void Main(string[] args)
        {
            bool isFirst = false;
            using (var mutex = new Mutex(false, "5D14E338-616C-4637-93E7-E59D152DC005", out isFirst))
            {
                using (var system = ActorSystem.Create(nameof(Order), CreateConfig(isFirst)))
                {
                    var receptionistConfig = ClusterClientReceptionist.DefaultConfig();
                    system.Settings.InjectTopLevelFallback(receptionistConfig);

                    ClusterRouterPoolSettings settings = new ClusterRouterPoolSettings(int.MaxValue, 1, true);
                    ClusterRouterPool pool = new ClusterRouterPool(new Akka.Routing.RoundRobinPool(1), settings);

                    var aref = system.ActorOf(pool.Props(Props.Create<OrderProcessor>()), nameof(OrderProcessor));

                    var receptionist = ClusterClientReceptionist.Get(system);
                    receptionist.RegisterService(aref);

                    system.WhenTerminated.Wait();
                }
            }
        }

        private static Config CreateConfig(bool isFirst)
        {
            var configString = "akka { actor.provider = \"Akka.Cluster.ClusterActorRefProvider, Akka.Cluster\"\n";

            var port = (isFirst) ? 8082 : 0;

            configString += "remote { helios.tcp { hostname = localhost, port = " + port + " } }\n";
            configString += "cluster {\n seed-nodes = [\"akka.tcp://" + nameof(Order) + "@localhost:8082\"] \n";
            configString += "}\n";
            configString += "}";
            var config = ConfigurationFactory.ParseString(configString);
            return config;
        }
    }
}

Client side code :

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var system = ActorSystem.Create(nameof(Client), CreateConfig()))
            {
                system.Settings.InjectTopLevelFallback(ClusterClientReceptionist.DefaultConfig());
                var client = system.ActorOf(ClusterClient.Props(ClusterClientSettings.Create(system)));

                bool quit = false;
                while (!quit)
                {
                    var str = Console.ReadLine();

                    if (string.Equals(str, "QUIT", StringComparison.InvariantCultureIgnoreCase))
                    {
                        quit = true;
                        continue;
                    }

                    Order order = new Order() { Msg = str };

                    var respTask = client.Ask<Response>(new ClusterClient.Send("/user/OrderProcessor", order));
                    respTask.Wait();

                    Console.WriteLine(respTask.Result.ResponseMsg);
                }
                system.Terminate();
                system.WhenTerminated.Wait();
            }
        }

        private static Config CreateConfig()
        {
            var configString = "akka { actor.provider = \"Akka.Remote.RemoteActorRefProvider, Akka.Remote\"\n";
            configString += "remote { helios.tcp { hostname = localhost, port = 0 } }\n";
            configString += "cluster {\n seed-nodes = [\"akka.tcp://" + nameof(Order) + "@localhost:8082\"], ";
            configString += " client { initial-contacts : [ \"akka.tcp://" + nameof(Order) + "@localhost:8082/system/receptionist\" ] }";
            configString += " }\n";
            configString += "}";
            var config = ConfigurationFactory.ParseString(configString);
            return config;
        }
    }
}

When i create One cluster Node and one client the sample work. If i try to create multiple cluster node, their connect each other then directly dissasociate and the cluster collapsed.

if i comment the two folling lines the cluster work but the mechanism Receptionist/Client doesn't work.

var receptionist = ClusterClientReceptionist.Get(system);
receptionist.RegisterService(aref);              

Is their a configuration missing ?

I was just having the same issue today and managed to fix it by changing to Wire serialization instead of the default Json.

I had to add Akka.Serialization.Wire from NuGet and update the serialization bindings in the config, you can see this being used in the Cluster Tools Example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM