繁体   English   中英

Kafka - 使用多个主题时出现 InvalidTopicException

[英]Kafka - InvalidTopicException when using multiple topics

我有一个 SpringBoot 应用程序,我在其中使用带有主题和 groupId 的 @KafkaListener 注释。 我有两个话题需要听众倾听。 听一个主题时,任何一个都可以正常工作

    @KafkaListener(topics = "topic1", groupId = "local")

要么

    @KafkaListener(topics = "topic2", groupId = "local")

然而,当我像这样将两者结合起来时(这是我对如何在一个听众上做多个主题的理解):

    @KafkaListener(topics = {"topic1,topic2"}, groupId = "local")

,我得到如下滚动异常:

{
  "app": "myApp",
  "@timestamp": "2022-12-20T12:01:55.004Z",
  "userId": "",
  "hostname": "",
  "ipAddress": "",
  "logger": "org.apache.kafka.clients.Metadata",
  "level": "ERROR",
  "thread": "org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1",
  "message": "[Consumer clientId=consumer-local-1, groupId=local] Metadata response reported invalid topics [topic1,topic2]",
  "class": "org.apache.kafka.clients.Metadata",
  "method": "checkInvalidTopics",
  "file": "Metadata.java",
  "line": 294
}
{
 "app": "myApp",
 "@timestamp": "2022-12-20T12:01:55.004Z",
 "userId": "",
 "hostname": "",
 "ipAddress": "",
 "logger": "org.apache.kafka.clients.consumer.internals.AbstractCoordinator",
 "level": "INFO",
 "thread": "org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1",
 "message": "[Consumer clientId=consumer-local-1, groupId=local] Rebalance failed.",
 "class": "org.apache.kafka.clients.consumer.internals.AbstractCoordinator",
 "method": "joinGroupIfNeeded",
 "file": "AbstractCoordinator.java",
 "line": 470,
 "stack": "org.apache.kafka.common.errors.InvalidTopicException: Invalid topics: [topic1,topic2]\n"

}

非常感谢任何关于我做错的想法。 谢谢

您可以通过在逗号分隔的对象中传递它们来收听同一个@KafkaListener 中的多个主题。 在你的情况下应该是

@KafkaListener(topics = {"topic1", "topic2"}, groupId = "local")

试试这个:

{"topic1", "topic2"}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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