我有2个Akka.Net进程通过远程相互通信。
进程1具有以下app.hocon:
akka{
actor{
provider = remote
}
remote{
dot-netty.tcp.port = 1111
}
}
进程2具有以下app.hocon:
akka{
actor{
provider = remote
}
remote{
dot-netty.tcp.port = 2222
dot-netty.tcp.hostname = "localhost"
}
}
请注意,由于两个进程都在本地主机上,因此配置非常简单。
流程1使用以下命令连接到流程2参与者:
Process1ActorSystem.ActorSelection($"akka.tcp://Process2ActorSystem@localhost:2222/user/someActor");
流程2在收到流程1的“ SubscribeMessage”后,将数据“告诉”流程1(Context.Sender.Tell)。
当两个进程都在同一台计算机上运行时,它们相互之间可以正常通信。
在docker容器中运行时,进程2本身似乎可以正常运行(进程1-<->进程2通信除外)。
但是,我根本不清楚我需要在进程2 dockerfile,docker run命令,进程1 hocon和进程2 hocon中放入什么,以便进程2在运行容器时仍可以进行对话。
我猜想我需要在Process 1 hocon和Process 2 hocon中获得这些值的某些子集的正确组合,并在dockerfile中获得正确的EXPOSE语句和/或在docker run中获得正确的端口映射。
Process 1 hocon:
"port" : "1111".
#"hostname": "???? or omit",
#"bind-hostname": "???? or omit",
#"bind-port": "???? or omit",
#"public-hostname": "???? or omit",
#"public-port": "???? or omit",
Process 2 hocon:
"port" : "2222".
#"hostname": "???? or omit",
#"bind-hostname": "???? or omit",
#"bind-port": "???? or omit",
#"public-hostname": "???? or omit",
#"public-port": "???? or omit",
Dockerfile:
EXPOSE 2222 #or omit?
Docker run:
docker run -p 2222:2222 mycontainer
任何指导表示赞赏。
更新:
我提高了调试日志级别,现在当进程1尝试发送消息时,我从进程2中看到了这一点。注意:容器的IP为172.22.87.66,这是进程1的地址。但是似乎因为进程2的主机名是0.0.0.0,所以它接收到该消息,但拒绝了它。
可能我可以通过将Process 2 hocon更改为主机名172.22.87.66来解决此问题,但每次运行容器时IP地址都会更改,因此不能成为整个解决方案。
[ERROR][3/7/2020 10:24:03 AM][Thread 0010][akka.tcp://[email protected]:8222/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FActorSystemRemote1%40host.docker.internal%3A8111-1/endpointWriter] Dropping message [Akka.Actor.ActorSelectionMessage] for non-local recipient [[akka.tcp://[email protected]:8222/]] arriving at [akka.tcp://[email protected]:8222] inbound addresses [akka.tcp://[email protected]:8222]
更新2
好的,现在我确实有两个过程可以通信,但这不是可行的长期设置。我连接到正在运行的容器,并做了一个ipconfig来获取其IP。我想我可以用
docker network inspect nat
或类似。
获得IP后,我在正在运行的容器中编辑app.hocon并重新启动Process2可执行文件。
然后从进程1中,我使用该IP寻址到进程2。
另外,进程1使用host.docker.internal的公用主机名,我认为它对于进程2能够解决它是必需的。
akka{
actor{
provider = remote
}
remote{
dot-netty.tcp.port = 8111,
dot-netty.tcp.hostname = 172.22.80.1
dot-netty.tcp.public-hostname=host.docker.internal
}
}
原来很简单。
akka{
actor{
provider = remote
}
remote{
dot-netty.tcp.port = 1111
}
}
Process 2 has the following app.hocon:
akka{
actor{
provider = remote
}
remote{
dot-netty.tcp.port = 2222
dot-netty.tcp.public-hostname = "localhost" //this was the key addition
}
}
码头工人运行-p 2222:2222 myimage
并且dockerfile中包含EXPOSE 2222。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句