Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #3728] docs: Make the 'Uses of keys' entry in the document 'Best practices' more complete. #3729

Merged
merged 1 commit into from
Jan 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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