This is an automated email from the ASF dual-hosted git repository.
xyz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-client-python.git
The following commit(s) were added to refs/heads/main by this push:
new bc173fd Add Consumer.consumer_name() API (#206)
bc173fd is described below
commit bc173fd25560e12ba1e19b0661ad1a912e4d3857
Author: Yunze Xu <[email protected]>
AuthorDate: Fri Mar 22 18:50:20 2024 +0800
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 @@ class Consumer:
"""
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 @@ class PulsarTest(TestCase):
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()