Skip to content

Commit

Permalink
[Issue 5811][pulsar-client-python]Expose redelivery count of message …
Browse files Browse the repository at this point in the history
…in python client (apache#5812)

Fixes apache#5811 

### Modifications

Added redelivery count method to message class

### Verifying this change

This change added tests and can be verified as follows:
  - Added python test for redelivery count
  • Loading branch information
frejonb authored and jiazhai committed Dec 8, 2019
1 parent 90944f1 commit e8db991
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pulsar-client-cpp/python/pulsar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ def topic_name(self):
"""
return self._message.topic_name()

def redelivery_count(self):
"""
Get the redelivery count for this message
"""
return self._message.redelivery_count()

@staticmethod
def _wrap(_message):
self = Message()
Expand Down
23 changes: 23 additions & 0 deletions pulsar-client-cpp/python/pulsar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,29 @@ def test_producer_consumer(self):
consumer.unsubscribe()
client.close()

def test_redelivery_count(self):
client = Client(self.serviceUrl)
consumer = client.subscribe('my-python-topic-redelivery-count',
'my-sub',
consumer_type=ConsumerType.Shared,
negative_ack_redelivery_delay_ms=500)
producer = client.create_producer('my-python-topic-redelivery-count')
producer.send(b'hello')

redelivery_count = 0
for i in range(4):
msg = consumer.receive(TM)
print("Received message %s" % msg.data())
consumer.negative_acknowledge(msg)
redelivery_count = msg.redelivery_count()

self.assertTrue(msg)
self.assertEqual(msg.data(), b'hello')
self.assertEqual(3, redelivery_count)
consumer.unsubscribe()
producer.close()
client.close()

def test_consumer_initial_position(self):
client = Client(self.serviceUrl)
producer = client.create_producer('my-python-topic-producer-consumer')
Expand Down
1 change: 1 addition & 0 deletions pulsar-client-cpp/python/src/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void export_message() {
.def("message_id", &Message_getMessageId, return_value_policy<copy_const_reference>())
.def("__str__", &Message_str)
.def("topic_name", &Topic_name_str)
.def("redelivery_count", &Message::getRedeliveryCount)
;

MessageBatch& (MessageBatch::*MessageBatchParseFromString)(const std::string& payload, uint32_t batchSize) = &MessageBatch::parseFrom;
Expand Down

0 comments on commit e8db991

Please sign in to comment.