简体   繁体   English

Akka Persistence ActorSelection路径?

[英]Akka Persistence ActorSelection path?

I am trying to understand and use akka persistence. 我试图理解和使用akka持久性。 I am new into this EventSourcing world. 我是这个EventSourcing世界的新手。

I am trying to get an ActorRef to list some items, I am getting this "actor name is not unique" error; 我试图让ActorRef列出一些项目,但出现此“演员名称不是唯一的”错误; so I am trying to use this actorSelection method. 所以我试图使用这个actorSelection方法。

The problem is it asks for a path . 问题是它要求一条 Which path is that? 那是哪条路? How can I make sure I am using the correct path if I am using PlayFramework's Akka.system()? 如果我使用PlayFramework的Akka.system(),如何确保使用正确的路径?

Current code : 当前代码

def index = Action {
    val queryActor = Akka.system.actorOf(IssuesView.props, IssuesView.actorName)
    val inbox = Inbox.create(Akka.system)
    inbox.send(queryActor, IssuesView.GetAll)
    val issueSet = inbox.receive(1 seconds).asInstanceOf[IssueSet]
    Ok(views.html.index(issueSet.issues.toSeq))
}

Every Actor gets an address within the ActorSystem. 每个Actor都会在ActorSystem中获得一个地址。

ActorPaths are a representation of the Actor hierarchy. ActorPath是Actor层次结构的表示。 At the top are guardian actors like the guardian actor for all user actors named "user". 顶部是守护角色,例如所有名为“ user”的用户角色的守护角色。 It's path resembles akka://<system>/user . 它的路径类似于akka://<system>/user

An actor created with actorSystem.actorOf has the user guardian as supervisor: akka://<system>/user/$1 . 使用actorSystem.actorOf创建的actorSystem.actorOf具有用户监护人作为主管: akka://<system>/user/$1 If an actor name is provided then that name is used as node name. 如果提供了参与者名称,则将该名称用作节点名称。

system.acorOf(props, "Foo")
-> akka://<system>/user/Foo

All actor on the same hierarchy level MUST have unique names. 同一层次结构级别上的所有参与者必须具有唯一的名称。 Thus, if you get an error 因此,如果您遇到错误

actor name is not unique 演员名称不是唯一的

Then you already have an actor with the same name running on the same level you want to start the new one. 然后,您已经有一个具有相同名称的actor,该actor在您要启动新角色的同一级别上运行。

Actors started by another Actor (eg by Foo) with context.actorOf(props, "Bar") , are started one level below the actor that started them: akka://<system>/Foo/Bar . 由另一个具有context.actorOf(props, "Bar") Actor(例如Foo)启动的Actor在启动它们的actor的下一级启动: akka://<system>/Foo/Bar

When using ActorSelection you pass an anchor ref and a relative ActorPath . 使用ActorSelection时,您传递锚点ref和相对的ActorPath

Eg if you are in Foo and want to send a message to all child actors of Foo , you could use a wildcard to multicast the message: 例如,如果你是在Foo ,并希望将消息发送到所有儿童演员Foo ,你可以使用通配符来多播消息:

ActorSelection(self, "./*") ! message

Have a look at this part of the akka documentation 看看akka文档的这一部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM