Honker.Stream (honker v0.1.4)

Copy Markdown

Append-only topic log with named-consumer offsets. Thin wrapper over honker_stream_* SQL functions.

{:ok, off1} = Honker.Stream.publish(db, "orders", %{id: 1})
{:ok, events} = Honker.Stream.read_since(db, "orders", 0, 100)
{:ok, true}  = Honker.Stream.save_offset(db, "billing", "orders", off1)

Summary

Functions

Current saved offset for consumer on topic, or 0 if unset.

Publish an event on topic. Returns {:ok, offset} — a monotonic per-topic offset assigned by the extension.

Publish inside an open transaction.

Read from the saved offset of consumer on topic. Does not advance the offset — call save_offset/4 after you've processed.

Read up to limit events from topic with offset strictly greater than offset. Returns {:ok, [%Honker.StreamEvent{}, ...]}.

Persist a consumer's offset. Monotonic: saving a lower offset than already stored is a no-op (returns {:ok, false}).

Save offset inside an open transaction.

Functions

get_offset(database, consumer, topic)

Current saved offset for consumer on topic, or 0 if unset.

publish(database, topic, payload, opts \\ [])

Publish an event on topic. Returns {:ok, offset} — a monotonic per-topic offset assigned by the extension.

Options:

  • :key — optional partition key (string) for per-key ordering downstream. Defaults to nil.

publish_tx(transaction, topic, payload, opts \\ [])

Publish inside an open transaction.

read_from_consumer(db, topic, consumer, limit)

Read from the saved offset of consumer on topic. Does not advance the offset — call save_offset/4 after you've processed.

read_since(database, topic, offset, limit)

Read up to limit events from topic with offset strictly greater than offset. Returns {:ok, [%Honker.StreamEvent{}, ...]}.

save_offset(database, consumer, topic, offset)

Persist a consumer's offset. Monotonic: saving a lower offset than already stored is a no-op (returns {:ok, false}).

save_offset_tx(transaction, consumer, topic, offset)

Save offset inside an open transaction.