简体   繁体   中英

Akka Persistence ActorSelection path?

I am trying to understand and use akka persistence. I am new into this EventSourcing world.

I am trying to get an ActorRef to list some items, I am getting this "actor name is not unique" error; so I am trying to use this actorSelection method.

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()?

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.

ActorPaths are a representation of the Actor hierarchy. At the top are guardian actors like the guardian actor for all user actors named "user". It's path resembles akka://<system>/user .

An actor created with actorSystem.actorOf has the user guardian as supervisor: 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.

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 .

When using ActorSelection you pass an anchor ref and a relative 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:

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

Have a look at this part of the akka documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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