该库定义了必须通过各种传输(Websocket、SockJS)发送的自定义协议和消息类型。服务器客户端在内部使用该协议,并为特性提供简单的API——建立持久连接、订阅通道、调用RPC命令等等。
./centrifugo genconfig生成配置文件 config.json
./centrifugo genconfig -c config.yaml
./centrifugo checkconfig --config=config.yaml
./centrifugo --config=config.yaml
最简单的配置只需要两个字段secret和api_key
Some of the most important options you can configure when running Centrifugo:
address – bind your Centrifugo to specific interface address (by default “”)
port – port to bind Centrifugo to (by default 8000)
engine – engine to use - memory or redis (by default memory). Read more about engines in special chapter.
./centrifugo --config=config.yaml --address=127.0.0.1 --port=8000 --engine=redis --redis_host=127.0.0.1 --redis_port=6379
{
“debug”: true,
“port”: 900,
“secret”: “my-secret-key”,
“api_key”: “secret-api-key”,
“anonymous”: true,
“publish”: true,
“subscribe_to_publish”: true,
“presence”: true,
“join_leave”: true,
“history_size”: 10,
“history_lifetime”: 300,
“history_recover”: true
}
默认三个可用的端点
原始websocket
ws://localhost:8000/connection/websocket
然后是SockJS端点——它需要服务使用SockJS库的客户端连接:http://localhost:8000/connection/sockjs
最后,您还有API端点来发布消息到通道(并执行其他可用的API命令):
http://localhost:8000/api
debug
http://localhost:8000/debug/pprof/
https://godoc.org/github.com/centrifugal/centrifuge-go
https://godoc.org/github.com/centrifugal/gocent
https://github.com/centrifugal/centrifuge-js