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 b9c7219 Fix negative acknowledge on a message ID does not work (#180)
b9c7219 is described below
commit b9c72195fbc33f7ff06a7fd1af54da9ce5e44a8a
Author: Yunze Xu <[email protected]>
AuthorDate: Tue Dec 26 10:53:33 2023 +0800
Fix negative acknowledge on a message ID does not work (#180)
Fixes https://github.com/apache/pulsar-client-python/issues/178
### Motivation
https://github.com/apache/pulsar-client-python/pull/121 introduces a
regression that when `negative_acknowledge` accepts a message ID, the
underlying `acknowledgeAsync` method will be called.
### Modifications
Fix the `Consumer_negative_acknowledge_message_id` method and add the
test for negative acknowledging message IDs in `test_redelivery_count`.
---
src/consumer.cc | 3 ++-
tests/pulsar_test.py | 5 ++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/consumer.cc b/src/consumer.cc
index 67d2daa..346673a 100644
--- a/src/consumer.cc
+++ b/src/consumer.cc
@@ -64,7 +64,8 @@ void Consumer_negative_acknowledge(Consumer& consumer, const
Message& msg) {
}
void Consumer_negative_acknowledge_message_id(Consumer& consumer, const
MessageId& msgId) {
- waitForAsyncResult([&](ResultCallback callback) {
consumer.acknowledgeAsync(msgId, callback); });
+ Py_BEGIN_ALLOW_THREADS consumer.negativeAcknowledge(msgId);
+ Py_END_ALLOW_THREADS
}
void Consumer_acknowledge_cumulative(Consumer& consumer, const Message& msg) {
diff --git a/tests/pulsar_test.py b/tests/pulsar_test.py
index 839ec3e..1872e0f 100755
--- a/tests/pulsar_test.py
+++ b/tests/pulsar_test.py
@@ -286,7 +286,10 @@ class PulsarTest(TestCase):
for i in range(4):
msg = consumer.receive(TM)
print("Received message %s" % msg.data())
- consumer.negative_acknowledge(msg)
+ if i % 2 == 0:
+ consumer.negative_acknowledge(msg)
+ else:
+ consumer.negative_acknowledge(msg.message_id())
redelivery_count = msg.redelivery_count()
self.assertTrue(msg)