Multiple KafkaConsumer on multiple Kafka Cluster in Spring Boot

耗尽温柔 提交于 2020-06-28 06:27:08

问题


Want to create homogeneous kafka consumers on different clusters from a Spring boot application using spring-kafka.

i.e Want to create a Kafka Consumer object for class defined already which listens to multiple cluster defined dynamically.

e.g: Lets say a Spring boot application S which contains the template for kafkaconsumer. And there are three Kafka Clusters custer1, cluster2, cluster3. The application S act as an aggregator of data produced from each of the cluster. Here the solution would be three consumers of the same template will be listening on individual cluster in parallel.

Is the above scenario is possible using spring-kafka?


回答1:


A @KafkaListener can't talk to multiple clusters. You would need to delegate to the real listener...

@KafkaListener(..., containerFactory="cluster1Factory")
public void listen1(...) {
    this.delegate.listen(...);
}

@KafkaListener(..., containerFactory="cluster2Factory")
public void listen2(...) {
    this.delegate.listen(...);
}

etc.


来源:https://stackoverflow.com/questions/52713290/multiple-kafkaconsumer-on-multiple-kafka-cluster-in-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!