-
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
[RFC/WIP] Embed client in producer and consumer #430
Conversation
CI will probably fail because I didn't update the mocks. |
This more-or-less requires we land a proper mock-client to embed in our mock-producer and mock-consumer. |
Hmmm; it's not possible in go to make This might be overkill after all. I see legitimate use cases for exporting |
Not automagically like this AFAIK.
I was still thinking that the basic I agree this feels kind of weird, but so does manually proxying a handful of methods. I agree the user shouldn't have to create a client in order to use the high-level consumer in the common case, but I'm not sure that's as true for the (current) low-level consumer. |
On the other hand, that
We don't have a high-level consumer yet, and even once we do, there still is a place for using the low level consumer. So I think we shouldn't neglect the API usability of that one. |
Not if you're writing your own consumer implementation. Honestly, the only reason I ever published Client in the first place was because the original producer implementation was so simple I exposed the primitives in case somebody wanted to write their own. I've always approached
Yes, but is there a use case for the low-level consumer that involves calling |
With our current API guarantees, it's much easier to add APIs than to remove them, so let's work on building the high-level consumer on top of the low-level consumer and the client, and see what proxies we need to add when that's done. |
Slightly tangential: Similarly, the methods above are only relevant when consuming, but they should only be relevant to the consumer itself, not to the user of the consumer. |
I still think that we should add
|
The use cases we are addressing here are:
So just |
[1] unless you make the final argument a |
If you have a list of offsets to start at, you know how many partitions are present and don't need to call |
But then you would need a different API for when you don't know this yet. |
It has to be a different path in the caller anyways, depending on whether you pass |
var consumers []*PartitionConsumer
partitions, _ := consumer.Partitions("topic")
for _, partition := range partitions
offset, err := fetchOffset("topic", partition)
if err != nil {
offset = sarama.OffsetOldest // or OffsetNewest,
}
pc, _ = consumer.ConsumePartition("topic", partition, offset)
consumers = append(consumers, pc)
} var consumers []*PartitionConsumer
offsets, err := fetchOffsets("topic")
if err != nil {
consumers, _ = consumer.ConsumeTopic("topic", offsets)
} else {
consumers, _ = consumer.ConsumerTopicFromOldest("topic")
// consumer.ConsumerTopicFromNewest("topic")
} I prefer the first option, because I think it's more straightforward, especially in the case when the |
I also prefer the first option, it's just the idea of exposing |
var consumers []*PartitionConsumer
partitions, _ := client.Partitions("topic")
for _, partition := range partitions
offset, err := fetchOffset("topic", partition)
if err != nil {
offset = sarama.OffsetOldest // or OffsetNewest,
}
pc, _ = consumer.ConsumePartition("topic", partition)
consumers := append(consumers, pc)
} would be three lines longer (to account for creating the client) and feels much cleaner to me |
This is turning into a 🚲 🏠, let's just add them and I will swallow my pride until we get people confused and I can say I told you so :D |
Except that testing is going to be way more complicated because you need to mock |
Anyway, I will just yolo-push. Once we're ready for v2 we can evaluate who was right :P |
Creating a second client is not a terrible thing; it's not optimally efficient, but it's not going to cause problems. |
ducks |
@wvanbergen