I started to learn Akka, and in many official examples I see that it is request-responseimplemented using the template tell. That is, after the employee has done his work, he sends the result as a new message back to the sender. For example, in this, the official Pi approximation guide showed how to develop an application in which a wizard sends some work to employees and then expects results as another message.
Master Code:
def receive = {
case Calculate ⇒
for (i ← 0 until nrOfMessages) workerRouter ! Work(i * nrOfElements, nrOfElements)
case Result(value) ⇒
pi += value
nrOfResults += 1
if (nrOfResults == nrOfMessages) {
listener ! PiApproximation(pi, duration = (System.currentTimeMillis - start).millis)
context.stop(self)
}
}
Work code:
def receive = {
case Work(start, nrOfElements) ⇒
sender ! Result(calculatePiFor(start, nrOfElements))
}
But I wonder why this example did not use a query template? What is wrong with using the query template here?
, : - ?
PoisonPill ?- -
Broadcast(PoisonPill)? - ?