From e8db9919d1f7a20b156d0a460ad0d879024c3d91 Mon Sep 17 00:00:00 2001 From: Fernando Rejon Barrera <39321865+frejonb@users.noreply.github.com> Date: Sun, 8 Dec 2019 12:57:54 +0100 Subject: [PATCH] [Issue 5811][pulsar-client-python]Expose redelivery count of message in python client (#5812) Fixes #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 --- pulsar-client-cpp/python/pulsar/__init__.py | 6 ++++++ pulsar-client-cpp/python/pulsar_test.py | 23 +++++++++++++++++++++ pulsar-client-cpp/python/src/message.cc | 1 + 3 files changed, 30 insertions(+) diff --git a/pulsar-client-cpp/python/pulsar/__init__.py b/pulsar-client-cpp/python/pulsar/__init__.py index 5fe82864f8f6c..c6b213d974239 100644 --- a/pulsar-client-cpp/python/pulsar/__init__.py +++ b/pulsar-client-cpp/python/pulsar/__init__.py @@ -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() diff --git a/pulsar-client-cpp/python/pulsar_test.py b/pulsar-client-cpp/python/pulsar_test.py index 3f8bc08de091f..14cf2938bc554 100755 --- a/pulsar-client-cpp/python/pulsar_test.py +++ b/pulsar-client-cpp/python/pulsar_test.py @@ -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') diff --git a/pulsar-client-cpp/python/src/message.cc b/pulsar-client-cpp/python/src/message.cc index 794a70e83d46d..f12c89ebe6804 100644 --- a/pulsar-client-cpp/python/src/message.cc +++ b/pulsar-client-cpp/python/src/message.cc @@ -138,6 +138,7 @@ void export_message() { .def("message_id", &Message_getMessageId, return_value_policy()) .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;