如何在Spring上下文中创建Kafka监听器并动态添加它们。

huangapple 未分类评论52阅读模式
英文:

how to create kafka listeners and add them dynamically in spring context

问题

你好,我正在开发一个Groovy DSL,它允许使用Spring Boot动态创建Kafka消费者。例如,我可以编写以下代码:

  1. consumer("topic1", "group_id_1") {
  2. //
  3. }
  4. consumer("topic2", "group_id_2") {
  5. //
  6. }

从这段代码中,我可以动态地创建两个Kafka消费者。一个消费者订阅主题"topic1",使用组ID "group_id_1",另一个消费者订阅主题"topic2",使用组ID "group_id_2"。然后将这两个消费者添加到Spring应用程序的上下文中。

英文:

hello i am developing a groovy dsl which allows to dynamically create kafka consumers with spring boot, exmple i can write.

  1. consumer("topic1","group_id_1"){
  2. //
  3. }
  4. consumer("topic2","group_id_2"){
  5. //
  6. }

and from this code I dynamically create two consumers kafka, consumer towards the topic "topic1" with a group id "group_id_1" and consumer towards the topic "topic 2" and with a group id "group_id_2" and add these two consumers in spring context application.

huangapple
  • 本文由 发表于 2020年3月15日 18:01:50
  • 转载请务必保留本文链接:https://java.coder-hub.com/60691680.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定