codelipenghui commented on a change in pull request #6065: [Issue 6056][docs] 
Add example on how to choose partition when using a key
URL: https://github.com/apache/pulsar/pull/6065#discussion_r369357166
 
 

 ##########
 File path: site2/docs/cookbooks-partitioned.md
 ##########
 @@ -72,6 +70,23 @@ Producer<byte[]> producer = pulsarClient.newProducer()
 producer.send("Partitioned topic message".getBytes());
 ```
 
-## Managing partitioned topics
+### How to choose partitions when using a key
+If a message has a key, it supersedes the round robin routing policy. The 
following example illustrates how to choose partition when you use a key.
 
-You can use Pulsar's [admin API](admin-api-overview.md) to create and manage 
[partitioned topics](admin-api-partitioned-topics.md).
+```java
+// If the message has a key, it supersedes the round robin routing policy
+        if (msg.hasKey()) {
+            return signSafeMod(hash.makeHash(msg.getKey()), 
topicMetadata.numPartitions());
 
 Review comment:
   ```suggestion
               return 
signSafeMod(Murmur3_32Hash.getInstance().makeHash(msg.getKey()), 
topicMetadata.numPartitions());
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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