2016-02-14 155 views
1

我試圖運行由AKKA遠程演員錯誤

1. Running the remote actor in a machine with IP 192.168.1.7 
2. Running the local from my machine 

遠程演員在啓動機器(IP地址爲192.168.1.7)的AKKA遠程例子;但是當我從我的機器啓動Local actor時,它無法連接到遠程actor。請找到本地和遠程的演員系統配置:

地方:

akka { 
    //loglevel = "INFO" 
    actor { 
    provider = "akka.remote.RemoteActorRefProvider" 
    } 
    remote { 
    enabled-transports = ["akka.remote.netty.tcp"] 
    netty.tcp { 
     hostname = "127.0.0.1" 
     port = 0 
    } 
    //log-sent-messages = on 
    //log-received-messages = on 
    } 
} 

遠程:

akka { 
    //loglevel = "INFO" 
    actor { 
    provider = "akka.remote.RemoteActorRefProvider" 
    } 
    remote { 
    enabled-transports = ["akka.remote.netty.tcp"] 
    netty.tcp { 
     hostname = "127.0.0.1" 
     port = 5150 
    } 
    //log-sent-messages = on 
    //log-received-messages = on 
    } 
} 

代碼在本地系統連接到遠程的演員:

class LocalActor extends Actor { 
    val remote = context.actorFor("akka.tcp://[email protected]:5150/user/RemoteActor") 
    var counter = 0 
    def receive = { 
    case "START" => 
     remote ! "Hello from the LocalActor" 
    case msg: String => 
     println(s"LocalActor received message: '$msg'") 
     if (counter < 5) { 
      sender ! "Hello back to you" 
      counter += 1 
     } 
    } 
} 

當我啓動本地系統時,我收到以下消息:

C:\Users\AnandKrishnan\Documents\GitHub\AkkaRemoteActorsHelloWorld\HelloLocal [master +0 ~5 -0]> sbt run 
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0 
[info] Set current project to HelloLocal (in build file:/C:/Users/AnandKrishnan/Documents/GitHub/AkkaRemoteActorsHelloWorld/HelloLocal/) 
[info] Compiling 1 Scala source to C:\Users\AnandKrishnan\Documents\GitHub\AkkaRemoteActorsHelloWorld\HelloLocal\target\scala-2.11\classes... 
[warn] there was one deprecation warning; re-run with -deprecation for details 
[warn] one warning found 
[info] Running local.Local 
[INFO] [02/14/2016 22:57:11.755] [run-main-0] [Remoting] Starting remoting 
[INFO] [02/14/2016 22:57:12.163] [run-main-0] [Remoting] Remoting started; listening on addresses :[akka.tcp://[email protected]:50830] 
[INFO] [02/14/2016 22:57:12.163] [run-main-0] [Remoting] Remoting now listens on addresses: [akka.tcp://[email protected]:50830] 
[WARN] [02/14/2016 22:57:13.351] [LocalSystem-akka.remote.default-remote-dispatcher-5] [akka.tcp://[email protected]:50830/system/endpointManager/reliableEndpointWriter-akka.tcp 
%3A%2F%2FHelloRemoteSystem%40192.168.1.7%3A5150-0/endpointWriter] AssociationError [akka.tcp://[email protected]:50830] -> [akka.tcp://[email protected]:5150]: Error 
[Invalid address: akka.tcp://[email protected]:5150] [ 
akka.remote.InvalidAssociation: Invalid address: akka.tcp://[email protected]:5150 
Caused by: akka.remote.transport.Transport$InvalidAssociationException: Connection refused: no further information: /192.168.1.7:5150 
] 
[WARN] [02/14/2016 22:57:13.371] [LocalSystem-akka.remote.default-remote-dispatcher-6] [Remoting] Tried to associate with unreachable remote address [akka.tcp://[email protected]:5150]. Address is now gated for 5000 ms, all messages to this address will be delivered to dead letters. Reason: Connection refused: no further information: /192.168.1.7:5150 
[INFO] [02/14/2016 22:57:13.389] [LocalSystem-akka.actor.default-dispatcher-3] [akka://LocalSystem/deadLetters] Message [java.lang.String] from Actor[akka://LocalSystem/user/LocalActor#1441959988] to Actor[akka://LocalSystem/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'. 
+0

是你能解決這個問題? –

回答

0

爲了讓Akka actor系統與其他主機通信,actor系統必須綁定到可由其他主機路由的主機名或IP。 localhost,當然不是。

你的遠程系統需要綁定到192.168.1.7:

akka { 
    remote { 
    netty.tcp { 
     hostname = "192.168.1.7" 
    } 
    } 
} 

當然,你可能會希望使用主機名,而不是IP地址的生產。

+0

嗨,我的遠程演員在192.168.1.7上運行。同樣在創建actor(val remote)的本地代碼中,我遇到了遠程IP。你可以更具體地瞭解上面配置中需要改變的部分嗎?本地conf或遠程? – Anand

+0

我對這個例子也有類似的問題。顯然,主機名不會被視爲與實際IP相同。爲什麼是這樣?對此可以做些什麼?因爲你是對的,我寧願使用主機名。 – Stradigos

+0

如果我將遠程主機名設置爲機器的IP地址,那麼我會收到一個異常,說'無法綁定...'無法分配請求的地址。 –

1

在遠程演員類,你必須:

val system = ActorSystem("HelloRemoteSystem", config) 

確保在本地演員在使用actorSelection/actorFor您使用了同一個名字:

val remoteActor = context.actorSelection("akka.tcp://[email protected]:2553/user/RemoteActor")