Allow Java client to create consumer with receiverQueueSize(0) when receiving with timeout
See original GitHub issueCurrently, 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
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
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)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Python consumer does not accept receiver_queue_size=0
Python client does not accept receiver queue size equal to 0, ... ConsumerImpl::receive(Message& msg, int timeout) not support.
Read more >ConsumerConfiguration (Pulsar Client Java 2.2.0 API)
Class specifying the configuration of a consumer. In Exclusive subscription, only a single consumer is allowed to attach to the subscription.
Read more >Apache Pulsar Client Application Best Practices - StreamNative
All client interactions are handled by a component in the Pulsar stack ... if an ackTimeout is provided - consumer.receive(500, TimeUnit.
Read more >Kafka Java Client | Confluent Documentation
Confluent Platform includes the Java producer and consumer shipped with Apache Kafka®. For a step-by-step guide on building a Java client application for...
Read more >Graceful shutdown of Pulsar queue consumers in Java and ...
In this article, we'll cover how to handle this for Apache Pulsar when using the Java client in a Spring Boot environment —but...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
when can implement some dummy loop that pools for a message for the given time, every X ms we call “receive”…
the user can do it by himself, but providing it out-of-the-box may be a good idea in order to provide user (developer) experience
Super, thx.