问题
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 threeconsumersof the same template will be listening on individual cluster inparallel.
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