-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# 消息队列 | ||
|
||
技术选型:`Redis Stream` | ||
|
||
## Web to Worker | ||
|
||
Startup: | ||
|
||
```bash | ||
# 若相应的 stream 不存在,会自动创建 | ||
XGROUP CREATE build worker_group 0 MKSTREAM | ||
XGROUP CREATE manual_match worker_group 0 MKSTREAM | ||
XGROUP CREATE auto_match worker_group 0 MKSTREAM | ||
``` | ||
|
||
Send message: | ||
|
||
```bash | ||
# 若相应的 stream 不存在,会自动创建 | ||
# type: game_logic / ai | ||
XADD build * type <type> id <id> | ||
XADD manual_match * id <match_id> | ||
XADD auto_match * id <match_id> | ||
``` | ||
|
||
Read message: | ||
|
||
```bash | ||
# 若相应名字的 consumer 不存在,会自动在 group 中创建 | ||
# BLOCK 0 表示永久阻塞,直到有消息到达 | ||
XREADGROUP GROUP worker_group <consumer_name> COUNT 1 BLOCK 0 STREAMS build manual_match auto_match > | ||
``` | ||
|
||
Ack message: | ||
|
||
```bash | ||
# stream: build / manual_match / auto_match | ||
XACK <stream> worker_group <message_id> | ||
``` | ||
|
||
## Worker to Web | ||
|
||
Send message: | ||
|
||
```bash | ||
XADD match_result * id <match_id> replay <replay> | ||
``` | ||
|
||
Read message: | ||
|
||
```bash | ||
XREAD BLOCK 0 STREAMS match_result > | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters