I am tasked with creating a web page (think twitter) that updates when new messages are added to the database. When a message is removed from the database, it also must be removed from the client. It is possible that multiple clients can be accessing the same messages at the same time. Other actions can occur, such as a stop command issued on the server. Once this happens all the messages on the server will stop showing.
我的任务是创建一个网页(想想推特),在新消息添加到数据库时更新。从数据库中删除邮件时,也必须从客户端删除它。多个客户端可能同时访问相同的消息。可能会发生其他操作,例如在服务器上发出停止命令。一旦发生这种情况,服务器上的所有消息都将停止显示。
What I am looking for is an architecture for solving this problem.
我正在寻找的是一个解决这个问题的架构。
Technologies that I am using are .Net 4.5, ASP.Net MVC and KnockoutJs. Nodejs could be used, but I’d need to know the benefit of using nodejs over using SignalR.
我使用的技术是.Net 4.5,ASP.Net MVC和KnockoutJs。可以使用Nodejs,但我需要知道使用nodejs而不是使用SignalR的好处。
My currently implementation is using a javascript timer which is polling the server every 30 seconds for new messages. It works, but the polling feels dirty.
我目前的实现是使用javascript计时器,它每隔30秒轮询一次服务器以获取新消息。它有效,但民意调查很脏。
2 个解决方案
#1
1
Can't comment on ASP.NET - but have used Node.js together with Knockout for this. I have used both WebSockets (via socket.io library) and also Server Sent Events (SSE) to push updates to the client model.
无法对ASP.NET发表评论 - 但已将Node.js与Knockout一起使用。我使用了两个WebSockets(通过socket.io库)和Server Sent Events(SSE)来推送更新到客户端模型。
Sounds like SSE would be a good fit in this case. The key is whatever your database technology is should support emitting changes events to your node middle-ware so that you can send this to the browser.
听起来像SSE在这种情况下会很合适。关键是您的数据库技术应支持向您的节点中间件发送更改事件,以便您可以将其发送到浏览器。
#2
0
After more research, the polling method is the optimal solution for the technologies in involved.
经过更多的研究,轮询方法是所涉及技术的最佳解决方案。
The crux of the problem is there is no notification of a new message, which would prompt a change in the system. Currently, a new message is received when it is committed to the database. SQL Server does not have a notification mechanism (this is not 100 percent true, but it not a dependency I wish to take on). In long the run, the optimal system would be to implement a publisher/subscribe motel using SignalR or nodejs which would deliver real-time messages to the client. For this to happen it would require a complete re-architecture of the application.
问题的关键在于没有新消息的通知,这会促使系统发生变化。当前,在将其提交到数据库时会收到新消息。 SQL Server没有通知机制(这不是百分之百,但它不是我想要的依赖)。从长远来看,最佳系统将使用SignalR或nodejs实现发布者/订阅汽车旅馆,这将向客户端传递实时消息。为此,需要对应用程序进行完整的重新架构。
#1
1
Can't comment on ASP.NET - but have used Node.js together with Knockout for this. I have used both WebSockets (via socket.io library) and also Server Sent Events (SSE) to push updates to the client model.
无法对ASP.NET发表评论 - 但已将Node.js与Knockout一起使用。我使用了两个WebSockets(通过socket.io库)和Server Sent Events(SSE)来推送更新到客户端模型。
Sounds like SSE would be a good fit in this case. The key is whatever your database technology is should support emitting changes events to your node middle-ware so that you can send this to the browser.
听起来像SSE在这种情况下会很合适。关键是您的数据库技术应支持向您的节点中间件发送更改事件,以便您可以将其发送到浏览器。
#2
0
After more research, the polling method is the optimal solution for the technologies in involved.
经过更多的研究,轮询方法是所涉及技术的最佳解决方案。
The crux of the problem is there is no notification of a new message, which would prompt a change in the system. Currently, a new message is received when it is committed to the database. SQL Server does not have a notification mechanism (this is not 100 percent true, but it not a dependency I wish to take on). In long the run, the optimal system would be to implement a publisher/subscribe motel using SignalR or nodejs which would deliver real-time messages to the client. For this to happen it would require a complete re-architecture of the application.
问题的关键在于没有新消息的通知,这会促使系统发生变化。当前,在将其提交到数据库时会收到新消息。 SQL Server没有通知机制(这不是百分之百,但它不是我想要的依赖)。从长远来看,最佳系统将使用SignalR或nodejs实现发布者/订阅汽车旅馆,这将向客户端传递实时消息。为此,需要对应用程序进行完整的重新架构。