2016-07-04 6 views
1
akka { 
    actor { 
    provider = "akka.cluster.ClusterActorRefProvider" 
    } 
    remote { 
    enabled-transports = ["akka.remote.netty.tcp"] 
    netty.tcp { 
     hostname = "127.0.0.1" 
     port = 0 
    } 
    } 
} 

akka.cluster { 
    seed-nodes = [ 
    "akka.tcp://[email protected]:2551", 
    "akka.tcp://[email protected]:2552" 
    ] 
} 

object AndromedaApiClusterActivator extends App { 
    val system = ActorSystem("MyCluster", ConfigFactory.load()) 
    val clusterController = system.actorOf(Props[MyCluster], name = "MyCluster") 
} 


class MyCluster extends Actor { 

    val log = Logging(context.system, this) 
    val cluster = Cluster(context.system) 

    override def preStart() { 
    cluster.subscribe(self, classOf[MemberEvent], classOf[UnreachableMember]) 
    } 

    override def postStop() { 
    cluster.unsubscribe(self) 
    } 

    override def receive = { 
    case x: MemberEvent => log.info("MemberEvent: {}", x) 
    case x: UnreachableMember => log.info("UnreachableMember {}: ", x) 
    } 

} 

Когда я запускаю его я получаю:Akka: Как запустить простой локальный кластер?

Association with remote system [akka.tcp://[email protected]:2552] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://[email protected]:2552]] Caused by: [Connection refused: /127.0.0.1:2552] 
Association with remote system [akka.tcp://[email protected]:2551] has failed, address is now gated for [5000] ms. Reason: [Association failed with [akka.tcp://[email protected]:2551]] Caused by: [Connection refused: /127.0.0.1:2551] 

Я не могу найти объяснение. Любая помощь?

+0

проверить в эта ссылка https://groups.google.com/forum/#!topic/akka-user/joTgQ6PDX0Y – aravindKrishna

ответ

1

Сначала вы должны запустить 2 узла, а затем подключиться к ним. Чтобы проиллюстрировать это, я создам обе системы внутри одного App, но вы можете запустить 2 экземпляра App с различными конфигурациями/портами, указанными в командной строке.

object Main extends App { 
    val system1 = ActorSystem("MyCluster1", ConfigFactory.load("node1.conf")) 
    val system2 = ActorSystem("MyCluster2", ConfigFactory.load("node2.conf")) 
    val clusterController = system1.actorOf(Props[MyCluster], name = "MyCluster1") 
} 

application.conf:

akka { 
    actor { 
    provider = "akka.cluster.ClusterActorRefProvider" 
    } 
    remote { 
    enabled-transports = ["akka.remote.netty.tcp"] 
    netty.tcp { 
     hostname = "127.0.0.1" 
     port = 2552 
    } 
    } 
} 

akka.cluster { 
    seed-nodes = [ 
    "akka.tcp://[email protected]:2552", 
    "akka.tcp://[email protected]:2553" 
    ] 
} 

Для запуска других узлов, я предлагаю, чтобы указать различные конфиги с node1.conf:

include "application" 

akka.remote.netty.tcp.port = 2552 

node2.conf:

include "application" 

akka.remote.netty.tcp.port = 2553 
Смежные вопросы