Juggernaut 2 的服务器端计时器
我正在使用 Juggernaut 2 编写一个用于实时推送通知的 Rails 应用程序,但不知道如何解决这个问题。我的聊天室中有许多用户,我想运行一个计时器,以便每 30 秒向聊天室中的每个浏览器推送一次。 Juggernaut 2 是基于 node.js 构建的,因此我假设我需要在那里编写此代码。我只是不知道从哪里开始将其与 Juggernaut 2 集成。
I am writing a rails app with Juggernaut 2 for real-time push notifications and am not sure how to approach this problem. I have a number of users in a chat room and I would like to run a timer so that a push can go out to each browser in the chat room every 30 seconds. Juggernaut 2 is built on node.js, so I'm assuming I need to write this code there. I just have no idea where to start in terms of integrating this with Juggernaut 2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我只是简单浏览了一下 Juggernaut,所以请对我的回答持保留态度......
每次循环迭代要做什么?嗯,前面提到的频道代码的链接有一个发布方法:
}
所以你基本上必须创建一个 Message 对象,并将 message.channels 设置为 Channel.channels,如果你将该消息传递给发布方法,它将发送给所有你的客户。
至于您的消息内容,我不知道您正在使用什么客户端(socket.io?某人已经为您在 Juggernaut 和 socket.io 上构建的聊天客户端?),所以这取决于您。
至于在哪里放置创建间隔并触发回调以将消息发布到所有通道的代码,您可能需要在此处检查创建在给定端口上侦听的实际服务器的代码: com/maccman/juggernaut/blob/master/lib/juggernaut/server.js) 如果您在 init() 中附加间隔,那么一旦您启动服务器,它将每 30 秒检查一次,以将给定的消息发布到每个渠道
I just browsed through Juggernaut briefly so take my answer with a grain of salt...
What to do in each loop iteration? Well, the link to the aforementioned Channel code has a publish method:
}
So you basically have to create a Message object with message.channels set to Channel.channels and if you pass that message to the publish method, it will send out to all your clients.
As to the contents of your message, I dunno what you are using client side (socket.io? a chat client someone already built for you off Juggernaut and socket.io?) so that's up to you.
As for where to put the code creating the interval and firing off the callback to publish your message to all channels, you might want to check here in the code that creates the actual server listening on the given port: (https://github.com/maccman/juggernaut/blob/master/lib/juggernaut/server.js) If you attach the interval within init(), then as soon as you start the server it will be checking every 30 seconds to publish your given message to every channel
下面是一个示例客户端,它在 Ruby 中每 30 秒推送一次。
使用 Redis 和 Node 安装 Juggernaut:安装 ruby 和 rubygems,然后运行 gem install juggernaut 并
Here is a sample client which pushes every 30 seconds in Ruby.
Install your Juggernaut with Redis and Node: install ruby and rubygems, then run
gem install juggernaut
and我们实施了一个测验系统,以可变的时间间隔推出问题。我们的做法如下:
在我们的案例中,关键是使用“spawn”来运行测验计时的后台进程,以便我们仍然可以处理传入的分数。
我不知道这有多大的可扩展性。
We implemented a quiz system which pushed out questions on a variable time interval. We did it as follows:
The key in our case was using 'spawn' to run a background process for the quiz timing so that we could still process the incoming scores.
I have no idea how scalable this is.