cckellogg 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_r407814437
 
 

 ##########
 File path: pulsar/producer_impl.go
 ##########
 @@ -73,25 +83,67 @@ func newProducer(client *client, options *ProducerOptions) 
(*producer, error) {
                p.messageRouter = options.MessageRouter
        }
 
-       partitions, err := client.TopicPartitions(options.Topic)
+       err := p.internalCreatePartitionsProducers()
        if err != nil {
                return nil, err
        }
 
-       numPartitions := len(partitions)
-       p.producers = make([]Producer, numPartitions)
+       p.ticker = time.NewTicker(partitionsAutoDiscoveryInterval)
+
+       go func() {
+               for range p.ticker.C {
+                       p.log.Debug("Auto discovering new partitions")
+                       p.internalCreatePartitionsProducers()
+               }
+       }()
+
+       return p, nil
+}
+
+func (p *producer) internalCreatePartitionsProducers() error {
+       partitions, err := p.client.TopicPartitions(p.topic)
+       if err != nil {
+               return err
+       }
+
+       oldNumPartitions := 0
+       newNumPartitions := len(partitions)
+
+       if p.producers != nil {
 
 Review comment:
   Do we need a lock for the producers?

----------------------------------------------------------------
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

Reply via email to