简体   繁体   中英

Spring Kafka Multiple Schema registries with Multiple Kafka Templates

From Spring Kafka 2.5 onwards it is possible to have multiple Kafka templates based on different producer config , from the documentation it seems the templates vary in Key and Value types.

In a Spring boot service,

Is it possible to have multiple Spring Kafka Templates with same Key and Value types, the templates only different in their producer configurations

ie for example:

KafkaTemplate<String, String> defaultKafkaTemplate
KafkaTemplate<String, String> anotherKafkaTemplate

If the answer is a yes to the above question:

Is it possible to have a separate schema registry for each of those templates

ie

defaultkafkaTemplate is tied to schema 1 present in Registry A anotherkafkaTemplate is tied to schema 10 present in Registry B

I am able to integrate single AWS Glue Schema registry with a Spring Kafka provided KafkaTemplate, was wondering if the above case is possible at all?

Yes, you can define two beans:

@Bean
KafkaTemplate<String, String> defaultTemplate(ProducerFactory<String, String> pf) {
    return new KafkaTemplate<>(pf);
}

@Bean
KafkaTemplate<String, String> otherTemplate(ProducerFactory<String, String> pf) {
    return new KafkaTemplate<>(pf, Map.of("some.property", "other.value");
}

If you define any KafkaTemplate bean(s), Boot will not auto configure one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM