Skip to content

Commit 0202218

Browse files
authored
Fix broker return error code confuse when not set subscription name. (#289)
1 parent 7cfe07c commit 0202218

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/ClientImpl.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,14 @@ void ClientImpl::handleConsumerCreated(Result result, ConsumerImplBaseWeakPtr co
506506
}
507507
callback(result, Consumer(consumer));
508508
} else {
509-
callback(result, {});
509+
// In order to be compatible with the current broker error code confusion.
510+
// https://github.com/apache/pulsar/blob/cd2aa550d0fe4e72b5ff88c4f6c1c2795b3ff2cd/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerServiceException.java#L240-L241
511+
if (result == ResultProducerBusy) {
512+
LOG_ERROR("Failed to create consumer: SubscriptionName cannot be empty.");
513+
callback(ResultInvalidConfiguration, {});
514+
} else {
515+
callback(result, {});
516+
}
510517
}
511518
}
512519

tests/ConsumerTest.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,4 +1311,14 @@ TEST(ConsumerTest, testNegativeAckDeadlock) {
13111311
client.close();
13121312
}
13131313

1314+
TEST(ConsumerTest, testNotSetSubscriptionName) {
1315+
const std::string topic = "test-not-set-sub-name";
1316+
Client client{lookupUrl};
1317+
ConsumerConfiguration conf;
1318+
Consumer consumer;
1319+
ASSERT_EQ(ResultInvalidConfiguration, client.subscribe(topic, "", conf, consumer));
1320+
1321+
client.close();
1322+
}
1323+
13141324
} // namespace pulsar

0 commit comments

Comments
 (0)