From 1b5722d35a2cbce35d1d0843fa6a999da5feb583 Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 10 Dec 2022 17:01:10 +0800 Subject: [PATCH] [fix][doc] Avoid refer to deprecated classes (#18845) Signed-off-by: tison --- site2/docs/cookbooks-compaction.md | 23 ++++++---------- .../version-2.10.x/cookbooks-compaction.md | 27 ++++++------------- .../version-2.8.x/cookbooks-compaction.md | 27 ++++++------------- .../version-2.9.x/cookbooks-compaction.md | 27 ++++++------------- 4 files changed, 32 insertions(+), 72 deletions(-) diff --git a/site2/docs/cookbooks-compaction.md b/site2/docs/cookbooks-compaction.md index 561acd59bd81f..0c1807ec1c823 100644 --- a/site2/docs/cookbooks-compaction.md +++ b/site2/docs/cookbooks-compaction.md @@ -92,20 +92,16 @@ Consumer compactedTopicConsumer = client.newConsumer() As mentioned above, topic compaction in Pulsar works on a *per-key basis*. That means that messages that you produce on compacted topics need to have keys (the content of the key will depend on your use case). Messages that don't have keys will be ignored by the compaction process. Here's an example Pulsar message with a key: ```java -import org.apache.pulsar.client.api.Message; -import org.apache.pulsar.client.api.MessageBuilder; +import org.apache.pulsar.client.api.TypedMessageBuilder; -Message msg = MessageBuilder.create() - .setContent(someByteArray) - .setKey("some-key") - .build(); +TypedMessageBuilder msg = producer.newMessage() + .key("some-key") + .value(someByteArray); ``` The example below shows a message with a key being produced on a compacted Pulsar topic: ```java -import org.apache.pulsar.client.api.Message; -import org.apache.pulsar.client.api.MessageBuilder; import org.apache.pulsar.client.api.Producer; import org.apache.pulsar.client.api.PulsarClient; @@ -117,11 +113,8 @@ Producer compactedTopicProducer = client.newProducer() .topic("some-compacted-topic") .create(); -Message msg = MessageBuilder.create() - .setContent(someByteArray) - .setKey("some-key") - .build(); - -compactedTopicProducer.send(msg); +compactedTopicProducer.newMessage() + .key("some-key") + .value(someByteArray) + .send(); ``` - diff --git a/site2/website/versioned_docs/version-2.10.x/cookbooks-compaction.md b/site2/website/versioned_docs/version-2.10.x/cookbooks-compaction.md index 8e4ed064438c9..55fcb71176b48 100644 --- a/site2/website/versioned_docs/version-2.10.x/cookbooks-compaction.md +++ b/site2/website/versioned_docs/version-2.10.x/cookbooks-compaction.md @@ -109,23 +109,16 @@ Consumer compactedTopicConsumer = client.newConsumer() As mentioned above, topic compaction in Pulsar works on a *per-key basis*. That means that messages that you produce on compacted topics need to have keys (the content of the key will depend on your use case). Messages that don't have keys will be ignored by the compaction process. Here's an example Pulsar message with a key: ```java +import org.apache.pulsar.client.api.TypedMessageBuilder; -import org.apache.pulsar.client.api.Message; -import org.apache.pulsar.client.api.MessageBuilder; - -Message msg = MessageBuilder.create() - .setContent(someByteArray) - .setKey("some-key") - .build(); - +TypedMessageBuilder msg = producer.newMessage() + .key("some-key") + .value(someByteArray); ``` The example below shows a message with a key being produced on a compacted Pulsar topic: ```java - -import org.apache.pulsar.client.api.Message; -import org.apache.pulsar.client.api.MessageBuilder; import org.apache.pulsar.client.api.Producer; import org.apache.pulsar.client.api.PulsarClient; @@ -137,12 +130,8 @@ Producer compactedTopicProducer = client.newProducer() .topic("some-compacted-topic") .create(); -Message msg = MessageBuilder.create() - .setContent(someByteArray) - .setKey("some-key") - .build(); - -compactedTopicProducer.send(msg); - +compactedTopicProducer.newMessage() + .key("some-key") + .value(someByteArray) + .send(); ``` - diff --git a/site2/website/versioned_docs/version-2.8.x/cookbooks-compaction.md b/site2/website/versioned_docs/version-2.8.x/cookbooks-compaction.md index 8e4ed064438c9..55fcb71176b48 100644 --- a/site2/website/versioned_docs/version-2.8.x/cookbooks-compaction.md +++ b/site2/website/versioned_docs/version-2.8.x/cookbooks-compaction.md @@ -109,23 +109,16 @@ Consumer compactedTopicConsumer = client.newConsumer() As mentioned above, topic compaction in Pulsar works on a *per-key basis*. That means that messages that you produce on compacted topics need to have keys (the content of the key will depend on your use case). Messages that don't have keys will be ignored by the compaction process. Here's an example Pulsar message with a key: ```java +import org.apache.pulsar.client.api.TypedMessageBuilder; -import org.apache.pulsar.client.api.Message; -import org.apache.pulsar.client.api.MessageBuilder; - -Message msg = MessageBuilder.create() - .setContent(someByteArray) - .setKey("some-key") - .build(); - +TypedMessageBuilder msg = producer.newMessage() + .key("some-key") + .value(someByteArray); ``` The example below shows a message with a key being produced on a compacted Pulsar topic: ```java - -import org.apache.pulsar.client.api.Message; -import org.apache.pulsar.client.api.MessageBuilder; import org.apache.pulsar.client.api.Producer; import org.apache.pulsar.client.api.PulsarClient; @@ -137,12 +130,8 @@ Producer compactedTopicProducer = client.newProducer() .topic("some-compacted-topic") .create(); -Message msg = MessageBuilder.create() - .setContent(someByteArray) - .setKey("some-key") - .build(); - -compactedTopicProducer.send(msg); - +compactedTopicProducer.newMessage() + .key("some-key") + .value(someByteArray) + .send(); ``` - diff --git a/site2/website/versioned_docs/version-2.9.x/cookbooks-compaction.md b/site2/website/versioned_docs/version-2.9.x/cookbooks-compaction.md index 8e4ed064438c9..55fcb71176b48 100644 --- a/site2/website/versioned_docs/version-2.9.x/cookbooks-compaction.md +++ b/site2/website/versioned_docs/version-2.9.x/cookbooks-compaction.md @@ -109,23 +109,16 @@ Consumer compactedTopicConsumer = client.newConsumer() As mentioned above, topic compaction in Pulsar works on a *per-key basis*. That means that messages that you produce on compacted topics need to have keys (the content of the key will depend on your use case). Messages that don't have keys will be ignored by the compaction process. Here's an example Pulsar message with a key: ```java +import org.apache.pulsar.client.api.TypedMessageBuilder; -import org.apache.pulsar.client.api.Message; -import org.apache.pulsar.client.api.MessageBuilder; - -Message msg = MessageBuilder.create() - .setContent(someByteArray) - .setKey("some-key") - .build(); - +TypedMessageBuilder msg = producer.newMessage() + .key("some-key") + .value(someByteArray); ``` The example below shows a message with a key being produced on a compacted Pulsar topic: ```java - -import org.apache.pulsar.client.api.Message; -import org.apache.pulsar.client.api.MessageBuilder; import org.apache.pulsar.client.api.Producer; import org.apache.pulsar.client.api.PulsarClient; @@ -137,12 +130,8 @@ Producer compactedTopicProducer = client.newProducer() .topic("some-compacted-topic") .create(); -Message msg = MessageBuilder.create() - .setContent(someByteArray) - .setKey("some-key") - .build(); - -compactedTopicProducer.send(msg); - +compactedTopicProducer.newMessage() + .key("some-key") + .value(someByteArray) + .send(); ``` -