liveBook · Manning

Producer setting

As explained in Akka in Action, Second Edition

producerSettings is an Akka Kafka configuration object or builder describing producer connection and behavior settings.

A producer setting describes how an Akka Kafka producer connects and encodes records. It supplies Kafka configuration, serializers, and usually the bootstrap server, then feeds producer APIs such as plainSink or SendProducer. section 14.2.1 section 15.1.2

Configure producer settings according to the publishing context:

  • Build ProducerSettings from the akka.kafka.producer configuration and provide serializers for the record key and value. section 14.2.1
  • Set the Kafka bootstrap server explicitly when the connection endpoint is not taken from the remaining configuration. section 14.2.1
  • Use string serializers for text records, or combine a string key serializer with a byte-array value serializer for serialized events. section 14.2.1 section 15.1.2
  • Reuse the settings with plainSink in an Akka Stream or with SendProducer when a projection handler publishes outside a stream. section 14.2.1 section 15.1.2

Publishing records with configured serializers

val producerSettings = ProducerSettings(config, new StringSerializer(), new StringSerializer()).withBootstrapServers("127.0.0.1:9092") Source(1 to 10).map(_.toString).map(value => new ProducerRecord[String, String]("test", value)).runWith(Producer.plainSink(producerSettings)) For a projection, construct SendProducer(producerSettings)(system), publish serialized records, and close the producer during coordinated shutdown. section 14.2.1 section 15.1.2

How Akka in Action, Second Edition covers it

How deep it goes
Explains construction, serializers, bootstrap configuration, and producer reuse, but defers detailed Kafka configuration beyond application defaults.
Examples
Uses a ten-record stream, a test Kafka topic, string serializers, and a market-event projection with byte-array values.
What it assumes
Assumes Kafka records, serializers, Akka Streams, and ActorSystem usage while demonstrating the producer setup directly.
What you can do after
Build it from scratch and apply it via plainSink or SendProducer to publish serialized records to Kafka.
How it connects
Connects ProducerSettings to ProducerRecord, plainSink, SendProducer, Akka Streams, projections, serializers, and CoordinatedShutdown.

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.