From bc173fd25560e12ba1e19b0661ad1a912e4d3857 Mon Sep 17 00:00:00 2001 From: Yunze Xu Date: Fri, 22 Mar 2024 18:50:20 +0800 Subject: [PATCH] Add Consumer.consumer_name() API (#206) Catch up for https://github.com/apache/pulsar-client-cpp/pull/360 --- pulsar/__init__.py | 6 ++++++ src/consumer.cc | 1 + tests/pulsar_test.py | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/pulsar/__init__.py b/pulsar/__init__.py index 9590fa3..fad33cd 100644 --- a/pulsar/__init__.py +++ b/pulsar/__init__.py @@ -1428,6 +1428,12 @@ def subscription_name(self): """ return self._consumer.subscription_name() + def consumer_name(self): + """ + Return the consumer name. + """ + return self._consumer.consumer_name() + def unsubscribe(self): """ Unsubscribe the current consumer from the topic. diff --git a/src/consumer.cc b/src/consumer.cc index 346673a..e32a865 100644 --- a/src/consumer.cc +++ b/src/consumer.cc @@ -112,6 +112,7 @@ void export_consumer(py::module_& m) { .def("topic", &Consumer::getTopic, "return the topic this consumer is subscribed to", py::return_value_policy::copy) .def("subscription_name", &Consumer::getSubscriptionName, py::return_value_policy::copy) + .def("consumer_name", &Consumer::getConsumerName, py::return_value_policy::copy) .def("unsubscribe", &Consumer_unsubscribe) .def("receive", &Consumer_receive) .def("receive", &Consumer_receive_timeout) diff --git a/tests/pulsar_test.py b/tests/pulsar_test.py index a3b97b6..bb62d99 100755 --- a/tests/pulsar_test.py +++ b/tests/pulsar_test.py @@ -1886,5 +1886,13 @@ def test_regex_subscription(self): client.close() + def test_consumer_name(self): + client = Client(self.serviceUrl) + name = 'my-consumer-name' + consumer = client.subscribe('test_consumer_name', 'sub', consumer_name=name) + self.assertEqual(consumer.consumer_name(), name) + client.close() + + if __name__ == "__main__": main()