bry00 opened a new issue #10479:
URL: https://github.com/apache/pulsar/issues/10479


   Currently, consumer with `receiverQueueSize == 0` cannot be user when using 
`receive` with timeout (see sample code below).
   
   ## Suggested solution
   Remove this constraint (i.e. allow `receiverQueueSize == 0` when using 
`receive` with timeout) to facilitate usage cases of shared subscriptions with 
long term processing of the message.
   
   ## Sample code 
   ```java
   package sample;
   
   import org.apache.pulsar.client.api.*;
   import java.util.concurrent.TimeUnit;
   
   public class App {
       public static void main(String[] args) {
   
           try (PulsarClient client = 
PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build()) {
               try (Consumer consumer = 
client.newConsumer().topic("sample").subscriptionName("try")
                       .subscriptionType(SubscriptionType.Shared)
                       
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
                       .receiverQueueSize(0)
                       .subscribe()) {
                   Message msg;
                   while ((msg = consumer.receive(10, TimeUnit.SECONDS)) != 
null) {
                       var data = msg.getValue();
                       System.out.println("Received: " + data.toString());
                       consumer.acknowledge(msg);
                   }
               }
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
   }
   ```
   
   ## Error message
   
   ```log
   
org.apache.pulsar.client.api.PulsarClientException$InvalidConfigurationException:
 Can't use receive with timeout, if the queue size is 0
           at 
org.apache.pulsar.client.impl.ConsumerBase.receive(ConsumerBase.java:175)
           at sample.App.main(App.java:16)
   ```


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


Reply via email to