You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2018/05/28 04:03:26 UTC

[incubator-pulsar] branch master updated: Fix message builder examples (#1848)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 5dcd5c4  Fix message builder examples (#1848)
5dcd5c4 is described below

commit 5dcd5c4396f2c608178a89980bfa7e49b172e480
Author: Luc Perkins <lu...@gmail.com>
AuthorDate: Sun May 27 21:03:19 2018 -0700

    Fix message builder examples (#1848)
    
    * fix deprecate MessageBuilder examples
    
    * use Arrays construct for list in geo-rep java example
---
 site/docs/latest/admin/GeoReplication.md | 19 +++++++++++--------
 site/docs/latest/clients/Java.md         | 15 +++++++++------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/site/docs/latest/admin/GeoReplication.md b/site/docs/latest/admin/GeoReplication.md
index dc344fa..4acc658 100644
--- a/site/docs/latest/admin/GeoReplication.md
+++ b/site/docs/latest/admin/GeoReplication.md
@@ -108,16 +108,19 @@ By default, messages are replicated to all clusters configured for the namespace
 Below is an example for the [Java API](../../clients/Java). Note the use of the `setReplicationClusters` method when constructing the {% javadoc Message client org.apache.pulsar.client.api.Message %} object:
 
 ```java
-List<String> restrictReplicationTo = new ArrayList<>;
-restrictReplicationTo.add("us-west");
-restrictReplicationTo.add("us-east");
+List<String> restrictReplicationTo = Arrays.asList(
+        "us-west",
+        "us-east"
+);
 
-Message message = MessageBuilder.create()
-        .setContent("my-payload".getBytes())
-        .setReplicationClusters(restrictReplicationTo)
-        .build();
+Producer producer = client.newProducer()
+        .topic("some-topic")
+        .create();
 
-producer.send(message);
+producer.newMessage()
+        .value("my-payload".getBytes())
+        .setReplicationClusters(restrictReplicationTo)
+        .send();
 ```
 
 #### Topic stats
diff --git a/site/docs/latest/clients/Java.md b/site/docs/latest/clients/Java.md
index 328e5ec..e5ee079 100644
--- a/site/docs/latest/clients/Java.md
+++ b/site/docs/latest/clients/Java.md
@@ -98,7 +98,7 @@ In Pulsar, {% popover producers %} write {% popover messages %} to {% popover to
 ```java
 String topic = "persistent://sample/standalone/ns1/my-topic";
 
-Producer producer<byte[]> = client.newProducer()
+Producer<byte[]> producer = client.newProducer()
         .topic(topic)
         .create();
 ```
@@ -106,18 +106,18 @@ Producer producer<byte[]> = client.newProducer()
 You can then send messages to the broker and topic you specified:
 
 ```java
-import org.apache.pulsar.client.api.MessageBuilder;
+import org.apache.pulsar.client.api.TypedMessageBuilder;
 
 import java.util.stream.IntStream;
 
-MessageBuilder<byte[]> msgBuilder = MessageBuilder.create();
+TypedMessageBuilder<byte[]> msgBuilder = producer.newMessage();
 
 // Publish 10 messages to the topic
 IntStream.range(1, 11).forEach(i -> {
-    msgBuilder.setContent(String.format("Message number %d", i).getBytes());
+    msgBuilder.value(String.format("Message number %d", i).getBytes());
 
     try {
-        producer.send(msgBuilder);
+        msgBuilder.send();
     } catch (PulsarClientException e) {
         e.printStackTrace();
     }
@@ -172,7 +172,10 @@ You can also publish messages [asynchronously](../../getting-started/ConceptsAnd
 Here's an example async send operation:
 
 ```java
-CompletableFuture<MessageId> future = producer.sendAsync("my-async-message".getBytes());
+TypedMessageBuilder<byte[]> msgBuilder = producer.newMessage()
+        .value("my-async-message".getBytes());
+
+CompletableFuture<MessageId> future = msgBuilder.sendAsync();
 future.thenAccept(msgId -> {
         System.out.printf("Message with ID %s successfully sent", new String(msgId.toByteArray());
 });

-- 
To stop receiving notification emails like this one, please contact
mmerli@apache.org.