PON chat-service — Luồng một tin nhắn thường (gửi → lưu → phát realtime → thông báo)

PON chat-service — Luồng một tin nhắn thường (gửi → lưu → phát realtime → thông báo) A workflow diagram generated by Archify. 01 / Người dùng · Web / Flutter 02 / chat-service · cổng STOMP / JWT (:8080) EX / Nhánh từ chối 04 / chat-service · xử lý tin 05 / MongoDB · GridFS 06 / Redis 07 / chat-service · phát & thông báo 08 / Bên ngoài: FCM · ai-service · Bot Factory Kết nối & nhận frame Kiểm tra · lưu Mongo Phát realtime · thông báo Gửi tin · mobile STOMP · web REST · Người dùng · Web / Flutter › Kết nối & nhận frame · /app/chat.send · POST /api/messages Gửi tin mobile STOMP · web REST /app/chat.send · POST /api/messages Nhận tin · /topic/conversation/{id} · Người dùng · Web / Flutter › Phát realtime · thông báo · patch cache, không refetch Nhận tin /topic/conversation/{id} patch cache, không refetch Xác thực · STOMP CONNECT · REST filter · chat-service · cổng STOMP / JWT (:8080) › Kết nối & nhận frame · SEND chỉ /app/** Xác thực STOMP CONNECT · REST filter SEND chỉ /app/** RateLimiter · 10 tin / 5s mỗi user · chat-service · cổng STOMP / JWT (:8080) › Kết nối & nhận frame · Redis INCR+EXPIRE atomic RateLimiter 10 tin / 5s mỗi user Redis INCR+EXPIRE atomic Lọc chiều ra · drop nếu hết là member · chat-service · cổng STOMP / JWT (:8080) › Phát realtime · thông báo · cache 10s · invalidate Redis Lọc chiều ra drop nếu hết là member cache 10s · invalidate Redis STOMP ERROR · JWT · session · dest cấm · Nhánh từ chối › Kết nối & nhận frame · đóng socket STOMP ERROR JWT · session · dest cấm đóng socket Từ chối tin · RATE_LIMITED · REJECTED · Nhánh từ chối › Kiểm tra · lưu Mongo · chỉ người gửi thấy Từ chối tin RATE_LIMITED · REJECTED chỉ người gửi thấy UploadController · POST /api/uploads · chat-service · xử lý tin › Kết nối & nhận frame · ext · size · magic bytes UploadController POST /api/uploads ext · size · magic bytes ChatController · /app/chat.send · chat-service · xử lý tin › Kết nối & nhận frame · REST: MessageController ChatController /app/chat.send REST: MessageController MessageService · member · type · block · reply · chat-service · xử lý tin › Kiểm tra · lưu Mongo · sendMessage MessageService member · type · block · reply sendMessage ClusterMessageBroker · thay SimpMessagingTemplate · chat-service · xử lý tin › Kiểm tra · lưu Mongo · Redis lỗi → phát local ClusterMessageBroker thay SimpMessagingTemplate Redis lỗi → phát local GridFS · file key UUID ngẫu nhiên · MongoDB · GridFS › Kết nối & nhận frame · GET public · nosniff · sandbox GridFS file key UUID ngẫu nhiên GET public · nosniff · sandbox MongoDB · messages · lastMessage · MongoDB · GridFS › Kiểm tra · lưu Mongo · $set atomic · evict cache MongoDB messages · lastMessage $set atomic · evict cache Redis pub/sub · stomp:broadcast · Redis › Kiểm tra · lưu Mongo · mọi instance đều nhận Redis pub/sub stomp:broadcast mọi instance đều nhận Presence · user:status TTL 5 phút · Redis › Phát realtime · thông báo · touch mỗi frame STOMP Presence user:status TTL 5 phút touch mỗi frame STOMP MessageNotification · NEW_MESSAGE · MENTIONED_YOU · chat-service · phát & thông báo › Kiểm tra · lưu Mongo · /user/queue/notifications MessageNotification NEW_MESSAGE · MENTIONED_YOU /user/queue/notifications BroadcastListener · → SimpleBroker local · chat-service · phát & thông báo › Phát realtime · thông báo · batch giữ thứ tự BroadcastListener → SimpleBroker local batch giữ thứ tự Trợ lý · @AI → ai-service · bot 1-1 · Bên ngoài: FCM · ai-service · Bot Factory › Kết nối & nhận frame · xem sơ đồ Module A Trợ lý @AI → ai-service · bot 1-1 xem sơ đồ Module A FCM push · offline · chưa mute · Bên ngoài: FCM · ai-service · Bot Factory › Kiểm tra · lưu Mongo · token chết → xoá FCM push offline · chưa mute token chết → xoá PUBLISH envelope đọc user:status STOMP SEND / POST kèm file từ chối offline, chưa mute toUser qua ClusterMessageBroker MessageResponse save + lastMessage không member · type · block quá 10 / 5s đạt SUBSCRIBE frame /topic text + @AI / bot 1-1 async fan-out sendMessage store url → tin image/file Bearer JWT Legend User UI Agent logic Policy Tool action Context / trace Cloud service External system