jerrypeng commented on a change in pull request #221: Auto update the client to
handle changes in number of partitions
URL: https://github.com/apache/pulsar-client-go/pull/221#discussion_r408426183
##########
File path: pulsar/consumer_impl.go
##########
@@ -130,56 +136,108 @@ func internalTopicSubscribe(client *client, options
ConsumerOptions, topic strin
log: log.WithField("topic", topic),
}
- partitions, err := client.TopicPartitions(topic)
+ if options.Name != "" {
+ consumer.consumerName = options.Name
+ } else {
+ consumer.consumerName = generateRandomName()
+ }
+
+ err := consumer.internalTopicSubscribeToPartitions()
if err != nil {
return nil, err
}
- numPartitions := len(partitions)
- consumer.consumers = make([]*partitionConsumer, numPartitions)
+ // set up timer to monitor for new partitions being added
+ duration := options.AutoDiscoveryPeriod
+ if duration <= 0 {
+ duration = defaultAutoDiscoveryDuration
+ }
+ consumer.ticker = time.NewTicker(duration)
+
+ go func() {
+ for range consumer.ticker.C {
+ consumer.log.Debug("Auto discovering new partitions")
+ consumer.internalTopicSubscribeToPartitions()
+ }
+ }()
+
+ return consumer, nil
+}
+
+func (c *consumer) internalTopicSubscribeToPartitions() error {
Review comment:
Shouldn't this whole method be under a mutex instead of only where
c.consumers is be in set? There could be race conditions if "Unsubscribe",
"Close", etc are being called while this method is running.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services