liveBook · Manning

CommittableOffset

As explained in Akka in Action, Second Edition

CommittableOffset is an Alpakka Kafka handle representing a consumed record position that can be committed.

CommittableOffset is the Kafka position attached to a consumed record. Carry it through the stream and commit it only after processing succeeds to obtain at-least-once delivery. section 14.1.4

Commit a consumed record

A committable source emits CommittableMessage values. Process the record, then map the message to msg.committableOffset and pass those offsets to Committer.flow. The flow accepts Committable values and produces Done. section 14.1.4

import akka.kafka.scaladsl.Committer
import akka.kafka.scaladsl.Consumer.DrainingControl
import akka.kafka.CommitterSettings
import akka.kafka.ConsumerMessage.CommittableMessage
 
object ConsumerCommittableSource {
  ...
  val drainingControl: DrainingControl[_] =
    Consumer
      .committableSource(                                           #1
        consumerSettings,
        Subscriptions.topics("test2"))
      .map { msg: CommittableMessage[String, String] =>             #1
        println(
          s"${msg.record.key} => ${msg.record.value.toUpperCase}")
        msg.committableOffset                                       #2
      }
      .via(Committer.flow(committerSettings.withMaxBatch(100)))     #3
      .toMat(Sink.seq)(DrainingControl.apply)                       #4
      .run()
  ...
}

This complete pipeline shows record processing, CommittableOffset extraction, batched committing, and draining during shutdown. section 14.1.4

Use the offset in several operational patterns:

  • Commit offsets individually for a simple pipeline, or batch them with maximum batch and interval limits; defaults are 1,000 messages and 10 seconds. section 14.1.4
  • Tune asynchronous commit parallelism with maxParallelism; the default is 100. section 14.1.4
  • Preserve the offset as passThrough in ProducerMessage.single when consuming from one Kafka topic and producing to another through committableSink. section 14.2.2
  • Drain the stream before shutdown so consumed messages still in flight can finish processing and committing. section 14.1.4

How Akka in Action, Second Edition covers it

How deep it goes
Explains extraction, individual and batched commits, commit settings, downstream pass-through, and draining, without detailing Kafka offset internals.
Examples
Demonstrates uppercase record processing, batched commits, draining control, and reading from one Kafka topic while writing to another.
What it assumes
Assumes familiarity with Kafka consumers and Akka Streams stages while introducing committable messages, offsets, committers, and draining.
What you can do after
Builds Kafka streams that commit processed records individually, in batches, or alongside produced records.
How it connects
Connects CommittableMessage, committableSource, Committer.flow, committableSink, ProducerMessage, and at-least-once delivery.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Akka in Action, Second Edition. The section links point to the parts of the book it draws on.