question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow Java client to create consumer with receiverQueueSize(0) when receiving with timeout

See original GitHub issue

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

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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
eolivellicommented, May 4, 2021

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

1reaction
bry00commented, May 11, 2021

2.7.1

Ok i will follow up the problem

Super, thx.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found