Skip to content

Commit

Permalink
Add Consumer.consumer_name() API (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
BewareMyPower authored Mar 22, 2024
1 parent 2a8819d commit bc173fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pulsar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/consumer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tests/pulsar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit bc173fd

Please sign in to comment.