我想要两个演员交流。我在本地机器上有一个本地系统(客户机),在EC2上有一个远程参与者(服务器)。但是我无法从客户端系统向远程参与者发送消息。
testClient.fs
#if INTERACTIVE
#time "on"
#r "nuget: Akka.FSharp"
#r "nuget: Akka.TestKit"
#endif
open System
open Akka.Actor
open Akka.Configuration
open Akka.FSharp
open System.Collections.Generic
let configuration =
ConfigurationFactory.ParseString(
@"akka {
actor {
provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
}
remote {
transport = ""akka.remote.netty.NettyRemoteTransport""
netty {
hostname = localhost
port = 0
}
}
}")
let system = ActorSystem.Create("System", configuration)
[<EntryPoint>]
let main args =
let remoteClient = system.ActorSelection(
"akka.tcp://RemoteSystem@A.B.C.D:2552/user/remoteActor")
printfn "%A" remoteClient
remoteClient <! "message from client"
Console.ReadLine() |> ignore
0testServer.fs
#if INTERACTIVE
#time "on"
#r "nuget: Akka.FSharp"
#r "nuget: Akka.TestKit"
#endif
open System
open Akka.Actor
open Akka.Configuration
open Akka.FSharp
open System.Collections.Generic
let helper msg = printfn "hello from server : %A" msg
let configuration =
ConfigurationFactory.ParseString(
@"akka {
actor {
provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
}
remote {
transport = ""akka.remote.netty.NettyRemoteTransport""
netty {
hostname = ""A.B.C.D""
port = 2552
}
}
}")
let remoteSystem = ActorSystem.Create("RemoteSystem", configuration)
let createActor (f : 'a -> unit) = actorOf f
[<EntryPoint>]
let main args =
let remoteActor = createActor helper |> spawn remoteSystem "remoteActor"
Console.ReadLine() |> ignore
0首先,当我启动我的服务器和运行客户机时,它会依次查找远程参与者并发送一条消息。然后我在EC2上的服务器上得到了以下错误。
INFOThread 0001启动远程处理INFOThread 0001远程处理已启动;监听地址: akka.tcp://RemoteSystem@0.0.0.0:255209/25/2020 19:20:08远程处理(akka://RemoteSystem)远程处理现在监听地址: akka.tcp://RemoteSystem@0.0.0.0:2552 RemoteSystem 0007正在删除非本地收件人的邮件Akka.Actor.ActorSelectionMessage [ akka.tcp://RemoteSystem@A.B.C.D:2552 /]到达akka.tcp://RemoteSystem@A.B.C.D:2552入站地址akka.tcp://RemoteSystem@0.0.0.0:2552
远程处理现在侦听地址:akka.tcp:// INFOThread @0.0.0.0:25529/25/ INFOThread 7:20:22 PMremoting (akka://System) remoting现在侦听地址: akka.tcp://System@0.0.0.0:2552 ActorSelectionAnchor(akka.tcp://RemoteSystem@A.B.C.D:2552/),Path(/INFOThread/INFOThread)
然后我搜索了很多次这个错误,并在服务器上的配置文件中尝试了以下选项: public-hostname = localhost,bind-hostname = ""A1.B1.C1.D1"“其中""A1.B1.C1.D1"”是EC2实例的私有IP地址,bind-port = 2552
可能的错误是什么?有没有办法解决这个问题?谢谢
发布于 2020-09-28 00:47:43
我的猜测是,这是由于NAT的参与。你需要告诉Akka你的外部/内部主机名是什么:
https://doc.akka.io/docs/akka/current/remoting.html#akka-behind-nat-or-in-a-docker-container
如果涉及2个NAT级别,则可能需要一些额外的试错。
https://stackoverflow.com/questions/64070431
复制相似问题