UNPKG

@ydbjs/topic

Version:

YDB Topics client for publish-subscribe messaging. Provides at-least-once delivery, exactly-once publishing, FIFO guarantees, and scalable message processing for unstructured data.

64 lines 2.47 kB
import type { Driver } from '@ydbjs/core'; import type { TopicWriterOptions } from './types.js'; export declare class TopicWriter implements AsyncDisposable { #private; constructor(driver: Driver, options: TopicWriterOptions); /** * Write a message to the topic * @param data Message payload * @param extra Optional message metadata */ write(data: Uint8Array, extra?: { seqNo?: bigint; createdAt?: Date; metadataItems?: Record<string, Uint8Array>; }): void; /** * Flush all buffered messages and wait for acknowledgment * @param signal Optional AbortSignal to cancel the flush operation * @returns Promise that resolves with the last acknowledged sequence number * * **Important:** After `flush()` completes, all messages written before this call * have been sent to the server with their final seqNo values. This is the safe way * to ensure seqNo accuracy for critical operations like deduplication or tracking. * * **Getting final seqNo for messages:** * After `flush()` completes, all seqNo values up to the returned `lastSeqNo` are final. * If you need to track individual messages, you can: * - Use the order of `write()` calls to determine final seqNo (sequential after flush) * - Use user-provided seqNo (always final, never recalculated) */ flush(signal?: AbortSignal): Promise<bigint>; /** * Get current writer statistics */ get stats(): { state: "ready" | "connecting" | "connected" | "errored" | "flushing" | "closing" | "idle" | "closed"; lastSeqNo: bigint; nextSeqNo: bigint; seqNoMode: "auto" | "manual" | null; bufferSize: bigint; bufferLength: number; inflightSize: bigint; inflightLength: number; isSessionInitialized: boolean; }; /** * Check if the writer session is initialized * @returns true if session is initialized, false otherwise */ get isSessionInitialized(): boolean; /** * Close the writer gracefully, waiting for all messages to be sent */ close(signal?: AbortSignal): Promise<void>; /** * Destroy the writer immediately without waiting */ destroy(reason?: Error): void; /** * AsyncDisposable implementation - graceful close with resource cleanup */ [Symbol.asyncDispose](): Promise<void>; } //# sourceMappingURL=writer.d.ts.map