Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,37 @@ 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]
Expand Down