LoginSignup
1

More than 5 years have passed since last update.

Akkaでround robinのremote routing

Posted at

cluster構成で、remoteのround robin routerを使う場合の
設定、実装

round robinを使う場合のconf

application.conf
akka {
  actor {
    provider = "akka.cluster.ClusterActorRefProvider"

    deployment {
      /clusterrouter {
        router = round-robin-pool
        nr-of-instances = 10
        target.nodes = [
          "akka.tcp://MetaInfoScraperCluster@なんか:2550",
          "akka.tcp://MetaInfoScraperCluster@あれか:2550"
        ]
      }
    }
  }

  remote {
    log-remote-lifecycle-events = on
    netty.tcp {
      hostname = "127.0.0.1"
      port = 0
    }
  }

  cluster {
    seed-nodes = [
      "akka.tcp://MetaInfoScraperCluster@なんか:2550",
      "akka.tcp://MetaInfoScraperCluster@あれか:2550"
    ]
    auto-down-unreachable-after = 10s
    //auto-down = on
  }
}

clusterの生成

val system = ActorSystem("MetaInfoScraperCluster")
val clusterListener = system.actorOf(Props[ClusterListener],
      name = "clusterListener")
Cluster(system).subscribe(clusterListener, classOf[ClusterDomainEvent])

routerの生成

    val router = system.actorOf(FromConfig.props(Props[MetaInfoScraper]),    "clusterrouter")

      val urls = Source.fromFile(input).getLines()
      urls.filter(!_.startsWith("#")).zipWithIndex.foreach {
        case (url, i) => {
          println(s"!! url: $url")
          // HashingRouter
          //router.tell(ConsistentHashableEnvelope(Request(url),i), clusterListener)
          router.tell(Request(url), clusterListener)
        }
      }

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
1