I am confused how to add authentication credentials progrmatically. Not sure if SECURITY_PROVIDERS_CONFIG is where I set these values. Was also going through the constants and I could see many configs have _DOC and I am curious what does it mean. For example SECURITY_PROVIDERS_CONFIG and SECURITY_PROVIDERS_DOC.
Here is my config class:
@Configuration
public class KafkaProducerConfig {
@Value(value = "${spring.kafka.bootstrap-servers}")
private String bootstrapAddress;
@Bean
public ProducerFactory<String, String> producerFactory() {
Map<String, Object> configProps = new HashMap<>();
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
configProps.put(ProducerConfig.INTERCEPTOR_CLASSES_CONFIG, CountingProducerInterceptor.class.getName());
configProps.put(ProducerConfig.ACKS_CONFIG, "all");
configProps.put(ProducerConfig.ENABLE_IDEMPOTENCE_DOC, "true");
configProps.put(ProducerConfig.RETRIES_CONFIG, 3);
//configProps.put(ProducerConfig.SECURITY_PROVIDERS_CONFIG, "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"username\" password=\"pa$$wrd\"");
configProps.put(ProducerConfig.MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION, 5);
configProps.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, 10000);
configProps.put(ProducerConfig.RETRY_BACKOFF_MS_CONFIG, 3000);
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
return new DefaultKafkaProducerFactory<>(configProps);
}
@Bean
public KafkaTemplate<String, String> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
}
I have commented out the property that I am confused. Not sure if this ishow you pass username and password. Thanks in advance.