spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.2k stars 40.69k forks source link

Provide auto-configuration for Spring for Apache Kafka's reactive support #18804

Closed rycee closed 4 years ago

rycee commented 5 years ago

To produce a ReactiveKafkaProducerTemplate I have to explicitly include the ProducerConfig.TRANSACTIONAL_ID_CONFIG property as per the following example

@Bean
public ReactiveKafkaProducerTemplate<String, byte[]> reactiveKafkaProducerTemplate(
    KafkaProperties properties) {
  Map<String, Object> props = properties.buildProducerProperties();
  props.put(
      ProducerConfig.TRANSACTIONAL_ID_CONFIG, properties.getProducer().getTransactionIdPrefix());
  return new ReactiveKafkaProducerTemplate<>(SenderOptions.create(props));
}

I would have expected this property to be included by default when calling properties.buildProducerProperties() making

@Bean
public ReactiveKafkaProducerTemplate<String, byte[]> reactiveKafkaProducerTemplate(
    KafkaProperties properties) {
  Map<String, Object> props = properties.buildProducerProperties();
  return new ReactiveKafkaProducerTemplate<>(SenderOptions.create(props));
}

work.

The transactional ID prefix property was added in #11076.

wilkinsona commented 5 years ago

When configured only at the property level, my understanding is that TRANSACTION_ID_CONFIG is useless without else setting ENABLE_IDEMPOTENCE_CONFIG to true. From the docs for the former:

Note that enable.idempotence must be enabled if a TransactionalId is configured.

As its name suggests, the transaction-id-prefix configuration property was added to map to the transaction ID prefix of DefaultKafkaProducerFactory. The producer factory automatically enables idempotent behaviour when a transaction ID prefix is set.

Like all of Boot's own @ConfigurationProperties classes, we also consider KafkaProperties to be internal:

Similar to auto-configuration classes, @ConfigurationProperties classes available in Spring Boot are for internal use only. The properties that map to the class, which are configured via properties files, YAML files, environment variables etc., are public API but the content of the class itself is not meant to be used directly.

As such, you shouldn't be using it for your own purposes and should use your own @ConfigurationProperties class instead.

We can revisit the current situation as part of possibly adding auto-configure for Spring for Apache Kafka's reactive support. We also have another request, that is somewhat related, to provide auto-configuration for Reactor Kafka directly rather than Spring for Apache Kafka's wrapper.

wilkinsona commented 4 years ago

Given that Reactor Kafka isn't a high priority for the Reactor team at the moment, we don't want to drive people towards it or Spring for Apache Kafka's features that are built on top of it. We can reconsider in the future if the situation changes.