PartitionedSource

Reads the partitions of a topic from an offset: the port a Kafka-sourced subscription reads through. The runtime assigns the partitions to nodes by its own leases and keeps the offsets in its checkpoint store, so a source has no consumer group, commits nothing and keeps no position: each read starts where it is told.

  • partitions are the topic's partitions, in order.

  • partitionOf is the partition a message keyed key lands in, as the TopicProducer of the same broker picks it: every message of a key is in that partition, so the records of one aggregate are found by re-scanning it.

  • offsets are what a partition holds now: where a subscription that starts from the end starts, and whether an offset is still retained.

  • read emits the messages of one partition with an offset at or after from, in offset order. A message that is no longer retained is skipped, so the first one emitted may be later than from; offsets may also have gaps within a partition. The flow does not complete: after the messages written so far it waits for new ones, until it is cancelled. Bounded by until, it emits those before until only and completes once it has passed them.

  • readAt reads the messages at offsets a caller already knows, such as those a ledger recorded, at once.

  • incarnation tells one creation of a topic from another of the same name.

Functions

Link copied to clipboard
open suspend fun incarnation(topic: String): String?

The incarnation of topic its partitions hold now: one name for everything the topic has held since it was created, and another once it is deleted and created again under the same name, whose offsets then name other messages; null when the source cannot tell any, the default. A source that tells them fails for a topic that does not exist, as partitions does, rather than answer null. A subscription keeps its offsets per incarnation, and asks when it joins the topic, when it places a read and when it reads the topic's partitions again; never per message.

Link copied to clipboard
abstract suspend fun offsets(topic: String, partition: Int): PartitionOffsets
Link copied to clipboard
abstract suspend fun partitionOf(topic: String, key: String): Int
Link copied to clipboard
abstract suspend fun partitions(topic: String): List<Int>
Link copied to clipboard
abstract fun read(topic: String, partition: Int, from: Long): Flow<SourceMessage>

open fun read(topic: String, partition: Int, from: Long, until: Long): Flow<SourceMessage>

The messages of partition from from to before until, then completes. By default the unbounded read up to the message at until - 1: a source whose partitions may end in a gap (such as transaction markers) overrides it.

Link copied to clipboard
open suspend fun readAt(topic: String, partition: Int, offsets: Collection<Long>): Map<Long, SourceMessage>

The messages of partition at offsets, which may be given in any order and more than once, keyed by their offsets. An offset the partition holds no message at is absent from the map: one no longer retained, one at or past its end, or one in a gap of its offsets. By default one bounded read per offset, after one offsets: a source whose reads each cost a connection of their own (Kafka) reads them through one.