diff --git a/pulsar/__init__.py b/pulsar/__init__.py index 96d80d9..f1f2b87 100644 --- a/pulsar/__init__.py +++ b/pulsar/__init__.py @@ -1398,6 +1398,7 @@ def my_listener(consumer, message): conf = _pulsar.ConsumerConfiguration() conf.consumer_type(consumer_type) conf.regex_subscription_mode(regex_subscription_mode) + conf.pattern_auto_discovery_period(pattern_auto_discovery_period) conf.read_compacted(is_read_compacted) if message_listener: conf.message_listener(_listener_wrapper(message_listener, schema)) diff --git a/tests/pulsar_test.py b/tests/pulsar_test.py index 68eb499..d830076 100755 --- a/tests/pulsar_test.py +++ b/tests/pulsar_test.py @@ -1366,11 +1366,9 @@ def test_topics_pattern_consumer(self): doHttpPut(url1, "2") doHttpPut(url2, "3") - doHttpPut(url3, "4") producer1 = client.create_producer(topic1) producer2 = client.create_producer(topic2) - producer3 = client.create_producer(topic3) consumer = client.subscribe( re.compile(topics_pattern), @@ -1378,10 +1376,16 @@ def test_topics_pattern_consumer(self): consumer_type=ConsumerType.Shared, receiver_queue_size=10, pattern_auto_discovery_period=1, + initial_position=InitialPosition.Earliest, ) - # wait enough time to trigger auto discovery - time.sleep(2) + # topic3 is created after the subscription, so the consumer can only get it through auto discovery. + # Expected: found about 1 second after the subscription since pattern_auto_discovery_period=1. Before + # the fix the period was never applied, so the C++ default of 60 seconds was used (issue 171). + # There is no fixed sleep: the receive() calls below wait up to TM (10 seconds) for each message, + # which is far below 60 seconds, so the test still times out without the fix. + doHttpPut(url3, "4") + producer3 = client.create_producer(topic3) for i in range(100): producer1.send(b"hello-1-%d" % i)