Semantics of Topic Reader/Writer
Reader
- Streaming model: the server sends message batches over active partition sessions.
read({ limit, batchWindowMs, signal })— async iterator of batches;limit— max messages per iteration (no limit by default).batchWindowMs— max time to accumulate a batch before yielding; empty batch on an idle topic.signal— cancel waiting/reading.
- Commits:
commit(batch|msg)— acknowledge processing on the server. - Hooks:
onPartitionSessionStart(session, committedOffset, { start, end })— adjustreadOffset/commitOffset.onPartitionSessionStop(session, committedOffset)— finalize/commit.onCommittedOffset(session, committedOffset)— ack notifications.
Buffering:
- Internal buffer limited by
maxBufferBytes. codecMapcontrols payload decompression.
Resilience:
- Stream‑level transparent reconnect (exponential backoff + jitter); pending commits are re‑sent on the new partition session, so a
read()+commit()loop survives reconnects. - A running reader whose topic is dropped idles until the server closes the stale stream (~1 min), then transparently reconnects and resumes automatically if the topic exists again.
Writer
write(payload)— buffer a message; returnsvoid. The finalseqNoarrives viaflush()oronAck.flush()— send the buffer to the server; returns the last acknowledgedseqNo.onAck(seqNo, status)— write acknowledgement notifications.- Limits:
maxBufferBytes,maxInflightCount,flushIntervalMs. - Stream‑level transparent reconnect (exponential backoff + jitter); unbounded by default (retries forever, waiting for the server/topic), bounded by
recoveryWindowMswhen set.
Transactions
- TxReader: tracks read offsets and sends
updateOffsetsInTransactionon tx commit. - TxWriter: awaits
flushbefore commit (viatx.onCommit). usingis optional (both implementAsyncDisposable/Disposable); lifecycle is managed by transaction hooks.