Skip to content

centrifugo

centrifugo v3.1.1

centrifugo 具备的关键能力:

  • pubsub模型
  • 订阅模型
  • 支持通过配置达到1人仅能连入1个连接的能力
  • 内置支持 presence 能力
  • 内置支持 join/leave 事件通知

特殊定制点

线上考虑采用 redis engine来扩容和实现centrifugo的HA能力。

同时,因为centrifugo无法支持离线通知(offline webhook) docs

Does Centrifugo support webhooks?

Proxy feature allows integrating Centrifugo with your session mechanism (via connect proxy) and provides a way to react to connection events (rpc, subscribe, publish). Also, it opens a road for bidirectional communication with RPC calls.

A tricky thing is disconnects hooks. **Centrifugo does not support them**.

但是,实际上房间的client是可以通过收取join/leave事件完全了解到所有在线情况。

考虑通过使用定制办法,监听redis来实现后端的 join/leave 侦听能力。

进入房间换token的交互过程

当前,为了方便特权用户能接收审核消息,不再直接使用 cent 的自身鉴权,而是使用 cent 的proxy鉴权。

即,通过配置 cent 的 proxy_connect_endpoint: http://live-lemon-api/local_hook/im/connect

指定 centrifugo 每次接收到连接请求,同步请求 lemon api,由 lemon api 指定附加的 channel.

{
  "result": {
    "channels": ["audit:100000"],
    "data": {
      "Nickname": "西门吹灯",
      "Username": "teacher1",
      "LoginIp": "172.18.0.1",
      "Avatar": "",
      "HasRole": true
    },
    "info": {
      "Nickname": "西门吹灯",
      "Username": "teacher1",
      "LoginIp": "172.18.0.1",
      "Avatar": "",
      "HasRole": true
    },
    "user": "10000022"
  }
}

centrifugo 收到 此应答,会自动完成 channel 订阅。