From 304843ffd0390e9b29b6f35a76d8f4903612de45 Mon Sep 17 00:00:00 2001 From: hapihu Date: Thu, 6 Jun 2019 23:48:40 +0800 Subject: [PATCH] Update concepts-messaging.md (#4483) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update concepts-messaging.md Since the #1089,the interface 'org.apache.pulsar.client.api.PulsarClient' has supported builder for consumer and producer. And,int the #3272, some deprecated client API have been removed including 'public static PulsarClient create(String serviceUrl)','Consumer subscribe(String topic, String subscription)' and 'Producer createProducer(String topic)'. So, I modified the example with the current version of the interface. * Apply suggestions from code review Specify message schema Co-Authored-By: Matteo Merli --- site2/docs/concepts-messaging.md | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/site2/docs/concepts-messaging.md b/site2/docs/concepts-messaging.md index 6baf519ce52bc..659167d3a3202 100644 --- a/site2/docs/concepts-messaging.md +++ b/site2/docs/concepts-messaging.md @@ -220,11 +220,17 @@ PulsarClient pulsarClient = // Instantiate Pulsar client object // Subscribe to all topics in a namespace Pattern allTopicsInNamespace = Pattern.compile("persistent://public/default/.*"); -Consumer allTopicsConsumer = pulsarClient.subscribe(allTopicsInNamespace, "subscription-1"); +Consumer allTopicsConsumer = pulsarClient.newConsumer() + .topicsPattern(allTopicsInNamespace) + .subscriptionName("subscription-1") + .subscribe(); // Subscribe to a subsets of topics in a namespace, based on regex Pattern someTopicsInNamespace = Pattern.compile("persistent://public/default/foo.*"); -Consumer someTopicsConsumer = pulsarClient.subscribe(someTopicsInNamespace, "subscription-1"); +Consumer someTopicsConsumer = pulsarClient.newConsumer() + .topicsPattern(someTopicsInNamespace) + .subscriptionName("subscription-1") + .subscribe(); ``` For code examples, see: @@ -316,17 +322,24 @@ Producers and consumers can connect to non-persistent topics in the same way as Here's an example [Java consumer](client-libraries-java.md#consumers) for a non-persistent topic: ```java -PulsarClient client = PulsarClient.create("pulsar://localhost:6650"); +PulsarClient client = PulsarClient.builder() + .serviceUrl("pulsar://localhost:6650") + .build(); String npTopic = "non-persistent://public/default/my-topic"; String subscriptionName = "my-subscription-name"; -Consumer consumer = client.subscribe(npTopic, subscriptionName); +Consumer consumer = client.newConsumer() + .topic(npTopic) + .subscriptionName(subscriptionName) + .subscribe(); ``` Here's an example [Java producer](client-libraries-java.md#producer) for the same non-persistent topic: ```java -Producer producer = client.createProducer(npTopic); +Producer producer = client.newProducer() + .topic(npTopic) + .create(); ``` ## Message retention and expiry