Difference between Actorref.tell and inbox.send in Akka

前端 未结 2 1688
深忆病人
深忆病人 2021-01-12 03:38

So i have started learning Akka and trying out the examples in typesafe. So the Hello Akka app has the following code :

    import akka.actor.{ ActorRef, Act         


        
2条回答
  •  终归单人心
    2021-01-12 04:41

    When you do the following you are dealing directly with an ActorRef

    greeter.tell(WhoToGreet("akka"), ActorRef.noSender)
    

    On the other hand, when you use an Inbox you are dealing something that is not exactly an actor but actor-like. One scenario where this is helpful is when you don't want to create your own actor but still want to interact with other actors asynchronously. Please see this

    An Inbox is an actor-like object which is interrogated from the outside. It contains an actor whose reference can be passed to other actors as usual and it can watch other actors’ lifecycle.

    The actor runs on the a threadpool (configured using a dispatcher). You can decide either by configuration or by putting in your code where which dispatcher that actor use for its execution.

提交回复
热议问题