PavelZeger commented on issue #1496:
URL: 
https://github.com/apache/pulsar-client-go/issues/1496#issuecomment-4582293031

   > Thanks for the detailed analysis [@nodece](https://github.com/nodece) - 
I've gone through the four `Consumer` implementations (_consumer_, 
_multiTopicConsumer_, _regexConsumer_, _zeroQueueConsumer_) and I agree on the 
first three: a `BatchReceive `here would only be a for-loop around Chan() - no 
real benefit.
   > 
   > So I withdraw the proposal to add BatchReceive to the Consumer interface 
for these cases.
   > 
   > Where I think there's still a real benefit - `ZeroQueueConsumer:` 
`zeroQueueConsumer.Receive` works differently:
   > 
   > 1. It takes a lock,
   > 2. calls `availablePermits.inc()` to grant exactly one permit,
   > 3. waits for that one message,
   > 4. repeats.
   > 
   > Consuming N messages with the current API costs N sequential permit grants 
and N round-trips to the broker. A native `BatchReceive(N)` could grant N 
permits upfront in a single Flow command and return when N messages have 
arrived (or the deadline fires). That's an actual optimization, not a wrapper - 
and it's specific to the Go client because of how `zeroQueueConsumer` is wired.
   > 
   > Proposed compromise:
   > 
   > 1. **Utility helper** for the common cases. A free function in a small 
pulsar/util (or batch) subpackage:
   >    `func BatchReceive(ctx context.Context, c pulsar.Consumer, policy 
BatchReceivePolicy) ([]pulsar.Message, error)`. It would wrap `Chan()` with 
correct timer semantics, a documented byte-size definition, partial-batch 
return on timeout/ctx cancel, etc. No changes to the Consumer interface. It's 
for users who want batch ergonomics opt in, everyone else is unaffected.
   > 2. **Native batch only for ZeroQueueConsumer.** Add `BatchReceive` to a 
narrower interface (or to `ZeroQueueConsumer` directly) where it earns its 
place by saving real round-trips. This is the only spot where the API gives the 
user something they can't replicate from outside.
   > 
   > If this looks for you as a benefit, I'd be happy to create the PR to 
reflect it - **utility helper for default/multi-topic/regex** _and/or_ **native 
batch for zero-queue only**. WDYT?
   
   Hi @nodece. Appreciate for the review of my latest comment/suggestion above.


-- 
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]

Reply via email to