I have written a KafkaConsumer
. The configuration looks like this:
@Bean
Map<String, Object> consumerConfig(
@Value("${spring.kafka.bootstrap-servers}") String bootstrapServers) {
return Map.of(
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,
bootstrapServers,
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
"earliest",
ConsumerConfig.ALLOW_AUTO_CREATE_TOPICS_CONFIG,
false,
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
StringDeserializer.class,
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
StringDeserializer.class);
}
When I assign a topic that does not exist to the KafkaConsumer
, no error is thrown. This is the code:
var topicPartition = new TopicPartition("75757584959595943", key);
var partitions = Set.of(topicPartition);
consumer.assign(partitions);
for (var records = consumer.poll(Duration.ZERO); !records.isEmpty(); ) {
// ...
Why does the KafkaConsumer
not alert me about a non-existing topic? Wouldn't this be helpful?