1

おそらく非常に基本的な質問ですが、私が達成しようとしているのは、socket.io を使用するリアルタイム機能を備えた Web アプリケーションと、テール可能なカーソルを備えた mongodb キャップ コレクションです (通常の mongodb コレクションは永続データにも使用されます)。

ここでは、アプリケーションがルーム、複数のユーザー、およびメッセージが飛び交うオンライン チャット システムであると想定してみましょう。

主な問題は次の 2 つです。

a) When the first initially joins the app, how/where should the initial set of data (list of chat rooms, maybe a count of users next to them) be loaded from...

    -> persistent mongo storage : db.Rooms.find().orderBy({ date : -1 })
    -> retrieved from "memory", a capped collection, some form of stream....

b) When the second user joins, should their initial set of data be loaded from

    -> either of the first two options for (a) or alternatively  or hit the first client up for their "live" version of data

その後、最初のユーザーがチャットをしている部屋に参加したときに、履歴をある程度まで取得する必要があります....ライブデータよりも.おそらく古いメッセージを見てください...などなど。

基本的に現時点では、ユーザーがいる「バックボーン」ビューに基づいてユーザーをサブスクライブし、「ライブ」データをsocket.io経由で直接ロードするsocket.ioルームを作成しています。

私は主に初期データロードについて困惑しており、適切なアーキテクチャクライアントを推測します->メッセージキュー->データベース->メッセージキュー->クライアント(複数可)のセットアップの並べ替え

以下の擬似コードの並べ替え

Initialize App and Sockets

==== assumption: application is called chat, has chat rooms, messages flying about in them ====

User 1 socket connect -> join "chat" 

    sockets requests room list (top X rooms) -> mongo db query?

User 2 socket connect -> join "chat" 

    socket requests room list (top X rooms) -> mongo db query? memcache? tailable cursor?


==== messages exist and are continually being sent to chatRoom1 =====

Users 1 joins "chatRoom1" -> socket notifies others a new user has joined

    socket requests user list and top X messages and Y users

User 2 joins "chatRoom1" -> socket notifies others a new user has joined

    socket requests user list and top X messages and Y users (potentially newer messages that user 1)

New Messages follow this process

    // client event handler on a new message, write to div for the correct room
    Client -> socket.on("new message", function(data) { $("#" + data.room).find("div.messages").append(data.message) }

    // client sending a new message, specifies room name and message
    Client -> socket.emit("new message", { "room" : "chatRoom1", "message" : "contents of the message" }

    // Server receives message and does two things
    // a) sends it to other clients of the same room
    Server -> socket.on("new message", function(data) {  io.sockets.in(data.room).emit("new mesage", data)   } )
    // b) stores it in the collection (capped?)

ありがとう!

4

0 に答える 0