apache / pulsar-client-python

Apache Pulsar Python client library
https://pulsar.apache.org/
Apache License 2.0
49 stars 38 forks source link

Reader.has_message_available() returns True even if no messages to consume, when start_message_id is earliest #199

Closed adamdelezuch89 closed 4 months ago

adamdelezuch89 commented 5 months ago

Hi, Reader.has_message_available() returns True on first execution, even if no message available on topic. Issue is only, when reader is created with start_message_id=pulsar.MessageId.earliest,

Environment: Python 3.11.5 pulsar-client 3.4.0

Reproduction

  1. Create reader with start_message_id=pulsar.MessageId.earliest:
    
    from my_schemas import Schema
    import pulsar

pulsar_url = "localhost" topic = "tenant/namespace/topic" name = "name" schema = pulsar.schema.AvroSchema(Schema)

client = pulsar.Client(pulsar_url)

reader = client.create_reader( topic=topic, start_message_id=pulsar.MessageId.earliest, schema=schema, reader_name=name, )

2. Seek MessageId.latest or timestamp after point, where is no more messages

reader.seek(pulsar.MessageId.latest)

3. read messages until no more messages available

while reader.has_message_available(): # It is True on first iteration but should be False msg = reader.read_next(timeout_millis=5000)

print("No more messages")


At point 3 I should get info log "No more messages", but I got Timeout exception.
BewareMyPower commented 4 months ago

It's a bug of C++ client, I will fix it ASAP.

BewareMyPower commented 4 months ago

The fix https://github.com/apache/pulsar-client-cpp/pull/409 is included in the C++ client 3.5.0.