我想要两个参与者进行交流。我在本地机器上有一个本地系统(客户端(,在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
0
testServer.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上的服务器中得到以下错误。
[信息][09/25/2020 19:20:07][线程0001][远程处理(akka://RemoteSystem)]正在启动远程处理[信息][09/25/2020 19:20:08][线程0001][远程处理(akka://RemoteSystem)]远程处理已启动;听地址:[阿卡。tcp://RemoteSystem@0.0.0.0:2552][信息][09/25/2020 19:20:08][线程0001][远程处理(akka://RemoteSystem)]Remoting现在监听地址:[akka。tcp://RemoteSystem@0.0.0.0:2552][akka://RemoteSystem/user/remoteActor#1987516675][错误][09/25/2020 19:20:23][Thread 0007][akka。tcp://RemoteSystem@0.0.0.0:2552/system/endpointManager/releaseEndpointWriter akka.tcp%3A%2F%2FSystem%400.0.0.0%3A2552-1/endpointWriter]正在删除非本地收件人[[akka.Actor.ActorSelectionMessage]的消息。tcp://RemoteSystem@A.B.C.D:2552/]]到达[阿卡。tcp://RemoteSystem@A.B.C.D:2552]入站地址[akka。tcp://RemoteSystem@0.0.0.0:2552]
运行客户端sie时的输出[信息][9/25/2020下午7:20:21][线程0001][远程处理(akka://System)]正在启动远程处理[信息][9/25/2020下午7:20:22][线程0001][远程处理(akka://System)]远程处理已启动;听地址:[阿卡。tcp://System@0.0.0.0:2552][信息][9/25/2020下午7:20:22][线程0001][远程处理(akka://System)]Remoting现在监听地址:[akka。tcp://System@0.0.0.0:2552]演员选举[主播(akka。tcp://RemoteSystem@A.B.C.D:2552/(,路径(/user/remoteActor(]
然后我搜索了很多这个错误,并在服务器上的配置文件中尝试了以下选项public hostname=localhost,bind hostname="A1.B1.C1.D1"其中"A1.B1.C1.D1"是EC2实例的私有IP地址,绑定端口=2552
可能是什么错误?你知道怎么修吗?感谢
我猜测这是由于涉及NAT。你需要告诉Akka你的外部/内部主机名是什么:
https://doc.akka.io/docs/akka/current/remoting.html#akka-后集装箱
如果涉及2个NAT级别,则可能需要一些额外的跟踪和错误。