i checked two approaches, first using your code with ClusterRouterPool As you said, when the process that starts the router is killed, TestActor will not receive any more messages. When reading the documentation and testing, if you change in application.conf :
`auto-down-unreachable-after = 20s`
for this
`auto-down-unreachable-after = off`
TestActor continues to receive messages, although the following message appears in the log (I donβt know how to put the log here, sorry):
[WARN] [01/30/2017 17: 20: 26.017] [mySys-akka.remote.default-remote-dispatcher-5] [akka.tcp: // mySys@127.0.0.1 : 2554 / system / endpointManager / reliableEndpointWriter- akka.tcp% 3A% 2F% 2FmySys% 40127.0.0.1% 3A2552-0] Association with the remote system [akka.tcp: // mySys@127.0.0.1 : 2552] failed, the address is now blocked for [5000] ms. Reason: [Association failure with [akka.tcp: // mySys @ 12.0.0.1: 2552]] Called: [Connection refused: /127.0.0.1: 2552] [INFO] [01/30/2017 17: 20: 29.860] [mySys-akka.actor.default-dispatcher-4] [akka.tcp: // mySys@127.0.0.1 : 2554 / remote / akka.tcp / mySys @ 127.0.0.1: 2552 / user / testActors / c1] The router is located on paths Actor [akka.tcp: // mySys @ 12.0.0.1: 2552 / user / testActors # -1120251475] [WARN] [01/30/2017 17: 20: 32.016] [mySys-akka.remote.default-remote- dispatcher-5]
And in case of restarting MainApp, the log works fine without warning or errors
MainApp Magazine:
[INFO] [01/30/2017 17: 23: 32.756] [mySys-akka.actor.default-dispatcher-2] [akka.cluster.Cluster (akka: // mySys)] Node cluster [akka.tcp: / / mySys@127.0.0.1 : 2552] - Welcome to [akka.tcp: // mySys@127.0.0.1 : 2554]
TestActor Log:
INFO] [01/30/2017 17:23:21.958] [mySys-akka.actor.default-dispatcher-14] [akka.cluster.Cluster (akka: // mySys)] Node cluster [akka.tcp: // mySys@127.0.0.1 : 2554] - A new incarnation of an existing participant [Member (address = akka.tcp: // mySys@127.0.0.1 : 2552, status = Up)] is trying to join. Existing ones will be removed from the cluster, and then the new member will be allowed to join. [INFO] [01/30/2017 17: 23: 21.959] [mySys-akka.actor.default-dispatcher-14] [akka.cluster.Cluster (akka: // mySys)] Node cluster [akka.tcp: / / mySys@127.0.0.1 : 2554] - marking is not available Node [akka.tcp: // mySys@127.0.0.1 : 2552] as [Down] [INFO] [01/30/2017 17: 23: 22.454] [mySys-akka. actor.default-dispatcher-2] [akka.cluster.Cluster (akka: // mySys)] Node cluster [akka.tcp: // mySys@127.0.0.1 : 2554] - The leader can fulfill his duties again [INFO] [01 / 30/2017 17: 23: 22.461] [mySys-akka.actor.default-dispatcher-2] [akka.cluster.Cluster (akka: // mySys)] Node cluster [akka.tcp: // mySys@127.0.0.1 : 2554] - The leader removes the unreachable Node [akka.tcp: // mySys@127.0.0.1 : 2552] [INFO] [01/30/2017 17: 23: 32.728] [mySys-akka.actor.default-dispatcher-4] [akka.cluster.Cluster (akka: // mySys)] Node cluster [akka.tcp: // mySys@127.0.0.1 : 2554] - Node [akka.tcp: // mySys@127.0.0.1 mySys@127.0.0.1 : 2552] - SAVE, roles [] [INFO] [01/30/2017 17: 23: 33.457] [mySys-akka.actor.default-dispatcher-14] [akka.cluster.Cluster (akka: // mySys)] Node cluster [akka.tcp: // mySys@127.0.0.1 : 2554] - The leader moves Node [akka.tcp: // mySys @ 12.0.0.1: 2552] to [Up] [INFO] [01/30 / 2017 17: 23: 37.925] [mySys-akka.actor.default-dispatcher-19] [akka.tcp: // mySys@127.0.0.1 : 2554 / remote / akka.tcp / mySys @ 127.0.0.1: 2552 / user / testActors / c1] The router is on the Actor path [akka.tcp: // mySys @ 12.0.0.1: 2552 / user / testActors # -630150507]
Another approach is to use ClusterRouterGroup , as routes are distributed between the nodes of the cluster
- Group - a router that sends messages to a specified path using actor selection . Routes can be used in conjunction with routers operating on different nodes of the cluster. One example of use for this type of router is a service running on some base nodes of a cluster and used by routers running on the interface nodes of the cluster.
- A pool is a router that creates routes as child entities and deploys them to remote nodes. Each router will have its own route instances. For example, if you run the router on 3 nodes of a 10-node cluster, you will get 30 routes if the router is configured to use one instance per node. Routes created by different routers will not be shared with routers. One example of use for this type of router is a single leader, which coordinates tasks and delegates actual work to routes running on other nodes in the cluster.
Main application
object Main extends App { val system = ActorSystem("mySys", ConfigFactory.load("application.conf")) val routerGroup = system.actorOf( ClusterRouterGroup(RoundRobinGroup(Nil), ClusterRouterGroupSettings( totalInstances = 2, routeesPaths = List("/user/testActor"), allowLocalRoutees = false, useRole = Some("testActor"))).props(), name = "testActors") }
you must run TestActor on every remote node device
object TestActor extends App{ val system = ActorSystem("mySys", ConfigFactory.load("application").getConfig("testactor1")) system.actorOf(Props[TestActor],"testActor") case object PrintRouterPath }
http://doc.akka.io/docs/akka/2.4/scala/cluster-usage.html#Router_with_Group_of_Routees
Route actors must start as early as possible when the actors system starts, because the router will try to use them as soon as the participant status is changed to "Up".
I hope this helps you