Skip to content

Python consumer does not accept receiver_queue_size=0 #5634

Closed

Description

@bry00

Describe the bug
Python client does not accept receiver queue size equal to 0, but according to documentation:

If you’d like to have tight control over message dispatching across consumers, set the consumers’ receiver queue size very low (potentially even to 0 if necessary).
while other clients (e.g. C++ and Java clients) accept receiver queue size equal to 0 and work according to documentation.

To Reproduce
Steps to reproduce the behavior:

  1. Run the following Python code:
#!/usr/bin/env python3
import sys
import pulsar

client = pulsar.Client('pulsar://localhost:6650')
consumer = client.subscribe('abcd', subscription_name='xyz',
    consumer_type=pulsar.ConsumerType.Shared,
    receiver_queue_size=0)

msg = consumer.receive()
print("Received message: %s" % msg.data(), flush=True)

consumer.acknowledge(msg)
client.close()
  1. See error

Expected behavior
Python client consumer API ( client.subscribe) should accept parameter receiver_queue_size=0 as described in documentation and as function correctly for other clients (C++, Java).

Screenshots

2019-11-12 15:11:57.331 INFO  Client:88 | Subscribing on Topic :abcd
2019-11-12 15:11:57.331 INFO  ConnectionPool:72 | Created connection for pulsar://localhost:6650
2019-11-12 15:11:57.333 INFO  ClientConnection:324 | [[::1]:51100 -> [::1]:6650] Connected to broker
2019-11-12 15:11:57.398 INFO  HandlerBase:52 | [persistent://public/default/abcd, xyz, 0] Getting connection from pool
2019-11-12 15:11:57.423 INFO  ConnectionPool:72 | Created connection for pulsar://cfc0ca6995fc:6650
2019-11-12 15:11:57.424 INFO  ClientConnection:326 | [[::1]:51101 -> [::1]:6650] Connected to broker through proxy. Logical broker: pulsar://cfc0ca6995fc:6650
2019-11-12 15:11:57.684 INFO  ConsumerImpl:170 | [persistent://public/default/abcd, xyz, 0] Created consumer on broker [[::1]:51101 -> [::1]:6650]
2019-11-12 15:11:57.684 WARN  ConsumerImpl:631 | [persistent://public/default/abcd, xyz, 0] Can't use this function if the queue size is 0
Traceback (most recent call last):
  File "tst.py", line 10, in <module>
    msg = consumer.receive()
  File "/python3.7/site-packages/pulsar/__init__.py", line 930, in receive
    msg = self._consumer.receive()
Exception: Pulsar error: InvalidConfiguration

Desktop (please complete the following information):

  • OS: macOS Catalina (v: 10.15.1)

Activity

  1. added
    type/bug
    on Nov 12, 2019
  2. jiazhai commented on Nov 14, 2019

    @jiazhai
    Member

    In Cpp, ConsumerImpl::receive(Message& msg) supports receiver_queue_size=0.
    but with timeout parameter, ConsumerImpl::receive(Message& msg, int timeout) not support.

    But in python, the methods both with and without timeout parameter, finally calls into
    ConsumerImpl::receive(Message& msg, int timeout).

    Message Consumer_receive(Consumer& consumer) {
        Message msg;
        Result res;
    
        while (true) {
            Py_BEGIN_ALLOW_THREADS
            // Use 100ms timeout to periodically check whether the
            // interpreter was interrupted
            res = consumer.receive(msg, 100);   < ====
            Py_END_ALLOW_THREADS
    
            if (res != ResultTimeout) {
                // In case of timeout we keep calling receive() to simulate a
                // blocking call until a message is available, while breaking
                // every once in a while to check the Python signal status
                break;
            }
    
            if (PyErr_CheckSignals() == -1) {
                PyErr_SetInterrupt();
                return msg;
            }
        }
    
        CHECK_RESULT(res);
        return msg;
    }
    
    Message Consumer_receive_timeout(Consumer& consumer, int timeoutMs) {
        Message msg;
        Result res;
        Py_BEGIN_ALLOW_THREADS
        res = consumer.receive(msg, timeoutMs);
        Py_END_ALLOW_THREADS
    
        CHECK_RESULT(res);
        return msg;
    }
    
  3. jiazhai commented on Nov 14, 2019

    @jiazhai
    Member

    @tuteng Not sure why python not call consumer.receive(msg)directly. Would you please help to take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions