ActorSelection vs ActorRef

588 views
Skip to first unread message

Thomas Zimmer

unread,
Mar 9, 2015, 7:45:10 AM3/9/15
to akka...@googlegroups.com
Hi,

i got a more conceptual question. Is it more to common to emit a message to a ActorRef directly or use the ActorSelection instead? I am thinking of the following use-case: I got a "business logic" actor (A) and a "persistence logic" actor (B). So if i A wants to tell B to save a DB-Entry would I use a ActorRef or a ActorSelection? I can only guess that ActorSelection makes more sense as i could have more than one Actor to process the incoming work (lets say I have 3 instances of B running in a cluster). What is the the common pattern here?

Regards,
Thomas

Roland Kuhn

unread,
Mar 9, 2015, 8:16:52 AM3/9/15
to akka-user
Hi Thomas (& everyone else),

as a general rule of thumb always use ActorRef. The exceptions to this rule are
  • sending via the AtLeastOnceDelivery trait
  • initiating first contact between remote systems
In all other cases you’ll have ActorRefs readily available by virtue of setting up the system of actors in proper hierarchical fashion, passing references from parent to child and introducing actors by sending messages containing ActorRefs.

The first exception is due to at-least-once semantics being radically different from normal message sends, which means that ActorRef is not the right thing. The second exception is obviously due to not having an ActorRef before a reply is received from the remote system.

We should probably add this to the docs.

Regards,

Roland

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn


Roland Kuhn

unread,
Mar 9, 2015, 8:39:09 AM3/9/15
to akka-user

Vikram Kadi

unread,
Nov 11, 2015, 5:18:03 PM11/11/15
to Akka User List
Hi Roland,

I have a similar question, i do prefer ActorRef since i m able to assign the actor references on startup in the right hierarchy. 

But if the underlying actor crashes and then restarts(due to the right recovery strategy), then the ActorRef i hold is obsolete, and all messages to it would end up in dead letters. How can i be notified of the crash-restart so i can look up the right ActorRef of the newly restarted actor?

And all the actors are local for this particular question i have.

thanks,
Vikram

Patrik Nordwall

unread,
Nov 16, 2015, 9:21:47 AM11/16/15
to akka...@googlegroups.com
You can watch them.
/Patrik
--

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

Adam

unread,
Nov 16, 2015, 12:49:49 PM11/16/15
to Akka User List
But that is not really accurate, isn't it?

When restarted the ActorRef is still perfectly valid and you only need to watch actors in case you have reason to believe that they will be terminated. Also, messages don't get lost during the restart, because the mailbox isn't restarted (well messages can always get "lost". I mean the great majority of them)

Am I wrong?
If I am, my system has been magically staying up through all sorts of issues 😄

Patrik Nordwall

unread,
Nov 16, 2015, 3:44:23 PM11/16/15
to Akka User List
You are right, Adam. I missed that the question was about restarts.

/Patrik
Reply all
Reply to author
Forward
0 new messages