-
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
Add two new optional channels to the ProducerConfig for handling failures and acks #114
Conversation
Please let me know any suggestions or required changes to get this accepted. |
MaxBufferedBytes uint32 // The maximum number of bytes to buffer per-broker before sending to Kafka. | ||
MaxBufferTime uint32 // The maximum number of milliseconds to buffer messages before sending to a broker. | ||
ReturnFailedMessages bool // Whether messages that have failed to be stored in Kafka should be returned via the Failed() channel. If true (default false) then you *must* read the values from the Failed() channel. | ||
ReturnAckCounts bool // Whether to return the number of acks per partition (per topic) on the Acked() channel. If true (defaul false) then you *must* read the values from the Acked() channel. |
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.
s/defaul/default
In the commit message, the AckCounts paragraph still refs ReturnFailedMessages in one spot instead of ReturnAckCounts |
// Setting ReturnAckCounts = true in the producer config is required for the ack counts to | ||
// be sent. You must consume this channel or it | ||
// will eventually block | ||
func (p *Producer) Acked() chan map[int32]int64 { |
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.
This (and Failed) should return read-only channels.
For getting the key back with the failed message, how would you prefer it done? It could just be a simple struct like
and they could be sent one at a time. Or it could be a |
I'd almost be tempted to just return each entire |
Other than figuring out the return format this looks fine to me now. |
Maybe we can just reuse the |
@wvanbergen I am all for reuse of an existing type. Of the two, ConsumerEvent seems to fit the bill pretty well. The only thing that cannot be populated is the offset field. Since it is an |
I think not setting it (so |
I prefer -1 I think, since 0 is in principle a valid offset. Err should be set if possible to the same err that comes out the Also, should we rename |
+1 on the rename. Does it make sense to merge Message and ConsumerEvent while we are at it? |
Is the current plan to do whatever naming rewrite before merging this? Or is that something that can be done afterward? |
Let's ;eave the renaming for a separate PR; use ConsumerEvent for now. |
After looking at this again, I think the API is a bit too complicated. You have to set a config variable, AND consume a channel that gets returned by a function call. Can we change it so as a user, you just provide a channel to the ProducerConfig if you want to use it? Does this make sense? |
Sure, it makes sense. I will get on this tonight. I think after it is done it will be a lot more apparent how much improvement it offers to the api. If this only for Errors, or do you want a similar approach take for acks? |
Kafka and to retrieve messages that failed for possible replay. ReturnFailedMessages in the config will trigger any messages that were not successfully sent / acked to be sent on the failed channel as []byte. The application using this package is responsible for reading from the failed channel, retrieved via the Failed() function on the Producer If ReturnFailedMessages is true, then the application must consume the Failed() channel or it will eventually block. ReturnAckCounts in the config will trigger ack counts per partition, per topic to be sent on the acked channel after each flush. The application using this package is responsible for reading from the acked channel, retrieved via the Acked() function on the Producer If ReturnFailedMessages is true, then the application must consume the Acked() channel or it will eventually block. This commit also includes a change for the error sent in the DroppedMessagesError struct to the errorCb to be the block error instead of the error returned from Produce.
I don't know what the heck happened with that upstream merge, but I hope all is right in the world. |
} | ||
default: | ||
errorCb(DroppedMessagesError{len(prb), err}) | ||
errorCb(DroppedMessagesError{len(prb), block.Err}) |
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.
oop, good catch
Not sure how one of my commits ended up in the history here... time for a rebase squish I think. |
…n potential key with []byte message of failures. Possibly a new struct. Change failed channel to type *ConsumerEvent so all relevent information including Key, Value, Partition, Topic and Err can be consumed by the async caller. A rewrite based on PR comments. Instead of boolean config values and needing to get a channel via a function call, put the onus on the user to provide an AckedChannel and/or a FailedChannel to read the acks / failures from. Add two new channels to the Producer for handling acknowledgments from Kafka and to retrieve messages that failed for possible replay. ReturnFailedMessages in the config will trigger any messages that were not successfully sent / acked to be sent on the failed channel as []byte. The application using this package is responsible for reading from the failed channel, retrieved via the Failed() function on the Producer If ReturnFailedMessages is true, then the application must consume the Failed() channel or it will eventually block. ReturnAckCounts in the config will trigger ack counts per partition, per topic to be sent on the acked channel after each flush. The application using this package is responsible for reading from the acked channel, retrieved via the Acked() function on the Producer If ReturnFailedMessages is true, then the application must consume the Acked() channel or it will eventually block. This commit also includes a change for the error sent in the DroppedMessagesError struct to the errorCb to be the block error instead of the error returned from Produce. Changes based on PR review. Still need to decide on best way to return potential key with []byte message of failures. Possibly a new struct. Change failed channel to type *ConsumerEvent so all relevent information including Key, Value, Partition, Topic and Err can be consumed by the async caller. A rewrite based on PR comments. Instead of boolean config values and needing to get a channel via a function call, put the onus on the user to provide an AckedChannel and/or a FailedChannel to read the acks / failures from.
If you like I can open a new, fresh PR with all of the latest changes to clean things up a bit. |
Fine by me. |
FailedChannel, when provided will have all messages that are not acked sent as type *ConsumerEvent. The application using this package is responsible for reading from the failed channel or it will eventually block.
AckingChannel, when provided will provide counts per partition, per topic of acked messages after each flush. The application using this package is responsible for reading from the acking channel or is will eventually block.
This commit also includes a change for the error sent in the DroppedMessagesError struct to the errorCb to be the block error instead of the error returned from Produce.