Skip to content

refactor: simplify partitionSubset logic in ConcurrentMessageListenerContainer #3987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -320,26 +320,24 @@ private KafkaMessageListenerContainer<K, V> constructContainer(ContainerProperti
if (topicPartitions == null) {
return null;
}

if (this.concurrency == 1) {
return topicPartitions;
}
else {
int numPartitions = topicPartitions.length;
if (numPartitions == this.concurrency) {
return new TopicPartitionOffset[] { topicPartitions[index] };
}
else {
int perContainer = numPartitions / this.concurrency;
TopicPartitionOffset[] subset;
if (index == this.concurrency - 1) {
subset = Arrays.copyOfRange(topicPartitions, index * perContainer, topicPartitions.length);
}
else {
subset = Arrays.copyOfRange(topicPartitions, index * perContainer, (index + 1) * perContainer);
}
return subset;
}

int numPartitions = topicPartitions.length;

if (numPartitions == this.concurrency) {
return new TopicPartitionOffset[] { topicPartitions[index] };
}

int perContainer = numPartitions / this.concurrency;
int start = index * perContainer;
int end = (index == this.concurrency - 1)
? numPartitions
: start + perContainer;

return Arrays.copyOfRange(topicPartitions, start, end);
}

/*
Expand Down