配置Akka.Net远程处理,以使(windows)docker容器内的进程可以与本地主机上的进程进行通信

问题描述 投票:-1回答:1

我有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)。

[当两个进程都在同一台计算机上运行时,它们相互通信就很好。

[进程2在docker容器中运行时本身似乎正常运行(进程1-进程2通信除外)。

但是,我根本不清楚我需要在进程2 dockerfile,docker run命令,进程1 hocon和进程2 hocon中添加什么,以便当进程2在容器中运行时进程1仍然可以讲话。

[我想我需要在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 

或类似。

已经获得了我正在运行的容器内编辑app.hocon的IP,并重新启动了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
 }
}

enter image description here

我有2个Akka.Net进程通过远程相互通信。进程1具有以下app.hocon:akka {演员{提供者=提供者=远程}远程{dot-netty.tcp.port = 1111}}进程...

docker-for-windows akka.net
1个回答
0
投票

结果非常简单。

© www.soinside.com 2019 - 2024. All rights reserved.