这是一个参考faye的简单的pub/sub系统, 只实现服务端部分.
参考下图
握手,获取ClientId
使用clientId注册一个链接,如果已经有链接可以用于表示心跳
订阅一个channel
/^\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/
取消订阅一个channel
同/meta/subscribe
断开链接
暂时的方法是发送一个/meta/connect
请求表示心跳
参考examples目录下的例子
telnet 127.0.0.1 8001 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'.
发送handshake请求
[{"channel":"/meta/handshake","version":"1.0","supportedConnectionTypes":["tcp"],"id":"1"}]
handshake返回成功结果如下
[{"id":"1","channel":"/meta/handshake","successful":true,"version":"1.0","supportedConnectionTypes":["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process","tcp"],"clientId":"b8eefea0-a94b-11e5-8160-d558d3f94685","advice":{"reconnect":"retry","interval":0,"timeout":20000}}]
发送connect请求
[{"channel":"/meta/connect","clientId":"b8eefea0-a94b-11e5-8160-d558d3f94685","connectionType":"tcp","id":"2"}]
connect请求成功
{"id":"2","clientId":"b8eefea0-a94b-11e5-8160-d558d3f94685","channel":"/meta/connect","successful":true,"advice":{"reconnect":"retry","interval":0,"timeout":20000}}
发送subscribe请求订阅pong频道
[{"channel":"/meta/subscribe","clientId":"b8eefea0-a94b-11e5-8160-d558d3f94685","subscription":"/pong","id":"3"}]
subscribe请求成功
[{"id":"3","clientId":"b8eefea0-a94b-11e5-8160-d558d3f94685","channel":"/meta/subscribe","successful":true,"subscription":"/pong"}]
向pong频道发送消息
[{"channel":"/pong","data":{},"clientId":"b8eefea0-a94b-11e5-8160-d558d3f94685","id":"4"}]
收到来自pong频道的消息
[{"channel":"/pong","data":{},"id":"4"}]
取消订阅pong频道
[{"channel":"/meta/unsubscribe","clientId":"b8eefea0-a94b-11e5-8160-d558d3f94685","subscription":"/pong","id":"5"}]
向pong频道发送消息的POST请求
curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H -d '{"channel":"/pong","data":{}}' 'http://localhost:8000/bayeux'
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。