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
Issue #2330: change getTopicName in MultiTopicsConsumer #2346
Conversation
rerun java tests |
* @return the name of the topic on which this message was published | ||
*/ | ||
public String getTopicName() { | ||
int position = topicName.lastIndexOf(PARTITIONED_TOPIC_SUFFIX); | ||
checkState(position != -1, "Topic Name not contains partition part. " + topicName); | ||
return topicName.substring(0, position); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think this is a bit expensive, if people calls getTopicName, it has to do substring
on every call. Can we pass in topicName
and topicPartitionName
on constructing TopicMessageImpl?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sijie Thanks. will keep the topicPartitionName while constructing.
3688e16
to
85ba903
Compare
this.topicName = topicPartitionName.substring(0, position); | ||
} else { | ||
this.topicName = topicPartitionName; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will potentially create strings for each received message
|
||
int position = topicPartitionName.lastIndexOf(PARTITIONED_TOPIC_SUFFIX); | ||
if (position != -1) { | ||
this.topicName = topicPartitionName.substring(0, position); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jiazhai I think you misunderstood my comment.
I think a better solution is in ConsumerBase
, we maintain two variables, one is topicName
, the other is topicPartitionName
. so when we construct TopicMessageIdImpl
, it will use the strings constructed in ConsumerBase
.
591d9fd
to
34b1565
Compare
@merlimat can you review this PR? |
@jiazhai can you rebase this PR? |
merged as 2595941 into branch-2.1 |
Motivation
getTopicName
inTopicMessageIdImpl
andTopicMessageImpl
is some kind of confusing.Developer may mis-use it.
Modifications
change method
getTopicName
to let it return topic name without partition.add method
getTopicPartitionName
, which return topic name with partition part.Result
More clear of the method names.
Unit-Tests all pass.
Issue #2330 get fixed.