Chapter 9. Routing messages
In this chapter
- Using the enterprise integration router pattern
- Scaling with Akka routers
- Building a state-based router with become/unbecome
In the previous chapter we looked at enterprise integration patterns as a way to connect actors to solve a wide range of problems. Yet all those approaches involved processing incoming messages in the same way. But often, you need to handle messages differently.
Routers are essential when you want to scale up or out. For example, when you want to scale up, you need multiple instances of the same task, and routers will decide which instance will process the received message. We’ll start this chapter by describing the enterprise router pattern and examine the three reasons for using routing to control message flow:
- Message content
We’ll then show you how to create routing processes for each of these patterns.
If performance or scaling is why you need to turn to a routing solution, you should use Akka’s built-in routers, because they’re optimized. Concerns with a message’s content or state, on the other hand, will point you to using normal actors.