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
