pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] merlimat commented on a change in pull request #2972: Introduce `Client.getPartitionsForTopic()`
Date Mon, 12 Nov 2018 20:57:04 GMT
merlimat commented on a change in pull request #2972: Introduce `Client.getPartitionsForTopic()`
URL: https://github.com/apache/pulsar/pull/2972#discussion_r232808777
 
 

 ##########
 File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientImpl.java
 ##########
 @@ -805,6 +807,22 @@ public void reloadLookUp() throws PulsarClientException {
         return metadataFuture;
     }
 
+    @Override
+    public CompletableFuture<List<String>> getPartitionsForTopic(String topic)
{
+        return getPartitionedTopicMetadata(topic).thenApply(metadata -> {
+            if (metadata.partitions > 1) {
+                TopicName topicName = TopicName.get(topic);
+                List<String> partitions = new ArrayList<>(metadata.partitions);
+                for (int i = 0; i < metadata.partitions; i++) {
+                    partitions.add(topicName.getPartition(i).toString());
+                }
+                return partitions;
+            } else {
+                return Collections.singletonList(topic);
 
 Review comment:
   If we give exception here, we're forcing an application to handle both cases. 
   
   Eg: I want to create a reader on a topic, I don't know if it's partitioned or not: 
   
   ```java
   client.getPartitionsForTopic("my-topic")
      .join()
      .forEach(partition -> client.newReader().topic(partition).create());
   ```
   
   If `getPartitionsForTopic()` returns error, application would always have to differentiate
between the 2 cases.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message