Hi,
I was filing KAFKA-7059 ([1]) and sent a PR adding a new ctor:
--
public ProducerRecord(String topic, K key, V value, Iterable<Header>
headers)
---
One reasonable comment on the PR was instead of doing constructor
overloading, why not working on a builder for the ProducerRecord class.
I think this is generally a nice idea I was wondering if there is much
interest in ?
Sample:
---
final ProducerRecord<String, String> myRecord = ProducerRecord.builder() //
or an exposed builder
.topic("mytopic")
.key("Key")
.value("the-val")
.headers(myHeaderIterable)
.build();
---
While at it - instead of just offering a builder for the "ProducerRecord"
class, why not adding a builder for the "KafkaProducer" and "KafkaConsumer"
clazzes.
---
final KafkaProducer<String, String> myProducer = KafkaProducer.builder() //
or an exposed builder clazz
.config(myProducerConfig)
.keySerializer(myStringSerializer)
.valueSerializer(myStringSerializer)
.build();
---
to even make the above more nice, I think the "ProducerConfig" (analog the
ConsumerConfig) configuration options could be also made accesible w/ this
fluent API - instead of properties/map, which is what now dominates the
creation of the Consumers/Producers.
Any thoughts? If there is interest, I am happy to start a KIP w/ a first
draft of the suggested API!
Cheers,
Matthias
[1] https://issues.apache.org/jira/browse/KAFKA-7059
--
Matthias Wessendorf
github: https://github.com/matzew
twitter: http://twitter.com/mwessendorf