scala - 有没有办法获取远程参与者的IP地址?

标签 scala ip actor akka remote-actors

我想知道是否有一种方法可以获得远程 akka actor 的 IP 地址,因为目前我正在使用广播 IP 地址来设置 actor 系统(这是唯一可行的方法)。我目前能够看到 actor 路径,但想确切地知道它驻留在哪台机器上,因为广播 IP 用于网络。

这是我为主要 Actor 编写的一些代码:

# remote actor config
remotecreation{ #user defined name for the configuration
    include "common"
    akka {
            actor{
                    deployment{
                            /remoteActor{   #Specifically has to be the name of the remote actor
                                    router = "round-robin"
                                    nr-of-instances = 10
                                    target {
                                            nodes = ["akka://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3664535b59425375445357425f5958760701041807011807060618040504" rel="noreferrer noopener nofollow">[email protected]</a>:2554", "akka://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d082b5bdbfa4b593a2b5b1a4b9bfbe90e1e7e2fee1e7fee1e0e0fee2e2e4" rel="noreferrer noopener nofollow">[email protected]</a>:2554"]
                                    }
                            }
                    }
            }
    remote.netty.port = 2554
    }

    remote{
            log-received-messages = on
            log-sent-messages = on
    }
}

这是主定义:

class Master(goodies: AuthNetActorObject) extends Actor {

var start: Long = _ // helps measure the calculation time

def receive = {
case "start" => {
  System.out.println("Master Started!")
  System.out.println("The master is at: " + self.path.toString())
...
        }
    }
}

这是我初始化并敲击 Actor 的地方:

object Payment extends Controller {
    var goodies: AuthNetActorObject = null
    val system = ActorSystem("RemoteCreation",ConfigFactory.load.getConfig("remotecreation"))
    ...
    val master = system.actorOf(Props(new Master(actorObject)))
    master ! "start"
    ...
}

最佳答案

使用actorRef.path.address.host

关于scala - 有没有办法获取远程参与者的IP地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12308552/

相关文章:

Scala 参与者和共享状态

scala - 给定一个范围,在Scala中获取该范围内的所有日期

php - 在 PHP 应用程序的 cURL 中强制使用 IPv4

java - "localhost"与 127.0.0.1 java

java - Akka actor resizer 没有创建实例

scala - 如何正确使用 Akka-TestKit TestProbe?

scala - Spark 斯卡拉 : Filter RDD if the record of the RDD doesn't exist in another RDD

android - Scala + Android 集成开发环境

go - 在 GO 中获取传入的 TTL

scala - Clojure 的代理与 Scala 的 Actor 相比如何?