liveBook · Manning

At-most-once delivery

As explained in Akka in Action, Second Edition

An at-most-once delivery guarantee means each record is delivered zero or one time, so records may be lost but are not redelivered.

At-most-once delivery sends each record zero or one time. The sender does not wait for an acknowledgment, so a record may be lost but is not redelivered. section 3.2.1

The guarantee becomes visible in two practical cases:

  • Actor messages sent to dead letters receive only best-effort delivery; a stopped recipient cannot process them. section 3.2.1
  • Kafka production through Producer.plainSink writes records without the stronger commit or transactional guarantees provided by other sinks. section 14.5
  • A failed worker may produce no response, while a manager observes a timeout rather than a duplicate response. section 3.2.1

Producing records to Kafka

Create ProducerSettings with StringSerializer instances and a bootstrap server, wrap values in ProducerRecord objects, and run the stream with Producer.plainSink. A listener such as kcat can observe the records written to the topic. section 14.2.1

Listing 14.2 plainSink producing to Kafka from the KafkaSpec test
import org.apache.kafka.common.serialization.StringSerializer
import org.apache.kafka.clients.producer.ProducerRecord
 
class KafkaSpec ... {
  ...
 
  "a producer" should "write to Kafka" in {
 
    val config =
      system.settings.config.getConfig("akka.kafka.producer")            #1
 
    val topicDest =
      system.settings.config.getString("kafka.test.topic")               #2
 
    val producerSettings = ProducerSettings(                             #3
      config,                                                            #3
      new StringSerializer(),                                            #3
      new StringSerializer()).withBootstrapServers("127.0.0.1:9092")     #3
 
    val done: Future[Done] = Source(1 to 10)
      .map(_.toString)
      .map(elem => new ProducerRecord[String, String](topicDest, elem))  #4
      .runWith(Producer.plainSink(producerSettings))                     #5
 
    Await.ready(done, 3.second)
  }
  ...
}

The producer test shows the complete path from Kafka configuration and ProducerRecord construction to running a source with plainSink. section 14.2.1

How Akka in Action, Second Edition covers it

How deep it goes
Explains loss and non-redelivery through actor failures and implements Kafka production, while stopping short of delivery internals.
Examples
Demonstrates stopped actors, worker timeouts, Kafka ProducerRecord values, plainSink, kcat output, and records numbered one through ten.
What it assumes
Assumes basic actors, Kafka topics, ProducerRecord, producer settings, serializers, and stream sinks.
What you can do after
Apply it via Akka actors or Alpakka Kafka by sending messages once and selecting Producer.plainSink for topic production.
How it connects
Connects dead letters and timeouts with Kafka, at-least-once delivery, and effectively-once semantics.

Also explained in

Compare how 5 books explain at-most-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.