问题描述
我正在学习如何从其他机器呼叫远程角色。为了模拟两台不同的计算机,我有一台主机,另一台是虚拟机(VM)。网络适配器设置为reduce
,因为通过此设置,我可以从VM对主机进行ping操作(我读到应将其设置为Bridge,但ping命令超时)。
NAT
此外,这是主机上Host IP: 172.16.104.242
VM IP: 10.0.2.15
的代码
RemoteActor.fsx
我首先执行了此脚本,这是输出
这是VM上#r "nuget: Akka.FSharp"
#r "nuget: Akka.Remote"
open System
open Akka.Actor
open Akka.Configuration
open Akka.FSharp
let config =
Configuration.parse
@"akka {
actor.provider = ""Akka.Remote.RemoteActorRefProvider,Akka.Remote""
remote.helios.tcp {
hostname = 172.16.104.242
port = 9001
}
}"
let system = System.create "RemoteFSharp" config
let echoServer =
spawn system "EchoServer"
<| fun mailBox ->
let rec loop() =
actor {
let! message = mailBox.Receive()
let sender = mailBox.Sender()
printfn "echoServer called"
match Box message with
| :? string ->
sender <! sprintf "Echo: %s" message
return! loop()
| _ -> failwith "UnkNown message"
}
loop()
的代码
LocalActor.fsx
这是此的输出
现在#r "nuget: Akka.FSharp"
#r "nuget: Akka.Remote"
open System
open Akka.Actor
open Akka.Configuration
open Akka.FSharp
let configuration =
ConfigurationFactory.ParseString(
@"akka {
actor {
provider = ""Akka.Remote.RemoteActorRefProvider,Akka.Remote""
deployment {
/remoteecho {
remote = ""akka.tcp://RemoteFSharp@172.16.104.242:9001""
}
}
}
remote {
helios.tcp {
port = 0
hostname = 10.0.2.15
}
}
}")
let system = ActorSystem.Create("RemoteFSharp",configuration)
let echoClient = system.ActorSelection("akka.tcp://RemoteFSharp@172.16.104.242:9001/EchoServer")
let task = echoClient <? "F#!"
let response = Async.RunSynchronously (task,1000)
printfn "Reply from remote %s" (string(response))
会引发此错误
我在Stack Overflow上发现了几处同样的错误,但找不到解决方法。显然是因为RemoteActor.fsx
在RemoteActor
发送消息之前死亡。同样,如果我在Local Actor
终端中键入此RemoteActor.fsx
,则在运行echoServer <! "Hello"
脚本之后,也会遇到相同的错误。
有人知道如何解决此问题吗?任何帮助将不胜感激!谢谢!
解决方法
更改此行
let echoClient = system.ActorSelection("akka.tcp://RemoteFSharp@172.16.104.242:9001/EchoServer")
收件人
let echoClient = system.ActorSelection("akka.tcp://RemoteFSharp@172.16.104.242:9001/user/EchoServer")
所有用户定义的参与者都存在于/user
参与者根下。