/mim

A toy im

Primary LanguageGo

简介

参考一套海量在线用户的移动端IM架构设计实践分享(含详细图文), 使用Go实现的一个玩具im

架构


                          +----------+
                          |  client  |
                          |          |
                          +---+--+---+
                              |  ^     websocket
                              v  |
          +-------------------+--+-------------------+
          |                                          |
          |   +-------------+       +-------------+  |
gateway   |   |             |       |             |  |
          |   |  websocket  |       |    push     |  |
          |   |             |       |             |  |
          |   |             |       |             |  |
          |   +-------------+       +-------------+  |
          |                                          |
          +-------+-+---------------------+---+------+
                  | ^                     ^   |
                  | | grpc                |   |  grpc
                  | |                     |   |
                  v |                     |   v
          +-------+-+---------------------+---+------+
          |                                          |
          |  +---------+   +----------+  +---------+ |
          |  |         |   |          |  |         | |
          |  |  auth   |   |   c2c    |  |   c2g   | |
 logic    |  |         |   |          |  |         | |
          |  |         |   |          |  |         | |
          |  +---------+   +----------+  +---------+ |
          |                                          |
          +------------------------------------------+
                              |  ^     
                              v  |
          +-------------------+--+-------------------+
          |                                          |
          |   +-------------+       +-------------+  |
 storage  |   |             |       |             |  |
          |   |    cache    |       |     db      |  |
          |   |             |       |             |  |
          |   |             |       |             |  |
          |   +-------------+       +-------------+  |
          |                                          |
          +-------+-+---------------------+---+------+

gateway和logic都是无状态的,可以水平扩展, gateway负责处理客户端长连接,解析网络包分发给不同的logic server, logic server负责处理业务逻辑,将消息存储到存储层。push server负责推送实时消息。

功能

  • 单聊
  • 群聊
  • 服务端推送
  • 离线消息

使用

启动logic服务

make logic

启动gate服务

make gate

启动web端

git clone https://github.com/RainJoe/mimweb
cd mimweb
npm run serve

TODO

  • 实现tcp网关和http网关
  • 服务发现与负载均衡(包括gateway和内部的rpc服务)
  • 数据库分库分表中间件DBProxy