interface EventClient
Core interface for event streaming clients in Eventicle.
EventClient provides the fundamental operations for working with event streams: publishing events, subscribing to streams, and replaying historical events. Different implementations support various backends like Kafka, Redis, or in-memory storage for development and testing.
Stream Types: - *\*Hot Streams\**: Only new events (live subscription) - \**Cold Streams\**: Historical events from the beginning - \**Cold-Hot Streams\*\*: Historical events followed by live subscription
Properties
coldHotStream
Play from persisted storage the continue from in memory
coldHotStream: (config: {
parallelEventCount?: number;
rawEvents: true;
stream: string | string[];
groupId: string;
handler: (event: EncodedEvent) => Promise<void>;
onError: (error: any) => void;
} | {
parallelEventCount?: number;
rawEvents: false;
stream: string | string[];
groupId: string;
handler: (event: EventicleEvent) => Promise<void>;
onError: (error: any) => void;
} | {
parallelEventCount?: number;
stream: string | string[];
groupId: string;
handler: (event: EventicleEvent) => Promise<void>;
onError: (error: any) => void;
}) => Promise<EventSubscriptionControl>;
coldStream
Replays historical events from the beginning of a stream.
Cold streams process all existing events in the stream from the start, then complete. This is useful for building projections, migrating data, or analyzing historical event patterns.
coldStream: (config: {
stream: string;
parallelEventCount?: number;
handler: (event: EventicleEvent) => Promise<void>;
onError: (error: any) => void;
onDone: () => void;
}) => Promise<EventSubscriptionControl>;
emit
Publishes events to the specified stream.
Events are processed atomically and will be available to subscribers after successful emission. The method supports both domain events (EventicleEvent) and pre-encoded events (EncodedEvent).
emit: (event: EventicleEvent[] | EncodedEvent[], stream: string) => Promise<void>;
hotRawStream
Only play hot data.
hotRawStream: (config: {
parallelEventCount?: number;
stream: string | string[];
groupId: string;
handler: (event: EncodedEvent) => Promise<void>;
onError: (error: any) => void;
deleteConsumerGroupOnClose?: boolean;
}) => Promise<EventSubscriptionControl>;
hotStream
Subscribes to live events from one or more streams.
Hot streams only receive new events published after the subscription is established. Multiple subscribers with the same groupId will share the event processing load (consumer group pattern).
hotStream: (config: {
parallelEventCount?: number;
stream: string | string[];
groupId: string;
handler: (event: EventicleEvent) => Promise<void>;
onError: (error: any) => void;
deleteConsumerGroupOnClose?: boolean;
}) => Promise<EventSubscriptionControl>;