From 7a43432a5555138f9cd5a550a5c82e33000418ad Mon Sep 17 00:00:00 2001 From: moonyoungCHAE Date: Tue, 9 Dec 2025 12:22:30 +0900 Subject: [PATCH 1/2] add topic assignment @KafkaListener docs Signed-off-by: moonyoungCHAE --- .../listener-annotation.adoc | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc b/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc index 8023e4aa67..8ac155a950 100644 --- a/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc +++ b/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc @@ -80,10 +80,34 @@ public void listen(String data) { } ---- -[[manual-assignment]] -== Explicit Partition Assignment +[[topic-partition-assignment]] +== Topic Partition Assignment -You can also configure POJO listeners with explicit topics and partitions (and, optionally, their initial offsets). +You can configure the topic for `@KafkaListener` in three ways. You must configure the topic in one of these ways. +[source, java] +---- +@KafkaListener(id = "myListener", topics = "myTopic") +public void listen(String data) { + ... +} + +@KafkaListener(id = "myListener", topicPattern = "my.*") +public void listen(String data) { + ... +} + +@KafkaListener(id = "myListener", topicPartitions = { @TopicPartition(topic = "myTopic", partitions = { "0", "1" })}) +public void listen(String data) { + ... +} +---- + + +You can simply configure the topic directly by name. In this case, you can also configure the multiple topics like `topics = {"myTopic1", myTopic2"}`. + +You can also configure topics using topicPattern, which enables topic subscription based on a regular expression. + +When you configure topics using either of these ways (topic or topic pattern), Kafka automatically assigns partitions according to the consumer group. Alternatively, you can configure POJO listeners with explicit topics and partitions (and, optionally, their initial offsets). The following example shows how to do so: [source, java] From 57bbca0634dbac8499e02471b6ac884e8eb39b25 Mon Sep 17 00:00:00 2001 From: moonyoungCHAE Date: Thu, 11 Dec 2025 21:16:38 +0900 Subject: [PATCH 2/2] modify convention Signed-off-by: moonyoungCHAE --- .../kafka/receiving-messages/listener-annotation.adoc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc b/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc index 8ac155a950..21c2892d9a 100644 --- a/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc +++ b/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc @@ -83,7 +83,8 @@ public void listen(String data) { [[topic-partition-assignment]] == Topic Partition Assignment -You can configure the topic for `@KafkaListener` in three ways. You must configure the topic in one of these ways. +You can configure the topic for `@KafkaListener` in three ways. +You must configure the topic in one of these ways. [source, java] ---- @KafkaListener(id = "myListener", topics = "myTopic") @@ -103,11 +104,13 @@ public void listen(String data) { ---- -You can simply configure the topic directly by name. In this case, you can also configure the multiple topics like `topics = {"myTopic1", myTopic2"}`. +You can simply configure the topic directly by name. +In this case, you can also configure the multiple topics like `topics = {"myTopic1", myTopic2"}`. You can also configure topics using topicPattern, which enables topic subscription based on a regular expression. -When you configure topics using either of these ways (topic or topic pattern), Kafka automatically assigns partitions according to the consumer group. Alternatively, you can configure POJO listeners with explicit topics and partitions (and, optionally, their initial offsets). +When you configure topics using either of these ways (topic or topic pattern), Kafka automatically assigns partitions according to the consumer group. +Alternatively, you can configure POJO listeners with explicit topics and partitions (and, optionally, their initial offsets). The following example shows how to do so: [source, java]