You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "nodece (via GitHub)" <gi...@apache.org> on 2024/01/02 03:11:14 UTC
Re: [PR] [fix] retry producer creation upon error after succssful topic lookup [pulsar-client-go]
nodece commented on code in PR #1139:
URL: https://github.com/apache/pulsar-client-go/pull/1139#discussion_r1439132008
##########
pulsar/producer_partition.go:
##########
@@ -185,7 +185,49 @@ func newPartitionProducer(client *client, topic string, options *ProducerOptions
} else {
p.userProvidedProducerName = false
}
- err := p.grabCnx()
+ // retry to create producer when failed with maxRetry
+ var maxRetry int
+ if p.options.MaxReconnectToBroker == nil {
+ maxRetry = -1
+ } else {
+ maxRetry = int(*p.options.MaxReconnectToBroker)
+ }
+
+ var delayReconnectTime time.Duration
+ defaultBackoff := internal.DefaultBackoff{}
+
+ var err error
+ for maxRetry != 0 {
+ if p.options.BackoffPolicy == nil {
+ delayReconnectTime = defaultBackoff.Next()
+ } else {
+ delayReconnectTime = p.options.BackoffPolicy.Next()
+ }
+
+ atomic.AddUint64(&p.epoch, 1)
+ err = p.grabCnx()
+ if err == nil {
+ break
+ }
+ p.log.WithError(err).Error("Failed to create producer at newPartitionProducer")
+ errMsg := err.Error()
+ if strings.Contains(errMsg, errTopicNotFount) {
Review Comment:
```suggestion
if errors.Is(err, ErrTopicNotfound) {
```
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org