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-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new 0202218 Fix broker return error code confuse when not set
subscription name. (#289)
0202218 is described below
commit 020221828721dd6b3a8d79b288e0525398db286e
Author: Baodi Shi <[email protected]>
AuthorDate: Wed Jun 21 14:58:41 2023 +0800
Fix broker return error code confuse when not set subscription name. (#289)
---
lib/ClientImpl.cc | 9 ++++++++-
tests/ConsumerTest.cc | 10 ++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/lib/ClientImpl.cc b/lib/ClientImpl.cc
index e7b6aa4..c94434e 100644
--- a/lib/ClientImpl.cc
+++ b/lib/ClientImpl.cc
@@ -506,7 +506,14 @@ void ClientImpl::handleConsumerCreated(Result result,
ConsumerImplBaseWeakPtr co
}
callback(result, Consumer(consumer));
} else {
- callback(result, {});
+ // In order to be compatible with the current broker error code
confusion.
+ //
https://github.com/apache/pulsar/blob/cd2aa550d0fe4e72b5ff88c4f6c1c2795b3ff2cd/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerServiceException.java#L240-L241
+ if (result == ResultProducerBusy) {
+ LOG_ERROR("Failed to create consumer: SubscriptionName cannot be
empty.");
+ callback(ResultInvalidConfiguration, {});
+ } else {
+ callback(result, {});
+ }
}
}
diff --git a/tests/ConsumerTest.cc b/tests/ConsumerTest.cc
index 9f28dfb..98c11cf 100644
--- a/tests/ConsumerTest.cc
+++ b/tests/ConsumerTest.cc
@@ -1311,4 +1311,14 @@ TEST(ConsumerTest, testNegativeAckDeadlock) {
client.close();
}
+TEST(ConsumerTest, testNotSetSubscriptionName) {
+ const std::string topic = "test-not-set-sub-name";
+ Client client{lookupUrl};
+ ConsumerConfiguration conf;
+ Consumer consumer;
+ ASSERT_EQ(ResultInvalidConfiguration, client.subscribe(topic, "", conf,
consumer));
+
+ client.close();
+}
+
} // namespace pulsar