-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split consumer’s Events() channel into Messages() and Errors() #303
Conversation
} | ||
|
||
return nil | ||
} | ||
|
||
// ConsumerEvent is what is provided to the user when an event occurs. It is either an error (in which case Err is non-nil) or | ||
// ConsumerMessage is what is provided to the user when an event occurs. It is either an error (in which case Err is non-nil) or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the remainder of this godoc is now out-of-date
a few little things (and one suggestion of an additional enhancement) but nothing major |
…an consumer example that works with goroutines instead of a select statement.
Should I guard multiple calls to |
Nope, I think that's overly-defensive |
Err error | ||
} | ||
|
||
func (ce ConsumerError) Error() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% convinced this needs to implement error
itself, given we never (ourselves) actually stuff it into an error
type, but I guess it doesn't hurt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nice part is that it will add some context to the error message, e.g. when printing the errors that you consume from the Errors()
channel, and it can be passed around as error value.
for err := range consumer.Errors() {
fmt.Println(err)
}
Primarily, I think it's expected that an Errors()
channel will give you error instances
e.g., to ensure something like this doesn't cause issues:
|
I'd consider that just bad code o.O |
Pretty sure it's not legit to call |
I guess you can just break the for loop, and call |
You can just call |
OK, I think I addressed all the outstanding issues. |
LGTM |
Split consumer’s Events() channel into Messages() and Errors()
This is more in line with the producer. Also, it is really easy to forget checking for the
Err
field for everyConsumerEvent
, which would lead to bugs.@Shopify/kafka