我发现的所有演示如何开始在 Akka.NET 中进行远程处理都展示了两个参与者使用 localhost 在同一台机器上运行的最简单的用例。
我试图让 Akka.NET 演员连接到远程机器并遇到了一些困难。
代码非常简单:
客户代码:
var config = ConfigurationFactory.ParseString(@"
akka {
log-config-on-start = on
stdout-loglevel = DEBUG
loglevel = DEBUG
actor {
provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
debug {
receive = on
autoreceive = on
lifecycle = on
event-stream = on
unhandled = on
}
deployment {
/remoteactor {
router = round-robin-pool
nr-of-instances = 5
remote = ""akka.tcp://system2@xxx.australiasoutheast.cloudapp.azure.com:666""
}
}
}
remote {
dot-netty.tcp {
port = 0
hostname = localhost
}
}
}
");
using (var system = ActorSystem.Create("system1", config))
{
Console.ReadLine();
}
服务器代码:
var config = ConfigurationFactory.ParseString(@"
akka {
log-config-on-start = on
stdout-loglevel = DEBUG
loglevel = DEBUG
actor {
provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
debug {
receive = on
autoreceive = on
lifecycle = on
event-stream = on
unhandled = on
}
}
remote {
dot-netty.tcp {
transport-protocol = tcp
port = 666
hostname = ""10.0.0.4"" //This is the local IP address
}
}
}
");
using (ActorSystem.Create("system2", config))
{
Console.ReadLine();
}
当我在本地网络上的另一台机器上运行参与者进程时,我可以成功连接,但是当我将相同的简单示例分发到云 VM 上时,我收到以下错误:
[ERROR][11/9/2017 3:58:45 PM][Thread 0008][[akka://system2/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2Fsystem1%40localhost%3A28456-1/endpointWriter#1657012126]] Dropping message [Akka.Remote.DaemonMsgCreate] for non-local recipient [[akka.tcp://system2@xxx.australiasoutheast.cloudapp.azure.com:666/remote]] arriving at [akka.tcp://system2@xxx.australiasoutheast.cloudapp.azure.com:666] inbound addresses [akka.tcp://system2@10.0.0.4:666]
Cause: Unknown
我也尝试过使用“127.0.0.1”,但这似乎在本地或网络上都不起作用。
任何人都可以就我可能做错的事情提供任何意见吗?
更新:
我尝试使用 Akka.NET 中可用的绑定主机名和绑定端口选项,因为这应该可以解决我认为我正在遭受的 NAT 问题。不幸的是,这似乎也不起作用,我尝试了各种配置选项,例如使用主机名和 IP 地址,如下所示:
remote {
dot-netty.tcp {
port = 666
hostname = "13.73.xx.xx"
bind-port = 666
bind-hostname = "0.0.0.0"
}
}
尝试上述配置时收到的错误消息是:
[ERROR][11/12/2017 5:19:58 AM][Thread 0003][Akka.Remote.Transport.DotNetty.TcpTransport] Failed to bind to 13.73.xx.xx:666; shutting down DotNetty transport.
Cause: System.AggregateException: One or more errors occurred. ---> System.Net.Sockets.SocketException: The requested address is not valid in its context