cckellogg commented on a change in pull request #156: [ISSUE #152][consumer] 
add consumer timeout
URL: https://github.com/apache/pulsar-client-go/pull/156#discussion_r362555712
 
 

 ##########
 File path: pulsar/consumer.go
 ##########
 @@ -135,6 +135,10 @@ type Consumer interface {
        // This calls blocks until a message is available.
        Receive(context.Context) (Message, error)
 
+       // Receive a single message.
+       // This calls blocks until a message is available or timeout.
+       ReceiveBlock(context.Context, time.Duration) (Message, error)
 
 Review comment:
   @wolfstudy I disagree that is more user friendly.
   
   The purpose of having a Context with the current Receive method is to allow 
users the ability to add a timeout or cancel to a receive call if they want to. 
Adding a new receive method that does something that can already be done 
through the current api is not good for the user. It confusing and complicates 
the api. We should try to keep the api simple because once you publicly expose 
something you have to always support it. We should add documentation on how to 
add a timeout to a receive as opposed to adding a new api.
   
   A user can add a few lines to their program and get a timeout with every 
receive. For example.
   
   ```
   func receiveWithTimeout(receiveFn func(ctx context.Context) (Message, 
error), duration time.Duration) (Message, error) {
        ctx, cancel := context.WithTimeout(context.Background(), duration)
        defer cancel()
        return receiveFn(ctx)
   }
   
   m, err := receiveWithTimeout(consumer.Receive, 500*time.Millisecond)
   ```
   
   We should give example like this instead of adding an additional api. 
Thoughts?
   
   
   
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to