我想创建一个不会出现单点故障的系统.我的印象是路由器是这样做的工具,但我不确定它是否像我期望的那样工作.这是我的计划的切入点:
object Main extends App{ val system = ActorSystem("mySys", ConfigFactory.load("application")) val router = system.actorOf( ClusterRouterPool(RoundRobinPool(0), ClusterRouterPoolSettings( totalInstances = 2, maxInstancesPerNode = 1, allowLocalRoutees = false, useRole = Some("testActor"))).props(Props[TestActor]), name = "testActors") }
这是运行远程的代码ActorSystem
(因此路由器可以将TestActor
代码部署到远程节点):
object TestActor extends App{ val system = ActorSystem("mySys", ConfigFactory.load("application").getConfig("testactor1")) case object PrintRouterPath }
我正在运行两次,一次使用testactor1
,一次使用testactor2
.
TestActor
码:
class TestActor extends Actor with ActorLogging{ implicit val ExecutionContext = context.dispatcher context.system.scheduler.schedule(10000 milliseconds, 30000 milliseconds,self, PrintRouterPath) override def receive: Receive = { case PrintRouterPath => log.info(s"router is on path ${context.parent}") } }
和application.conf
akka{ actor { provider = "akka.cluster.ClusterActorRefProvider" } remote { log-remote-lifecycle-events = off netty.tcp { hostname = "127.0.0.1" port = 2552 } } cluster { seed-nodes = [ "akka.tcp://mySys@127.0.0.1:2552" "akka.tcp://mySys@127.0.0.1:2553" "akka.tcp://mySys@127.0.0.1:2554"] auto-down-unreachable-after = 20s } } testactor1{ akka{ actor { provider = "akka.cluster.ClusterActorRefProvider" } remote { log-remote-lifecycle-events = off netty.tcp { hostname = "127.0.0.1" port = 2554 } } cluster { roles.1 = "testActor" seed-nodes = [ "akka.tcp://mySys@127.0.0.1:2552" "akka.tcp://mySys@127.0.0.1:2553" "akka.tcp://mySys@127.0.0.1:2554"] auto-down-unreachable-after = 20s } } } testactor2{ akka{ actor { provider = "akka.cluster.ClusterActorRefProvider" } remote { log-remote-lifecycle-events = off netty.tcp { hostname = "127.0.0.1" port = 2553 } } cluster { roles.1 = "testActor" seed-nodes = [ "akka.tcp://mySys@127.0.0.1:2552" "akka.tcp://mySys@127.0.0.1:2553" "akka.tcp://mySys@127.0.0.1:2554"] auto-down-unreachable-after = 20s } } }
现在的问题是,当启动路由器的进程被终止时,运行代码的actor TestActor
没有收到任何消息(调度程序发送的消息),我本以为路由器将部署在另一个上群集中的种子节点和actor将被恢复.这可能吗?或者是否有其他方法来实现此流程并且没有单点故障?