Basic usage with Task semantics
Basic usage with Task semantics
import { EventLog } from "@anabranch/eventlog"; import { createKafka } from "@anabranch/eventlog-kafka"; const connector = createKafka({ brokers: ["localhost:9092"] }); const log = await EventLog.connect(connector).run(); const eventId = await log.append("users", { action: "created", userId: 123 }).run();
Consuming events as a stream with manual cursor commit
Consuming events as a stream with manual cursor commit
const connector = createKafka({ brokers: ["localhost:9092"], groupId: "processor-1" }); const log = await EventLog.connect(connector).run(); const { successes, errors } = await log .consume("users", "processor-1") .withConcurrency(5) .map(async (batch) => { for (const event of batch.events) { await processEvent(event.data); } await log.commit(batch.topic, batch.consumerGroup, batch.cursor).run(); }) .partition();
Event log wrapper with Task/Stream semantics for event-sourced systems.
-
append<T>(): Task<string, EventLogAppendFailed>topic: string,data: T,options?: AppendOptions
Append an event to a topic.
-
close(): Task<void, EventLogCloseFailed>
Close the event log connection.
-
commit(): Task<void, EventLogCommitCursorFailed>topic: string,consumerGroup: string,cursor: Cursor
Commit a cursor to mark progress for a consumer group.
-
connect<Cursor = string>(connector: EventLogConnector<Cursor>): Task<EventLog<Cursor>, EventLogConnectionFailed>
Connect to an event log via a connector.
-
consume<T>(): Channel<EventBatch<T, Cursor>, EventLogConsumeFailed>topic: string,consumerGroup: string,options?: ConsumeOptions<Cursor>
Consume events from a topic as a stream.
-
getCommittedCursor(): Task<Cursor | null, EventLogGetCursorFailed>topic: string,consumerGroup: string
Get the last committed cursor for a consumer group.
Error thrown when an append operation fails.
Error thrown when closing an event log connection fails.
Error thrown when committing a cursor fails.
Error thrown when a Kafka event log connection cannot be established.
Error thrown when consuming events fails.
Error thrown when getting a cursor fails.
Error thrown when getting an event fails.
Error thrown when listing events fails.
Creates a Kafka event log connector for production use.
Cursor type for Kafka, tracking position across partitions.
-
partitions: Record<number, string>
Mapping of partition number to offset string.
Configuration options for Kafka event log connector.
- admin: AdminConfig & { dummyMaxWaitTimeInMs?: number; }
-
consumer: Omit<ConsumerConfig, "groupId">
Kafka consumer configuration. Must include groupId.
-
onMalformedMessage: () => voidtopic: string,partition: number,offset: string,raw: string
Callback for handling malformed messages that cannot be parsed.
- producer: ProducerConfig