Skip to content

Commit

Permalink
When topic does not exist, optimize the prompt message (#10845)
Browse files Browse the repository at this point in the history
### Motivation
If we set enableRetry=true, the client will subscribe to the retry topic.
If we set AllowAutoTopicCreation=false, the client will receive `Topic dose not exists`, which means that the retry Topic does not exists.
This makes users very confused. My topic clearly exists, why is it still prompted like this?
Therefore, the prompt information is improved to facilitate users to troubleshoot problems.

### Modifications
add topic name to the returning message
  • Loading branch information
315157973 committed Jun 8, 2021
1 parent cb79032 commit e72a0d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,8 @@ protected void handleSubscribe(final CommandSubscribe subscribe) {
.thenCompose(optTopic -> {
if (!optTopic.isPresent()) {
return FutureUtil
.failedFuture(new TopicNotFoundException("Topic does not exist"));
.failedFuture(new TopicNotFoundException(
"Topic " + topicName + " does not exist"));
}

Topic topic = optTopic.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4051,6 +4051,27 @@ public void testAccessAvroSchemaMetadata(Schema<MyBean> schema) throws Exception
assertEquals(1, res.getFields().size());
}

@Test
public void testTopicDoesNotExists() throws Exception {
cleanup();
conf.setAllowAutoTopicCreation(false);
setup();
String topic = "persistent://my-property/my-ns/none" + UUID.randomUUID();
admin.topics().createPartitionedTopic(topic, 3);
try {
@Cleanup
Consumer<byte[]> consumer = pulsarClient.newConsumer()
.enableRetry(true)
.topic(topic).subscriptionName("sub").subscribe();
fail("should fail");
} catch (Exception e) {
String retryTopic = topic + "-sub-RETRY";
assertTrue(e.getMessage().contains("Topic " + retryTopic + " does not exist"));
} finally {
conf.setAllowAutoTopicCreation(true);
}
}

/**
* Test validates that consumer of partitioned-topic utilizes threads of all partitioned-consumers and slow-listener
* of one of the partition doesn't impact listener-processing of other partition.
Expand Down

0 comments on commit e72a0d8

Please sign in to comment.