From ae29fa2157bcffae2806cca71feaf3f64a920b62 Mon Sep 17 00:00:00 2001 From: XiaoyiPeng <644120242@qq.com> Date: Fri, 7 Jan 2022 16:31:28 +0800 Subject: [PATCH] [ISSUE #3728] docs: Make the 'Uses of keys' entry in the document 'Best practices' more complete. --- docs/en/best_practice.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/en/best_practice.md b/docs/en/best_practice.md index c50c5df415b..e9d0ee4e307 100755 --- a/docs/en/best_practice.md +++ b/docs/en/best_practice.md @@ -17,6 +17,19 @@ Since it is a hash index, make sure that the key is as unique as possible to avo String orderId = "20034568923546"; message.setKeys(orderId); ``` +If you have multiple keys for a message, please concatenate them with 'KEY_SEPARATOR' char, as shown below: +```java + // order id + String orderId = "20034568923546"; + String otherKey = "19101121210831"; + String keys = new StringBuilder(orderId) + .append(org.apache.rocketmq.common.message.MessageConst.KEY_SEPARATOR) + .append(otherKey).toString(); + message.setKeys(keys); +``` +And if you want to query the message, please use `orderId` and `otherKey` to query respectively instead of `keys`, +because the server will unwrap `keys` with `KEY_SEPARATOR` and create corresponding index. +In the above example, the server will create two indexes, one for `orderId` and one for `otherKey`. #### 3 Log print Print the message log when send success or failed, make sure to print the SendResult and key fields. Send messages is successful as long as it does not throw exception. Send successful will have multiple states defined in sendResult.