Akka provides routing functionality. This is useful from a business point of view because you can route to the right Actor in the sense of business logic and behavior. For architecture, we can use this as load balancing and route messages to more Actors to achieve fault tolerance and scalability.
Akka has several options for routing, which are as follows:
RoundRobin: This is a random logic to every different Actor on the pool.
SmallestMailbox: This sends the message to the Actor with fewer messages.
Consistent Hashing: This partitions the Actors per hash ID.
ScatterGather: This sends message to all actors, and the first to reply wins.
TailChopping: This sends to a route randomly, and if a reply doesn't come back in a second, it chooses a new route and sends again, and so on.
Let's see the following code in practice:
import akka.actor._ import akka.routing.RoundRobinPool class ActorUpperCasePrinter extends Actor { def receive = { ...