Akka.NET:给远程 Actor 的死信

Akka.NET: Dead Letters to Remote Actor

我正在学习如何从不同的机器调用远程参与者。为了模拟两台不同的机器,我有一台主机,另一台是虚拟机 (VM)。网络适​​配器设置为 NAT 因为通过此设置我可以从 VM ping 主机(我读到它应该设置为 Bridge 但 ping 命令超时)。

Host IP: 172.16.104.242
VM IP: 10.0.2.15

除此之外,这是主机上 RemoteActor.fsx 的代码

#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()

我首先执行了这个脚本,这是输出

这是 VM

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))

这是这个的输出

现在 RemoteActor.fsx 抛出这个错误

我在 Stack Overflow 上发现了一些帖子也有同样的错误,但无法找出解决方法。显然错误是因为 RemoteActorLocal Actor 发送消息之前就死了。同样在 运行 RemoteActor.fsx 脚本之后,如果我在 RemoteActor 终端中输入 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-defined 演员都存在于 /user 演员根下。