nodece commented on code in PR #1490:
URL: https://github.com/apache/pulsar-client-go/pull/1490#discussion_r3247573928
##########
pulsar/consumer.go:
##########
@@ -222,6 +222,28 @@ type ConsumerOptions struct {
// MaxReconnectToBroker sets the maximum retry number of
reconnectToBroker. (default: ultimate)
MaxReconnectToBroker *uint
+ // MaxReconnectToBrokerListener is called when the consumer gives up on
reconnecting to the
+ // broker. The consumer argument is the parent consumer, and err is the
last connection error.
+ // Use this callback to detect silent failure and take recovery action
(e.g. recreate the
+ // consumer). The callback fires at most once per reconnect cycle, in
either of two cases:
+ // 1. The retry budget set by MaxReconnectToBroker is exhausted.
+ // 2. The broker reports a non-retriable error (e.g.
AuthorizationError, TopicNotFound,
+ // TopicTerminated, IncompatibleSchema). In this case the listener
fires regardless of
+ // whether MaxReconnectToBroker was set, since retrying cannot
recover.
+ // This callback is invoked from the partition consumer event loop, so
applications must not
+ // call consumer.Close() synchronously from within the callback — doing
so can deadlock. If
+ // closing is required, do it asynchronously (for example, in another
goroutine), or enable
+ // CloseConsumerOnMaxReconnectToBroker to let the client close the
consumer safely after the
+ // callback returns.
+ MaxReconnectToBrokerListener func(consumer Consumer, err error)
Review Comment:
@PavelZeger
1. `OnConsumerClose(consumer Consumer, err error)` looks good. When `err` is
nil, this means the consumer has been closed by the user.
2. This hook should be called once when the consumer has been closed.
3. Good catch, please add `ConsumerCloseInterceptor` to keep backward
compatibility.
--
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]