UNPKG

@stalkchain/grpc-pool

Version:

High-availability gRPC connection pooling module with active-active configuration, deduplication, and stale connection detection

88 lines 2.7 kB
/** * lib/pool.ts - Main gRPC pool manager * * Manages connections to 3 gRPC endpoints simultaneously and routes * transaction data from all of them. Handles all stream management internally, * emits processed messages to the user, and monitors for stale connections. * * @module lib/pool * @author StalkChain Team * @version 1.1.0 */ import { EventEmitter } from 'events'; import { PoolConfig, PoolOptions } from '../types'; /** * Main pool manager for multiple gRPC connections * * This class extends EventEmitter and handles all the complexity of managing * multiple gRPC streams internally. Users simply listen for 'message-processed' * events to receive transaction data. Includes automatic stale detection. */ export declare class GrpcPool extends EventEmitter { private config; private options; private clients; private connected; private pingInterval; private staleCheckInterval; private currentSubscription; private deduplicationService; private endpointStates; constructor(config: PoolConfig, options?: PoolOptions); /** * Connect to all endpoints in the pool and set up internal stream management */ connect(): Promise<void>; /** * Set up internal stream listeners for all connected clients */ private setupInternalStreams; /** * Check pool connection status and emit connected/disconnected events */ private checkPoolConnectionStatus; /** * Start automatic ping interval for connection health */ private startPingInterval; /** * Start stale connection detection monitoring */ private startStaleDetection; /** * Check all clients for stale connections and force reconnect if needed */ private checkForStaleConnections; /** * Subscribe to transactions using the simplified API * * This method handles all the internal stream setup and subscription management. * Users just need to call this once and listen for 'message-processed' events. */ subscribe(subscribeRequest: any): Promise<void>; /** * Send ping to all endpoints that support it (internal method) */ private pingAllEndpoints; /** * Close all connections and clean up resources */ close(): Promise<void>; /** * Get connection status for monitoring */ getStatus(): { endpoint: string; connected: boolean; timeSinceLastMessage?: number; }[]; /** * Get deduplication statistics for monitoring */ getDeduplicationStats(): { size: number; maxSize: number; ttlMs: number; }; } //# sourceMappingURL=pool.d.ts.map