Akka Streams Kafka
Producer
A producer publishes messages to Kafka topics. The message itself contains information about what topic and partition to publish to so you can publish to different topics with the same producer.
The underlaying implementation is using the
KafkaProducer
, see Javadoc for details.Producer as a Sink
Producer.plainSink
is the easiest way to publish messages. The sink consumes ProducerRecord
elements which contains a topic name to which the record is being sent, an optional partition number, and an optional key and value.- Scala
- Java
protected final ProducerSettings<byte[], String> producerSettings = ProducerSettings .create(system, new ByteArraySerializer(), new StringSerializer()) .withBootstrapServers("localhost:9092"); protected final KafkaProducer<byte[], String> kafkaProducer = producerSettings.createKafkaProducer();
Producer as a Sink
Producer.plainSink
is the easiest way to publish messages. The sink consumes ProducerRecord
elements which contains a topic name to which the record is being sent, an optional partition number, and an optional key and value.Sharing KafkaProducer
If you have many streams it can be more efficient to share the underlying
KafkaProducer
.
You can create a
KafkaProducer
instance from ProducerSettings
.
The
KafkaProducer
is passed as a parameter to the Producer
factory methods.
Comments
Post a Comment