Using `actorSelection` is a look up and we all know that look ups should be 
avoided. In addition you can’t watch an `ActorSelection`. So you should clearly 
prefer the second variant.

Heiko

On 21 Jun 2014, at 20:08, Владимир Морозов <[email protected]> wrote:

> Hi all,
> 
> I have system design question about application with akka actors inside.
> 
> For example I have some Actors:
> 
> object EmailSender {
>   case class SendMessage(address: String, msg: String)
> }
> 
> class EmailSender(config: SMTPConfig) extends Actor with ActorLogging {
>   import EmailSender._
> 
>   def receive = {
>     case SendMessage(address, msg) =>
>       // some email send logic
>   }
> }
> 
> object Worker {
>   case object DoWork
> }
> 
> 
> //First variant
> class Worker extends Actor with ActorLogging {
>   import Worker._
> 
>   val emailActor = context.actorSelection("email-sender")
> 
>   def receive = {
>     case DoWork =>
>       //do some work and send email
>       emailActor ! EmailSender.SendMessage("[email protected]", "Work 
> complete")
>   }
> }
> 
> //Second variant
> class Worker(emailActor: ActorRef) extends Actor with ActorLogging {
>   import Worker._
> 
>   def receive = {
>     case DoWork =>
>       //do some work and send email
>       emailActor ! EmailSender.SendMessage("[email protected]", "Work 
> complete")
>   }
> }
> 
> What variant more 'true akka-style'?
> 
> PS: I read about cake pattern and cake I really liked, for obvious dependency 
> injections, but I don't figure out how use 'cake' in case of some dependent 
> actor`s.
> 
> -- 
> >>>>>>>>>> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.


--

Heiko Seeberger
Twitter: @hseeberger
Web: heikoseeberger.de




-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to