@mastra/core
Version:
91 lines • 4.48 kB
TypeScript
import { PubSub } from './pubsub.js';
import type { LeaseProvider, PubSubDeliveryMode } from './pubsub.js';
import type { Event, EventCallback, SubscribeOptions } from './types.js';
type UnixSocketPubSubOptions = {
maxRemoteClientQueuedBytes?: number;
/** Maximum outstanding client-to-broker frame bytes, including a single frame. */
maxPublisherQueuedBytes?: number;
/**
* Maximum size in bytes of a single inbound newline-delimited frame,
* including a partial frame that has not been terminated yet. A peer that
* exceeds it has its socket destroyed so one connection cannot grow process
* memory without bound.
*/
maxInboundFrameBytes?: number;
/**
* How long (ms) a client waits for the broker to acknowledge a
* subscribe/unsubscribe frame before proceeding best-effort. Brokers running
* an older protocol version never send `subscribed`/`unsubscribed` acks, so
* an unbounded wait would deadlock startup of any newer client that connects
* to them. On timeout the membership change is assumed applied — old brokers
* do honor the frames, they just never acknowledge them.
*/
membershipAckTimeoutMs?: number;
/**
* How often (ms) a broker checks that its socket path still leads to its own
* socket. If the file was deleted or replaced, the broker hands over and
* rejoins through normal election. Otherwise it would keep serving clients
* that nobody new can reach.
*/
brokerPathCheckIntervalMs?: number;
};
/**
* Max number of times a local subscriber callback may be redelivered after a
* nack. MUST be >= the consumer-side retry budget
* (`WorkflowEventProcessor.MAX_DELIVERY_ATTEMPTS`) — otherwise the transport
* gives up before the consumer can exhaust its budget and surface the terminal
* failure, which would leave the run silently hung.
*
* An invariant test in
* `packages/core/src/events/unix-socket-pubsub-redelivery-budget.test.ts`
* pins this ordering against the consumer constant so the two constants stay
* in sync as the consumer budget changes.
*/
export declare const MAX_LOCAL_REDELIVERIES = 6;
export declare class UnixSocketPubSub extends PubSub implements LeaseProvider {
#private;
readonly socketPath: string;
constructor(socketPath: string, options?: UnixSocketPubSubOptions);
get supportedModes(): ReadonlyArray<PubSubDeliveryMode>;
/**
* A nack redelivers only to the subscriber that nacked. The broker keeps no
* pending list across processes, so a message a dead process held is lost.
*/
get redeliversUnacked(): boolean;
get isBroker(): boolean;
/** Number of remote clients currently connected to this broker. Always 0 for non-broker instances. */
get remoteClientCount(): number;
/**
* Atomically acquires or renews a filesystem-backed lease shared by every
* UnixSocketPubSub instance in this socket directory.
*/
acquireLease(key: string, owner: string, ttlMs: number): Promise<{
acquired: boolean;
owner?: string;
}>;
/** Reads the current lease owner, reclaiming an expired or dead-process record. */
getLeaseOwner(key: string): Promise<string | undefined>;
/**
* Releases the lease only when `owner` still matches the stored owner. A
* release that started before close() runs to completion (close() awaits it):
* shutdown fires releases and closes right after, and an aborted release
* leaves the lease file behind until another process notices the holder died.
*/
releaseLease(key: string, owner: string): Promise<void>;
/** Renews the lease only when it remains live and owned by `owner`. */
renewLease(key: string, owner: string, ttlMs: number): Promise<boolean>;
/**
* Transfers a live lease without leaving the key unowned. The owner check and
* replacement are serialized by the same per-key filesystem mutation lock.
*/
transferLease(key: string, fromOwner: string, toOwner: string, ttlMs: number): Promise<boolean>;
publish(topic: string, event: Omit<Event, 'id' | 'createdAt'>, options?: {
localOnly?: boolean;
}): Promise<void>;
subscribe(topic: string, cb: EventCallback, options?: SubscribeOptions): Promise<void>;
unsubscribe(topic: string, cb: EventCallback): Promise<void>;
flush(): Promise<void>;
close(): Promise<void>;
}
export {};
//# sourceMappingURL=unix-socket-pubsub.d.ts.map