Skip to content

Commit

Permalink
Fix broker return error code confuse when not set subscription name. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shibd authored Jun 21, 2023
1 parent 7cfe07c commit 0202218
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/ClientImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/ConsumerTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0202218

Please sign in to comment.