merlimat commented on a change in pull request #1181: Multi-topic subscription 
documentation
URL: https://github.com/apache/incubator-pulsar/pull/1181#discussion_r171361819
 
 

 ##########
 File path: site/docs/latest/clients/Java.md
 ##########
 @@ -215,6 +215,39 @@ CompletableFuture<Message> asyncMessage = 
consumer.receiveAsync();
 
 Async receive operations return a {% javadoc Message client 
org.apache.pulsar.client.api.Message %} wrapped in a 
[`CompletableFuture`](http://www.baeldung.com/java-completablefuture).
 
+### Multi-topic subscriptions
+
+In addition to subscribing a consumer to a single Pulsar topic, you can also 
subscribe to multiple topics simultaneously using [multi-topic 
subscriptions](../../getting-started/ConceptsAndArchitecture#multi-topic-subscriptions).
 To use multi-topic subscriptions:
+
+* All topics must be within the same Pulsar {% popover namespace %}
+* You must supply a regular expression (regex)
+
+Here are some examples:
+
+```java
+import java.util.regex.Pattern;
+
+import org.apache.pulsar.client.api.Consumer;
+import org.apache.pulsar.client.api.PulsarClient;
+
+PulsarClient pulsarClient = // Instantiate Pulsar client object
+
+// Subscribe to all topics in a namespace
+Pattern allTopicsInNamespace = 
Pattern.compile("persistent://sample/standalone/ns1/*");
+Consumer allTopicsConsumer = pulsarClient.subscribe(allTopicsInNamespace, 
"subscription-1");
 
 Review comment:
   This feature will only be avaialable through new conf builder API: 
   
   ```java
   Consumer allTopicsConsumer = pulsarClient.newConsumer()
                 .topicsPattern("persistent://sample/standalone/ns1/.*")
                 .subscriptionName("subscription-1")
                 .subscbribe();
   ```
   
   also there's a version with just a list of topics: 
   
   ```java
   List<String> topics = new ArrayList<>();
   topics.add("persistent://sample/standalone/ns1/topic-1");
   topics.add("persistent://sample/standalone/ns1/topic-2");
   
   Consumer allTopicsConsumer = pulsarClient.newConsumer()
                 .topics(topics)
                 .subscriptionName("subscription-1")
                 .subscbribe();
   ```
   
   or directly : 
   
   
   ```java
   Consumer allTopicsConsumer = pulsarClient.newConsumer()
                 .topic("persistent://sample/standalone/ns1/topic-1",
                        "persistent://sample/standalone/ns1/topic-2")
                 .subscriptionName("subscription-1")
                 .subscbribe();
   ```
   
   Also, with regex pattern, it will also refresh automatically the list of 
topic and subscribe to new topics that might pop up

----------------------------------------------------------------
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