-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Milestone
Description
**Affects Version(s):**current main
🎁 Enhancement
instrumentations attached to ProducerFactory instances are destroyed if the user adds the configOverrides parameter. This behavior is unexpected for the developer, for example it will undo sleuth instrumentation that is otherwise kept if the new KafkaTemplate(Map) constructor would be used.
/* produces an instrumented ProducerFactory, PostProcessors are added, eg for sleuth */
@Bean
ProducerFactory<K,T> producerFactory(Map<String,Object>config) {
return new DefaultKafkaProducerFactory<K,T>(config);
}
@Bean
KafkaTemplate<K,T>kafkaTemplate(ProducerFactory<K,T>producerFactory) {
KafkaTemplate<K,T>instrumented = new KafkaTemplate(producerFactory);
// this constructor removes all PostProcessors because of the added config properties
KafkaTemplate<K,T>notInstrumented = new KafkaTemplate(producerFactory, Collections.singletonMap(ProducerConfig.CLIENT_ID, "new-client"));
return instrumented;
}