Zum Inhalt springen
Deutsch

Router

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

const Router: object

Defined in: src/Router.ts:269

Helpers that return a ready-to-spawn actor factory for pool-style routers. Example: const pool = system.spawnAnonymous(Router.roundRobin(5, Worker)); pool.tell(‘work’); pool.tell(new Broadcast(‘announce’));

The routee is given the same way any actor is — the class itself, or a factory when it needs dependencies — with its own optional spawn options.

broadcast<TMessage>(size, routee, routeeOptions?): ActorFactory<TMessage | Broadcast<TMessage>>

TMessage

number

ActorClassOrFactory<TMessage>

ActorOptions<TMessage>

ActorFactory<TMessage | Broadcast<TMessage>>

custom<TMessage>(size, routee, strategy, routeeOptions?): ActorFactory<TMessage | Broadcast<TMessage>>

TMessage

number

ActorClassOrFactory<TMessage>

RoutingStrategy

ActorOptions<TMessage>

ActorFactory<TMessage | Broadcast<TMessage>>

random<TMessage>(size, routee, routeeOptions?): ActorFactory<TMessage | Broadcast<TMessage>>

TMessage

number

ActorClassOrFactory<TMessage>

ActorOptions<TMessage>

ActorFactory<TMessage | Broadcast<TMessage>>

roundRobin<TMessage>(size, routee, routeeOptions?): ActorFactory<TMessage | Broadcast<TMessage>>

TMessage

number

ActorClassOrFactory<TMessage>

ActorOptions<TMessage>

ActorFactory<TMessage | Broadcast<TMessage>>

scatterGatherFirstCompleted<TMessage>(size, routee, options?, routeeOptions?): ActorFactory<TMessage>

Send every message to all routees and answer the caller with the first reply — Akka’s ScatterGatherFirstCompletedPool, the hedged-request pattern:

const hedgeOptions = ScatterGatherOptions.create().withTimeoutMs(250);
const replicas = system.spawn(
Router.scatterGatherFirstCompleted(3, Replica, hedgeOptions),
'replicas',
);
const value = await replicas.ask<string>({ kind: 'read', key: 'a' });

Unlike the five strategy factories this one is reply-shaped: the router intercepts the routee replies to pick a winner, so it has to be asked (or tell’d with an explicit sender). It returns ActorFactory<TMessage> rather than ActorFactory<TMessage | Broadcast<TMessage>> — a Broadcast wrapper would mean nothing to a router that already broadcasts.

The scatter/gather settings take the third argument and per-routee spawn options move to the fourth, the same shape Router.custom already has: the two configure different things — how the router behaves, and how each routee is spawned — so folding them into one bag would make a single argument mean two scopes.

TMessage

number

ActorClassOrFactory<TMessage>

ScatterGatherOptions

ActorOptions<TMessage>

ActorFactory<TMessage>

smallestMailbox<TMessage>(size, routee, routeeOptions?): ActorFactory<TMessage | Broadcast<TMessage>>

TMessage

number

ActorClassOrFactory<TMessage>

ActorOptions<TMessage>

ActorFactory<TMessage | Broadcast<TMessage>>