【问题标题】:Online/Offline Notification in Node.js like Facebook notification systemNode.js 中的在线/离线通知,如 Facebook 通知系统
【发布时间】:2013-11-22 18:36:00
【问题描述】:

我正致力于在 Node.js 中实现通知系统,类似于 Facebook 通知系统。我见过一些使用 Socket.io 的实现,但我不知道它是否适合我的情况。我正在考虑的另一种方法是创建一个通知模型(我使用 MongoDB 作为存储),如下所示:

var Notification = new mongoose.Schema({
    title: {type: String},
    added: {type: Date},
    accountId: {type: mongoose.Schema.ObjectId},
    notificationType: {type: String},
    isSeen: {type: Boolean}
});

然后,我将在我的帐户架构中使用它:

var AccountSchema = new mongoose.Schema({
    email:     { type: String, unique: true },
    password:  { type: String },
    name: {
        first:   { type: String },
        last:    { type: String },
        full: {type: String}
    },
    notifications: [Notification]
});

然后,我将根据操作向用户添加通知。但是,我不太确定这种方法是否会奏效。因此,我想知道哪种方法最适合这种情况:在线/离线通知

提前致谢,

【问题讨论】:

    标签: javascript node.js mongodb notifications


    【解决方案1】:

    您真的应该研究发布/订阅系统以获取实时通知。

    如果您遇到离线的订阅者,您可以将其存储在您的 [Notification] 架构中。一旦用户再次连接,它就可以查询它们并确认它们看起来。

    资源:

    Publish Subscriber pattern

    Redis Pub/Sub

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-27
      • 2015-12-25
      • 1970-01-01
      • 2021-02-17
      • 1970-01-01
      • 2017-03-16
      相关资源
      最近更新 更多