简体   繁体   English

HTML Web应用程序通知系统

[英]HTML Web Application Notification System

I'm using Play Framework 2.3 (Java) and MySQL. 我正在使用Play Framework 2.3(Java)和MySQL。

I'm building a notification system that reads from a "notifications" table in MySQL. 我正在构建一个从MySQL中的“ notifications”表读取的通知系统。

I've tried using AJAX polling where a request is sent asynchronously every 30 seconds, the table is read and if any new notifications exist, are sent via JSON back to the client. 我尝试使用AJAX轮询,其中每30秒异步发送一次请求,读取表,如果存在任何新通知,则通过JSON发送回客户端。 However, the performance is concerning, especially with many concurrent users. 但是,性能令人担忧,尤其是对于许多并发用户。

What's the best way to build such a system? 构建这样的系统的最佳方法是什么? Are there any particular Java libraries that would work well for this? 是否有任何特定的Java库对此适用?

Thanks in advance. 提前致谢。

I see I read too fast, you're using the Play Framework, which I don't know. 我看得太快了,您正在使用Play框架,但我不知道。 But a quick search reveals that it also has websocket capabilities: 但是快速搜索发现它也具有websocket功能:

http://www.playframework.com/documentation/2.3.x/JavaWebSockets http://www.playframework.com/documentation/2.3.x/JavaWebSockets

---- Old answer below ---- ----下面的旧答案----

If you're using JEE7, why not try to use websockets? 如果您使用的是JEE7,为什么不尝试使用websocket? It would limit your application to 'newer' browsers, supporting websockets, but it would improve performance, since the connection is bi-directional and suffers less from overhead. 它将您的应用程序限制为支持Websocket的“较新”浏览器,但由于连接是双向的并且开销较小,因此可以提高性能。

More information on the subject can be found here: 有关此主题的更多信息,请参见:

http://docs.oracle.com/javaee/7/tutorial/doc/websocket.htm http://docs.oracle.com/javaee/7/tutorial/doc/websocket.htm

I've also found the following example very useful: 我还发现以下示例非常有用:

http://mgreau.com/posts/2013/11/11/javaee7-websocket-angularjs-wildfly.html http://mgreau.com/posts/2013/11/11/javaee7-websocket-angularjs-wildfly.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM