34 lines
899 B
Markdown
34 lines
899 B
Markdown
# Send / sync examples
|
|
|
|
## Persist then enqueue then ACK
|
|
|
|
```go
|
|
msg.ID, err = idgen.NextMsgID()
|
|
if err != nil { return nil, err }
|
|
if err := repo.Create(ctx, msg); err != nil { return nil, err }
|
|
if err := convRepo.UpdateLastMsg(ctx, msg.ConversationID, msg.ID, now); err != nil { return nil, err }
|
|
if err := deliver.Push(ctx, &deliver.Job{MsgID: msg.ID, ExcludeDevice: req.DeviceID}); err != nil {
|
|
return nil, err // no SEND_ACK
|
|
}
|
|
return &SendResponse{MsgID: msg.ID, ClientMsgID: req.ClientMsgID, ServerTimeMS: now}, nil
|
|
```
|
|
|
|
## EventLoop submit
|
|
|
|
```go
|
|
if frame.Command == protocol.CmdHeartbeat {
|
|
return writeHeartbeat(c, frame)
|
|
}
|
|
_ = pool.Submit(ctx, func() { router.Dispatch(ctx, frame) })
|
|
```
|
|
|
|
## Sync
|
|
|
|
```sql
|
|
SELECT * FROM messages
|
|
WHERE conversation_id = ? AND id > ?
|
|
ORDER BY id ASC LIMIT 200;
|
|
```
|
|
|
|
Inbox sync reads Redis ZSET by `dialog_score`, then mailbox events by `mailbox_seq`.
|