zjxxzjwang commented on code in PR #1459:
URL: https://github.com/apache/pulsar-client-go/pull/1459#discussion_r2757787587
##########
pulsar/consumer_impl.go:
##########
@@ -150,32 +150,40 @@ func newConsumer(client *client, options ConsumerOptions)
(Consumer, error) {
oldRetryTopic := tn.Domain + "://" + tn.Namespace + "/" +
options.SubscriptionName + RetryTopicSuffix
oldDlqTopic := tn.Domain + "://" + tn.Namespace + "/" +
options.SubscriptionName + DlqTopicSuffix
- if r, err :=
client.lookupService.GetPartitionedTopicMetadata(oldRetryTopic); err == nil &&
- r != nil &&
- r.Partitions > 0 {
- retryTopic = oldRetryTopic
- }
-
- if r, err :=
client.lookupService.GetPartitionedTopicMetadata(oldDlqTopic); err == nil &&
- r != nil &&
- r.Partitions > 0 {
- dlqTopic = oldDlqTopic
+ CheckTopicIsExists := func(topic string) bool {
+ r, err :=
client.lookupService.GetPartitionedTopicMetadata(topic)
+ return err == nil && r != nil && r.Partitions > 0
}
+ //If the retryTopic or DLQTopic has already been set,
+ //there is no need to perform GetPartitiondTopicMetadata
operation on oldRetroTopic or oldDLQTopic
if options.DLQ == nil {
+ if CheckTopicIsExists(oldRetryTopic) {
+ retryTopic = oldRetryTopic
+ }
+ if CheckTopicIsExists(oldDlqTopic) {
+ dlqTopic = oldDlqTopic
+ }
options.DLQ = &DLQPolicy{
MaxDeliveries: MaxReconsumeTimes,
DeadLetterTopic: dlqTopic,
RetryLetterTopic: retryTopic,
}
} else {
if options.DLQ.DeadLetterTopic == "" {
+ if CheckTopicIsExists(oldDlqTopic) {
+ dlqTopic = oldDlqTopic
+ }
options.DLQ.DeadLetterTopic = dlqTopic
}
if options.DLQ.RetryLetterTopic == "" {
+ if CheckTopicIsExists(oldRetryTopic) {
+ retryTopic = oldRetryTopic
+ }
options.DLQ.RetryLetterTopic = retryTopic
}
}
Review Comment:
I agree
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]