liveBook · Manning

Group router

As explained in Akka in Action, Second Edition

A group router is an Akka router whose routees are created externally and discovered through receptionist registrations under a service key.

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

Figure 6.5 Actor hierarchies of pool and group routers
CH06_F05_Abraham2

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

Figure 6.7 Steps the consistent hashing router follows to decide which routee to select
CH06_F07_Abraham2

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

How Akka in Action, Second Edition covers it

How deep it goes
Explains creation, registration, routing strategies, and consistent-hash key mapping; notes that hash-selection steps are internal.
Examples
Uses cameras and photo processors for even distribution, then data enrichment and aggregation for consistent hashing.
What it assumes
Builds on actor creation, typed messages, ActorRef usage, and receptionist registration; introduces group-router setup directly.
What you can do after
Apply it via Akka Routers.group to route messages to registered actors while retaining independent routee lifecycle control.
How it connects
Connects ServiceKey and receptionist discovery with pool routers, round-robin routing, random routing, broadcasting, and consistent hashing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Akka in Action, Second Edition. The section links point to the parts of the book it draws on.