You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/10/26 10:58:21 UTC

[GitHub] [pulsar] lhotari edited a comment on issue #8307: [Java] [v2.5.2] An exception was thrown by TimerTask: NullPointerException

lhotari edited a comment on issue #8307:
URL: https://github.com/apache/pulsar/issues/8307#issuecomment-716471985


   > Hi @lhotari do you think this could fix an issue with a blocking `pulsarConsumer.batchReceive()` while using a `BatchReceivePolicy` with a timeout set ? I set a timeout to 250ms but it may fail to return after waiting for 60s.
   
   @e-marchand-exensa The problem is that `Consumer.batchReceive` doesn't currently provide a way to set the timeout for a batchReceive call. The  `BatchReceivePolicy` controls the batch creation, but when no messages are received, the timeout will have no impact on a batchReceive call. With the #8326 changes, it's possible to set the timeout for batchReceiveAsync call in JDK 9+, for example:
   ```
   CompletableFuture<Messages<?>> batchResult = consumer.batchReceiveAsync().orTimeout(250, TimeUnit.MILLISECONDS);
   ```
   This means that there is a workaround for your problem when using the async API (the improvement will be available in 2.6.2 release) and JDK9+ (which brings the `orTimeout` method to CompletableFuture). 
   
   For the non-async API, I'd suggest creating a feature request for adding `batchReceive(int timeout, TimeUnit unit)` to `org.apache.pulsar.client.api.Consumer`. There's current `receive(int timeout, TimeUnit unit)` so it would make sense to have a similar method for `batchReceive`. I noticed that you have already created #7696 . However I think that having a timeout for batchReceive method is a new feature and is not something that should or is controlled by BatchReceivePolicy. Therefore creating a new feature request would be a way to proceed.


----------------------------------------------------------------
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:
users@infra.apache.org