899 B
899 B
Send / sync examples
Persist then enqueue then ACK
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
if frame.Command == protocol.CmdHeartbeat {
return writeHeartbeat(c, frame)
}
_ = pool.Submit(ctx, func() { router.Dispatch(ctx, frame) })
Sync
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.