Aller au contenu
Français

EntityRef

Ce contenu n’est pas encore disponible dans votre langue.

Defined in: src/cluster/sharding/EntityRef.ts:32

Location-transparent handle to a single sharded entity — the counterpart to the region ref, addressed by id rather than by whatever routing key your message type happens to carry.

Without it the region ref is the only handle sharding hands out, so every message has to embed its own entity id for extractEntityId to dig back out. An EntityRef wraps each message in a EntityEnvelope instead, which the region routes by the id in the envelope — the message type itself no longer has to know how it is routed.

Like ClusterSingletonProxy it extends ActorRef without being backed by an actor of its own: it is a thin forwarder onto the local region, which owns all the routing, buffering and cross-node machinery already. ask therefore works unchanged — the region forwards the caller’s sender to the entity, so a reply goes straight back without a detour.

The path is the entity’s path as it would be under this node’s region (/system/cluster/sharding/region-<type>/shard-<n>/entity-<id>). It identifies the entity — two refs for the same (typeName, entityId) are equals() — but it does not say which node currently hosts it; that can change on every rebalance, which is the entire point of holding the handle instead of a path.

TMessage = unknown

new EntityRef<TMessage>(region, typeName, entityId, numShards, systemName): EntityRef<TMessage>

Defined in: src/cluster/sharding/EntityRef.ts:35

ActorRef<unknown>

string

string

number

string

EntityRef<TMessage>

ActorRef.constructor

readonly entityId: string

Defined in: src/cluster/sharding/EntityRef.ts:38


readonly path: ActorPath

Defined in: src/cluster/sharding/EntityRef.ts:33

ActorRef.path


readonly typeName: string

Defined in: src/cluster/sharding/EntityRef.ts:37

ask<TResponse>(message, timeoutMs?): Promise<TResponse>

Defined in: src/ActorRef.ts:77

Request/response — send message and await the recipient’s reply. The framework synthesises a one-shot reply ref, injects it as both the sender slot and as message.replyTo, and resolves the returned promise with the first reply (or rejects with AskTimeoutError).

The caller never specifies replyTo on the message — the OmitReplyTo type subtracts it from the parameter type if the recipient declares it.

const value = await counter.ask<number>({ kind: 'get' });

TResponse = unknown

OmitReplyTo<TMessage>

number = DEFAULT_ASK_TIMEOUT_MS

Promise<TResponse>

ActorRef.ask


equals(other): boolean

Defined in: src/ActorRef.ts:104

ActorRef

boolean

ActorRef.equals


kill(): void

Defined in: src/ActorRef.ts:100

Kill this actor — raises ActorKilledError through the normal supervision path.

void

ActorRef.kill


send(message): void

Defined in: src/ActorRef.ts:64

Alias for tell — useful if you want to pipe something.

TMessage

void

ActorRef.send


stop(): void

Defined in: src/ActorRef.ts:97

Gracefully stop this actor after it drains its mailbox.

void

ActorRef.stop


tell(message, sender?): void

Defined in: src/cluster/sharding/EntityRef.ts:50

Send a message to this actor. sender is surfaced as context.sender in the recipient.

TMessage

ActorRef<unknown> | null

void

ActorRef.tell


toString(): string

Defined in: src/ActorRef.ts:102

string

ActorRef.toString