A group router forwards messages to routees that are created outside the router. Each routee registers with the Akka receptionist under a shared ServiceKey; the router is created from that key and discovers the available routees. This separates routing from routee lifecycle management: routees may belong to any actor hierarchy, as long as they are running and registered. section 6.3 section 6.3.3
Unlike pool routees, group routees are not children of the router. Their creators control where they are instantiated and how their lifecycles are managed. section 6.3
Use a group router when routees already exist or must be controlled independently of routing:
- Define a ServiceKey for the routee message type and register every routee with the receptionist. section 6.3.3
- Create the router with Routers.group(serviceKey), then spawn it and send routee messages to its ActorRef. section 6.3.3
- Wait for at least one registration before expecting a message to reach a routee. section 6.3.3
- Choose a routing strategy. Group routers default to random routing, while round-robin gives each routee a turn before repeating. section 6.3.3 section 6.5
Camera and photo processors
A camera sends photo URLs to a group router built from the photo-processor ServiceKey. Independently created photo processors register under that key. With round-robin routing, successive photos are distributed evenly among registered processors; the router needs no configured routee count because registrations define membership. section 6.3.3
Consistent hashing is useful when related messages must reach the same routee while routees register or deregister. Supply a mapping from each message to a stable String key, such as an ID. Messages with the same key can then be routed to the same aggregator, allowing separately processed parts to be joined correctly. section 6.3.4 section 6.5
The routing path turns a stable message key into a hash and then selects a routee. These selection steps are internal; callers provide the key-extraction mapping. section 6.3.4
