首页 > 解决方案 > 什么是 Spring KafkaListener 的多个主题阅读策略?

问题描述

Kafka 如何处理多个主题?

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

例如:

阅读顺序是什么?

或者服务器将实例化两个同时读取两个主题的线程?

标签: javaapache-kafkakafka-consumer-apispring-kafka

解决方案


这两个都是真的。它是随机的

  • "topic1_message1","topic1_message2","topic2_message1","topic2_message2"
  • "topic1_message1","topic2_message1","topic1_message2","topic2_message2"

因为它们位于单个分区上,所以您应该知道一件事;

  1. “topic1_message1”在“topic1_message2”之前
  2. “topic2_message1”在“topic2_message2”之前

推荐阅读