-1

I am new to AkKA/Actor. I need to create synchronized Parent actor and two or more asynchronized actors to call some Rest API. Please suggest what kind of pattern would be suitable i.e Tell or ask or inbox ?

zapping
  • 4,118
  • 6
  • 38
  • 56
yesPeeB
  • 1
  • 3

1 Answers1

1

Firstly, Akka does not recommend to create a blocking actor.

Coming to your question, As per Akka documentation (here),

tell (as documentation explain fire and forget) is used when you are not expecting a response from the target actor (async call). Example:

actorRef ! Message // async call

ask is used for both async and sync requests. When using ask with Await the current actor will wait for the response from the target actor and when ask is used with any of the future directives when it's an async operation. Example:

Await.result(actorRef ? Message, TimeOut(1 seconds)) // sync blocking call

onComplete(actorRef ? Message) {   // async non-blocking
  case Success(value) => complete(s"The result was $value")
  case Failure(ex)    => complete((InternalServerError, s"An error occurred: ${ex.getMessage}"))
}

References:

  • For Akka future Directives: here
  • Messages Sending methods: here
Prog_G
  • 1,539
  • 1
  • 8
  • 22