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.