1

我正在学习如何从另一台机器调用远程演员。为了模拟两台不同的机器,我有一台主机,另一台是虚拟机 (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()

我首先执行了这个脚本,这是输出 在此处输入图像描述

这是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 上发现了一些有同样错误但无法解决的帖子。显然错误是因为在发送消息RemoteActor之前死亡。Local Actor同样在运行RemoteActor.fsx脚本后,如果我echoServer <! "Hello"RemoteActor终端中键入它,我也会收到同样的错误。

知道如何解决这个问题吗?任何帮助将不胜感激!谢谢!

4

1 回答 1

1

更改此行

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根目录下。

于 2020-09-18T01:04:03.307 回答