我找到的所有展示如何在 Akka.NET 中开始远程处理的演示都演示了最简单的用例,其中两个参与者使用本地主机在同一台机器上运行。
我试图让 Akka.NET actor 连接到远程机器,但遇到了一些困难。
代码极其简单:
客户端代码:
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();
}
当我在本地网络的另一台机器上运行 actor 进程时,我可以成功连接,但是当我将相同的简单示例分发到云 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 中可用的绑定(bind)主机名和绑定(bind)端口选项,因为这应该可以解决我认为我正在遭受的 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
最佳答案
几点说明:
在您的服务器配置中将其绑定(bind)到 0.0.0.0。 (hostname = 0.0.0.0) 这样套接字将绑定(bind)到所有本地端点,以防您的云托管环境使用多个网络端点。
然后使用设置 public-hostname = xxx.australiasoutheast.cloudapp.azure.com
。这样,服务器实例的主机名就与您在远程 URL 中使用的远程地址相同。
请注意,公共(public)主机名(和主机名,如果您不使用公共(public)主机名)必须是 DNS 可解析的。
关于c# - 让 Akka.NET 连接到远程地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47206602/