Skip to content

Commit 4f1906c

Browse files
GH-4189 : Modify Topic Assignment Docs of @KafkaListener (#4204)
* add topic assignment @KafkaListener docs * modify convention Signed-off-by: moonyoungCHAE <xpf_fl@naver.com>
1 parent febecbd commit 4f1906c

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,37 @@ public void listen(String data) {
8080
}
8181
----
8282

83-
[[manual-assignment]]
84-
== Explicit Partition Assignment
83+
[[topic-partition-assignment]]
84+
== Topic Partition Assignment
8585

86-
You can also configure POJO listeners with explicit topics and partitions (and, optionally, their initial offsets).
86+
You can configure the topic for `@KafkaListener` in three ways.
87+
You must configure the topic in one of these ways.
88+
[source, java]
89+
----
90+
@KafkaListener(id = "myListener", topics = "myTopic")
91+
public void listen(String data) {
92+
...
93+
}
94+
95+
@KafkaListener(id = "myListener", topicPattern = "my.*")
96+
public void listen(String data) {
97+
...
98+
}
99+
100+
@KafkaListener(id = "myListener", topicPartitions = { @TopicPartition(topic = "myTopic", partitions = { "0", "1" })})
101+
public void listen(String data) {
102+
...
103+
}
104+
----
105+
106+
107+
You can simply configure the topic directly by name.
108+
In this case, you can also configure the multiple topics like `topics = {"myTopic1", myTopic2"}`.
109+
110+
You can also configure topics using topicPattern, which enables topic subscription based on a regular expression.
111+
112+
When you configure topics using either of these ways (topic or topic pattern), Kafka automatically assigns partitions according to the consumer group.
113+
Alternatively, you can configure POJO listeners with explicit topics and partitions (and, optionally, their initial offsets).
87114
The following example shows how to do so:
88115

89116
[source, java]

0 commit comments

Comments
 (0)