sijie commented on a change in pull request #1269: Issue #1237: support builder 
for topicsConsumer
URL: https://github.com/apache/incubator-pulsar/pull/1269#discussion_r169899089
 
 

 ##########
 File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerBuilderImpl.java
 ##########
 @@ -77,22 +81,51 @@ public Consumer subscribe() throws PulsarClientException {
 
     @Override
     public CompletableFuture<Consumer> subscribeAsync() {
-        if (topicName == null) {
+        if (topicNames == null || topicNames.isEmpty()) {
             return FutureUtil
-                    .failedFuture(new IllegalArgumentException("Topic name 
must be set on the producer builder"));
+                    .failedFuture(new IllegalArgumentException("Topic name 
must be set on the consumer builder"));
         }
 
         if (subscriptionName == null) {
             return FutureUtil.failedFuture(
-                    new IllegalArgumentException("Subscription name must be 
set on the producer builder"));
+                    new IllegalArgumentException("Subscription name must be 
set on the consumer builder"));
         }
 
-        return client.subscribeAsync(topicName, subscriptionName, conf);
+        if (topicNames.size() == 1) {
+            return client.subscribeAsync(topicNames.get(0), subscriptionName, 
conf);
+        } else {
+            return client.subscribeAsync(topicNames, subscriptionName, conf);
+        }
     }
 
     @Override
-    public ConsumerBuilder topic(String topicName) {
-        this.topicName = topicName;
+    public ConsumerBuilder topic(String... topicNames) {
+        checkArgument(topicNames.length > 0, "Passed in topicNames should not 
be empty.");
+        if (this.topicNames == null) {
+            this.topicNames = Lists.newArrayList();
+        }
+
+        for (int i = 0; i < topicNames.length; i++) {
+            if (!this.topicNames.contains(topicNames[i])) {
+                this.topicNames.add(topicNames[i]);
+            }
+        }
+        return this;
+    }
+
+    @Override
+    public ConsumerBuilder topics(List<String> topicNames) {
+        checkArgument(topicNames != null && !topicNames.isEmpty(),
+            "Passed in topicNames list should not be empty.");
+        if (this.topicNames == null) {
+            this.topicNames = topicNames;
+        } else {
+            topicNames.forEach(name -> {
 
 Review comment:
   this.topicNames.addAll(topicNames)

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to