merlimat closed pull request #1848: Fix message builder examples
URL: https://github.com/apache/incubator-pulsar/pull/1848
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/site/docs/latest/admin/GeoReplication.md 
b/site/docs/latest/admin/GeoReplication.md
index dc344fa957..4acc658c27 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 328e5ec29f..e5ee079c5d 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());
 });


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to