標籤:網路 node.js pubsub
參考資料
http://faye.jcoglan.com/
Faye is a publish-subscribe messaging system based on theBayeux protocol/CometD. It provides message servers forNode.js and Ruby, and clients for use on the server and in all major web browsers.
系統架構
|
組件 |
功能 |
|
Storage |
儲存內容
- 活躍client的id
- 訂閱資訊
- queued message to be delivered to clients
儲存方式
- memory engine
- redis engine
|
|
Engine |
Storage的抽象層,實現了Faye的所有服務
- client registering
- storing subscriptions
- routing messages
|
|
Server |
實現了Bayeus 協議,操作集
- handshake
- connect
- disconnect
- subscribe
- unsubscribe
- publish
Server無HTTP或其他任何網路傳輸技術有關 |
|
Server-side extendsions |
擴充層,可以攔截incoming/outgoing message |
|
Adapter |
通過HTTP提供Server的服務,負責以JSON方式序列化和還原序列化message;
串連處理
- 基於WebSocket的持久串連
- 基於HTTP POST的long polling
- CORS(Cross Origin Resource sharing)
- JSONP
兩個實現:NodeAdapter, RackAdapter |
|
Transport |
用戶端的network transport,負責通訊和JSON的序列化和還原序列化以及網路故障的檢測和恢複
- Websocket即時性強
- long polling / JSONP只能依賴逾時
|
|
client-side extensions |
類似於Server-side extendsions |
|
client |
提供subscribe/unsubscribe, send/receive message的介面,實現了Bayeux protocol,使用者不需要處理handshake 和 connect等底層操作 |
Cluster支援
這種結構中的Storage採用Redis。Server是無狀態,方便水平擴充,簡化路由(使用隨機/rr策略即可)。
使用簡單
使用類似socket.io。
Faye,Simple pub/sub messaging for the web