【问题标题】:Akka remote configuration unnamed actorsAkka 远程配置无名演员
【发布时间】:2015-07-07 12:06:15
【问题描述】:

我是一名新手 Akka 开发人员,我刚刚开始使用远程处理。我总是看到这种类型的配置:

akka {

  actor {
    provider = "akka.remote.RemoteActorRefProvider"

    deployment {
      "/mainRepository/*" {
        remote = "akka.tcp://MqttRemote@127.0.0.1:2553"
      }
    }
  }

  remote {
    netty.tcp {
      hostname = "127.0.0.1"
    }
  }

  remote.netty.tcp.port = 2553

}

演员被命名的地方,例如“mainRepository”,但如果我想创建未命名的远程演员怎么办?我应该在配置中指定什么?或者我可以通过在请求新演员时不设置 ActorSystem 中的 name 参数来实现吗?

另外,“*”字符是什么意思?或者我在哪里可以了解有关远程配置的更多信息? (除了 akka.io)

【问题讨论】:

    标签: configuration akka akka-remote-actor


    【解决方案1】:

    这个配置的意思是,如果在路径/user/mainRepository/* 下创建了任何actor 实例(即绑定到名称/user/mainRepository 的actor 实例的任何子级),则不应将其部署到本地ActorSystem但应改为使用远程系统MqttRemote@127.0.0.1:2553 的远程守护程序将该参与者部署到该远程系统中。所以如果我做这样的事情:

    context.actorOf(Props[MyActor], "foo")
    

    其中context 是我的mainRepository 演员实例的ActorContext,那么那个孩子将被远程部署。

    * 是一个通配符,可让您更全面地了解远程部署的参与者。如果配置是这样的:

      "/mainRepository/foo" {
        remote = "akka.tcp://MqttRemote@127.0.0.1:2553"
      }
    

    然后只有绑定到名称foo 的子级将被远程部署。我的mainRepository 演员的任何其他孩子都将部署到本地ActorSystem

    因此,使用这种方法,使用通配符,您确实可以创建未命名的子代并远程部署它们,只要它们的父代正确命名并且该名称已配置(如本示例中所示)以远程部署它的子代。

    如果使用这种配置驱动的方法对您没有吸引力,您还可以通过编程方式远程部署参与者实例。看起来像这样:

    import akka.actor.{ Props, Deploy, Address, AddressFromURIString }
    import akka.remote.RemoteScope    
    
    val address = Address("akka.tcp", "RemoteSystem", "1.2.3.4", 1234)
    val ref = system.actorOf(Props[MyActor].
      withDeploy(Deploy(scope = RemoteScope(address))))
    

    在上面的代码中,MyActor 的一个实例将被部署在远程节点RemoteSystem@1.2.3.4:1234

    有关更多信息,您可以查阅远程处理文档here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-09
      • 2014-05-28
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      • 2015-03-27
      • 2020-10-26
      相关资源
      最近更新 更多