Allow Java client to create consumer with receiverQueueSize(0) when receiving with timeout
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 142
Description
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)
```
Contributor guide
Research direction
Start at ConsumerBase.receive(ConsumerBase.java:175) and compare its validation with the sample's receiverQueueSize(0) and timed receive call. Trace the Java consumer tests or entry points that cover timed receiving, then verify that the sample scenario no longer raises InvalidConfigurationException and still receives and acknowledges messages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- distributed-systems
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100