Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • KafkaProducer
  • KafkaConsumer
  • KafkaStreams 

These builders will give a an easy way to construct these objects using different arguments/combinations without having to add a new constructor every time a new parameter is required.

From a user point of view, builders could would be used as follow

Code Block
languagejava
themeRDark
final var consumerBuilder = new ConsumerBuilder<String, MyPojo>(<MAP_OR_PROPERTIES_OR_CONFIG>)
  .withKeyDeserializer(<KEY_DESERIALIZER>)
  .withValueDeserializer(<VALUE_DESERIALIZER>)
  .withInterceptors(<LIST_OF_INTERCEPTORS>)
  .withMetricsReporter(<METRICS_REPORTER>)
  .build();

final var producerBuilder = new ProducerBuilder<String, MyPojo>(<MAP_OR_PROPERTIES_OR_CONFIG>)
  .withKeySerializer(<KEY_SERIALIZER>)
  .withValueSerializer(<VALUE_SERIALIZER>)
  .withInterceptors(<LIST_OF_INTERCEPTORS>)
  .withPartitioner(<PARTITIONER>)
  .withMetricsReporter(<METRICS_REPORTER>)
  .build();

final var kafkaStreamsBuilder = new KafkaStreamsBuilder(<TOPOLOGY>, <MAP_OR_PROPERTIES_OR_CONFIG>)
  .withProducerInterceptors(<LIST_OF_PRODUER_INTERCEPTORS>)
  .withConsumerInterceptors(<LIST_OF_CONSUMER_INTERCEPTORS>)
  .withTime(<TIME>)
  .withKafkaClientSupplier(<KAFKA_CLIENT_SUPPLIER>)
  .withMetricsReporter(<METRICS_REPORTER>)
  .build();

This KIP can also be seen as the continuity of the KIP-832.

Proposed Changes

...

Three new builders will be added

  • KafkaProducerBuilder
  • KafkaConsumerBuilder
  • KafkaStreamsBuilder

Requirements:

  • The builder will always
    • override → single value
    • complete the configuration parameters → list values
  • Any closeable objects provided to a builder will still be closed once the client is closed, and as a result, a builder should only be used once. An exception will be thrown if build() is invoked multiple times.
  • Any configurable object provided to a builder will be configured by the client after instantiation.

Compatibility, Deprecation, and Migration Plan

...