Skip to content

Commit

Permalink
[ISSUE apache#3728] docs: Make the 'Uses of keys' entry in the docume…
Browse files Browse the repository at this point in the history
…nt 'Best practices' more complete. (apache#3729)
  • Loading branch information
XiaoyiPeng authored and 上河 committed Mar 3, 2022
1 parent 3bb3f9d commit 7df70f4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/en/best_practice.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7df70f4

Please sign in to comment.