I get the following error message during runtime, every time a Kafka event is generated in my production environment. Please note that the same code works in my local setup without any issues and all Jenkins builds are successful. The error is the following:
Caused by: o.a.k.c.c.ConfigException: Invalid value io.confluent.kafka.serializers.context.NullContextNameStrategy for configuration context.name.strategy: Class io.confluent.kafka.serializers.context.NullContextNameStrategy could not be found.\n"}
This is my Kafka config class:
@Bean
@Qualifier("json-schema")
public KafkaTemplate<String, MyEvent<?>> jsonSchemaKafkaTemplate() throws ClassNotFoundException {
return new KafkaTemplate<>(new DefaultKafkaProducerFactory<>(setCommonProducerProperties(),
new StringSerializer(),
new KafkaJsonSchemaSerializer<>()));
}
private Map<String, Object> setCommonProducerProperties(){
// Setting common properties
Map<String, Object> configProps = setBrokerProperties();
configProps.put(ProducerConfig.RETRIES_CONFIG, KafkaPropertiesConfiguration.JsonSchemaProperties.RETRIES);
configProps.put(ProducerConfig.CLIENT_ID_CONFIG,
return configProps;
}
private Map<String, Object> setBrokerProperties() {
Map<String, Object> brokerProperties = new HashMap<>();
brokerProperties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaPropertiesConfiguration.getBroker().getBootstrapServers());
brokerProperties.put(SCHEMA_REGISTRY_URL_CONFIG, kafkaPropertiesConfiguration.getBroker().getSchemaRegistryUrl());
KafkaPropertiesConfiguration.SecurityProperties securityProperties = kafkaPropertiesConfiguration.getBroker().getSecurity();
(... Keystore and Truststore credentials)
return brokerProperties;
}
Im using the following versions in my POMS:
<spring-kafka.version>3.1.0</spring-kafka.version>
<kafka-client.version>3.6.1</kafka-client.version>
<confluent.version>7.6.0</confluent.version>
and:
<!-- Kafka -->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>${spring-kafka.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<version>${spring-kafka.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>${kafka-client.version}</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>${kafka-client.version}</version>
<classifier>test</classifier>
<scope>test</scope>
</dependency>
<!-- Confluent Schema Registry Client -->
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-json-schema-serializer</artifactId>
<version>${confluent.version}</version>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-schema-registry-client</artifactId>
<version>${confluent.version}</version>
</dependency>
It is worth mentioning that some Kafka classes could not be found and loaded by the context loader during runtime, such as the “StringSerializer” class “KafkaJsonSchemaSerializer”, for this reason I have used the contstructor for both classes in my Kafka template. Otherwise I get the same error message that these classes could not be found.