集群通讯 |如何获取包含 IP 和端口的 ActorPath

Cluster Communication | How to get an ActorPath including IP & Port

我们可以在与 Akka 示例代码相同的 JVM 上设置

"replyTo" via context.self.

final case class Greet(whom: String, replyTo: ActorRef[Greeted])

但是为了能够在另一个 JVM 上寻址一个 actor,我需要执行一个 ActorRef,例如: Actor[akka://shakto@172.31.19.110:25520/user/supervisor#1566727323]

为了获得这样的 ActorRef,我尝试了以下但没有成功:

context.self: Actor[akka://shakto/user/supervisor#-893416855] | -> Type: ActorRef -> no IP & Port
context.self.ref: Actor[akka://shakto/user/supervisor#-893416855] | -> Type: ActorRef -> no IP & Port
context.self.path: akka://shakto/user/supervisor | -> Wrong Type: ActorPath 
Cluster(context.system).selfMember.address: akka://shakto@172.31.17.16:25520 | -> Wrong Type: Address 
Cluster(context.system).selfMember: Member(address = akka://shakto@172.31.17.16:25520, status = Up) | -> Wrong Type: Member
Cluster(context.system).selfMember.uniqueAddress: UniqueAddress(akka://shakto@172.31.17.16:25520,7005817905428950198) | -> Wrong Type: UniqueAddress 
DistributedData(context.system).selfUniqueAddress: SelfUniqueAddress(UniqueAddress(akka://shakto@172.31.17.16:25520,7005817905428950198)) | -> Wrong Type: SelfUniqueAddress 

我怎样才能从 actor 内部获得一个完整的 ActorRef,包括 IP 和端口,然后我可以将其作为“replyTo”传递,以允许不同 JVM 上的不同节点使用这个 ActorRef 回复我在同一集群内?


你浏览过这个页面吗? https://doc.akka.io/docs/akka/current/typed/actor-discovery.html

与远程参与者通信的推荐方式是使用 akka 集群和 Receptionist。

您在使用 akka-remote 吗?