@pulzar/core
Version:
Next-generation Node.js framework for ultra-fast web applications with zero-reflection DI, GraphQL, WebSockets, events, and edge runtime support
131 lines • 3.49 kB
TypeScript
import { EventHandler, EventBusConfig, PublishOptions, SubscribeOptions, SubscriptionHandle, EventBusStats, DeadLetterQueue, EventSchema, EventMiddleware, RequestOptions, ReplyHandler } from "./types";
export declare class EventBus {
private adapter;
private config;
private dlq?;
private schemaRegistry?;
private middleware;
private connected;
private publishQueue;
private processingQueue;
private activeTasks;
private concurrencySemaphore;
private stats;
private subscriptions;
private replyHandlers;
constructor(config: Partial<EventBusConfig>);
/**
* Connect to the event system
*/
connect(): Promise<void>;
/**
* Disconnect from the event system
*/
disconnect(): Promise<void>;
/**
* Publish an event with schema validation and middleware
*/
publish<T = any>(subject: string, data: T, options?: PublishOptions): Promise<void>;
/**
* Subscribe to events with concurrency control
*/
subscribe<T = any>(subject: string, handler: EventHandler<T>, options?: SubscribeOptions): Promise<SubscriptionHandle>;
/**
* Request-Reply pattern
*/
request<TRequest = any, TResponse = any>(subject: string, data: TRequest, options?: RequestOptions): Promise<TResponse>;
/**
* Register reply handler
*/
reply<TRequest = any, TResponse = any>(subject: string, handler: ReplyHandler<TRequest, TResponse>, options?: SubscribeOptions): Promise<SubscriptionHandle>;
/**
* Register an event schema
*/
registerSchema<T>(schema: EventSchema<T>): Promise<void>;
/**
* Add middleware
*/
use(middleware: EventMiddleware): void;
/**
* Get event bus statistics
*/
getStats(): Promise<EventBusStats>;
/**
* Get DLQ instance
*/
getDLQ(): DeadLetterQueue | undefined;
/**
* Check if connected
*/
isConnected(): boolean;
/**
* Internal publish with validation and middleware
*/
private publishInternal;
/**
* Wrap handler with middleware, concurrency control, and error handling
*/
private wrapHandler;
/**
* Handle event with timeout and middleware
*/
private handleEvent;
/**
* Process publish queue with backpressure control
*/
private processPublishQueue;
/**
* Wait for all pending operations to complete
*/
private waitForPendingOperations;
/**
* Check if error should be sent to DLQ
*/
private shouldSendToDLQ;
/**
* Create adapter instance
*/
private createAdapter;
/**
* Create Redis adapter
*/
private createRedisAdapter;
/**
* Create NATS adapter
*/
private createNatsAdapter;
/**
* Create Kafka adapter
*/
private createKafkaAdapter;
/**
* Create AMQP adapter (placeholder)
*/
private createAmqpAdapter;
/**
* Create DLQ instance
*/
private createDLQ;
/**
* Create schema registry
*/
private createSchemaRegistry;
/**
* Merge configuration with defaults
*/
private mergeConfig;
/**
* Generate unique ID
*/
private generateId;
/**
* Get memory usage estimate
*/
private getMemoryUsage;
}
/**
* Create an event bus instance
*/
export declare function createEventBus(config?: Partial<EventBusConfig>): EventBus;
export default EventBus;
//# sourceMappingURL=bus.d.ts.map