Router
Este conteúdo não está disponível em sua língua ainda.
constRouter: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.
Type Declaration
Section titled “Type Declaration”broadcast()
Section titled “broadcast()”broadcast<
TMessage>(size,routee,routeeOptions?):ActorFactory<TMessage|Broadcast<TMessage>>
Type Parameters
Section titled “Type Parameters”TMessage
Section titled “TMessage”TMessage
Parameters
Section titled “Parameters”number
routee
Section titled “routee”ActorClassOrFactory<TMessage>
routeeOptions?
Section titled “routeeOptions?”ActorOptions<TMessage>
Returns
Section titled “Returns”ActorFactory<TMessage | Broadcast<TMessage>>
custom()
Section titled “custom()”custom<
TMessage>(size,routee,strategy,routeeOptions?):ActorFactory<TMessage|Broadcast<TMessage>>
Type Parameters
Section titled “Type Parameters”TMessage
Section titled “TMessage”TMessage
Parameters
Section titled “Parameters”number
routee
Section titled “routee”ActorClassOrFactory<TMessage>
strategy
Section titled “strategy”routeeOptions?
Section titled “routeeOptions?”ActorOptions<TMessage>
Returns
Section titled “Returns”ActorFactory<TMessage | Broadcast<TMessage>>
random()
Section titled “random()”random<
TMessage>(size,routee,routeeOptions?):ActorFactory<TMessage|Broadcast<TMessage>>
Type Parameters
Section titled “Type Parameters”TMessage
Section titled “TMessage”TMessage
Parameters
Section titled “Parameters”number
routee
Section titled “routee”ActorClassOrFactory<TMessage>
routeeOptions?
Section titled “routeeOptions?”ActorOptions<TMessage>
Returns
Section titled “Returns”ActorFactory<TMessage | Broadcast<TMessage>>
roundRobin()
Section titled “roundRobin()”roundRobin<
TMessage>(size,routee,routeeOptions?):ActorFactory<TMessage|Broadcast<TMessage>>
Type Parameters
Section titled “Type Parameters”TMessage
Section titled “TMessage”TMessage
Parameters
Section titled “Parameters”number
routee
Section titled “routee”ActorClassOrFactory<TMessage>
routeeOptions?
Section titled “routeeOptions?”ActorOptions<TMessage>
Returns
Section titled “Returns”ActorFactory<TMessage | Broadcast<TMessage>>
scatterGatherFirstCompleted()
Section titled “scatterGatherFirstCompleted()”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.
Type Parameters
Section titled “Type Parameters”TMessage
Section titled “TMessage”TMessage
Parameters
Section titled “Parameters”number
routee
Section titled “routee”ActorClassOrFactory<TMessage>
options?
Section titled “options?”routeeOptions?
Section titled “routeeOptions?”ActorOptions<TMessage>
Returns
Section titled “Returns”ActorFactory<TMessage>
smallestMailbox()
Section titled “smallestMailbox()”smallestMailbox<
TMessage>(size,routee,routeeOptions?):ActorFactory<TMessage|Broadcast<TMessage>>
Type Parameters
Section titled “Type Parameters”TMessage
Section titled “TMessage”TMessage
Parameters
Section titled “Parameters”number
routee
Section titled “routee”ActorClassOrFactory<TMessage>
routeeOptions?
Section titled “routeeOptions?”ActorOptions<TMessage>
Returns
Section titled “Returns”ActorFactory<TMessage | Broadcast<TMessage>>
