Skip to content

Commit

Permalink
Fix consumer of python queue size is zero (apache#5706)
Browse files Browse the repository at this point in the history
Fixes apache#5634


Master Issue: apache#5634

### Motivation

In java clients, when we call the `receive`, we will block it until a message arrives. in python clients, when we call the `receive` function, we add a delay parameter of 100ms. when the queue size is 0, the `receive` will have a strict check on the queue size, causing the following exception to be thrown

```
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
```
### Modifications

* Removing timeout parameter in synchronous `receive`
* Add test for queue size is 0

### Verifying this change

Add Test
  • Loading branch information
tuteng authored and sijie committed Nov 21, 2019
1 parent 39f37c9 commit fa02970
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 17 additions & 0 deletions pulsar-client-cpp/python/pulsar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ def test_consumer_initial_position(self):
consumer.unsubscribe()
client.close()

def test_consumer_queue_size_is_zero(self):
client = Client(self.serviceUrl)
consumer = client.subscribe('my-python-topic-consumer-init-queue-size-is-zero',
'my-sub',
consumer_type=ConsumerType.Shared,
receiver_queue_size=0,
initial_position=InitialPosition.Earliest)
producer = client.create_producer('my-python-topic-consumer-init-queue-size-is-zero')
producer.send(b'hello')
time.sleep(0.1)
msg = consumer.receive()
self.assertTrue(msg)
self.assertEqual(msg.data(), b'hello')

consumer.unsubscribe()
client.close()

def test_message_properties(self):
client = Client(self.serviceUrl)
topic = 'my-python-test-message-properties'
Expand Down
4 changes: 1 addition & 3 deletions pulsar-client-cpp/python/src/consumer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ Message Consumer_receive(Consumer& consumer) {

while (true) {
Py_BEGIN_ALLOW_THREADS
// Use 100ms timeout to periodically check whether the
// interpreter was interrupted
res = consumer.receive(msg, 100);
res = consumer.receive(msg);
Py_END_ALLOW_THREADS

if (res != ResultTimeout) {
Expand Down

0 comments on commit fa02970

Please sign in to comment.