I have only kafka consumer in my code, below is the configuration:
@Configuration
@RequiredArgsConstructor
public class OrderGraphKafkaConsumerConfig {
public static final String SECURITY_PROTOCOL_CONFIG = "SASL_SSL";
public static final String PLAIN = "PLAIN";
public static final String CONNECTION_STRING = "$ConnectionString";
public static final String SASL_JASS_CONFIG = "%s required username="%s" password="%s";";
private final OrderGraphConfiguration configuration;
@Bean
public ConsumerFactory<Object, Object> consumerFactory() {
Map<String, Object> props = new HashMap<>();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, configuration.getBootstrapServers());
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.GROUP_ID_CONFIG, configuration.getGroup_id());
props.put(ErrorHandlingDeserializer.KEY_DESERIALIZER_CLASS, StringDeserializer.class);
props.put(ErrorHandlingDeserializer.VALUE_DESERIALIZER_CLASS, StringDeserializer.class);
props.put(JsonDeserializer.USE_TYPE_INFO_HEADERS, false);
props.put(JsonDeserializer.TRUSTED_PACKAGES, "*");
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, SECURITY_PROTOCOL_CONFIG);
props.put(SaslConfigs.SASL_MECHANISM, PLAIN);
props.put(SaslConfigs.SASL_JAAS_CONFIG, SASL_JASS_CONFIG.formatted(
PlainLoginModule.class.getName(),
CONNECTION_STRING,
configuration.getSaslJassPsw()
));
return new DefaultKafkaConsumerFactory<>(props);
}
}
And here is application.yaml (with my tries so far)
kafka:
bootstrap-servers: localhost:7042
consumer:
auto-offset-reset: earliest
security:
protocol: SASL_PLAINTEXT
properties:
message.max.bytes: 524288000
security:
protocol: SASL_PLAINTEXT
kafka-clients-configuration:
my_component:
topics: test_topic
bootstrapServers: localhost:7042
group_id: group-test
sasl_jass_psw: psw
I tried to play with the application yaml as I saw in many answers buy nothing works for me…
How can I send a kafka message in test, without create a producer?
Additonal Info:
spring-boot: 3.3.1
spring-kafka: 3.2.1
kafka-clients: 3.7.1
spring-kafka-test: 3.2.2