我试图实现基本社交网络的基本通知系统p:poll
在视图层和一个简单的NotificationService
类从数据库获取新的通知和刷新通知列表NotificationBean
这是每个用户viewscoped。类似这样的流程:p:poll/push的通知系统
-Poll calls NotificationBean.getNewNotifications for example every 15 sec.
--getNewNotifications calls NotificationService and DAO methods
---notificationList of user is refreshed
----DataTable on view layer shows new notifications
但p:poll
担心的是它的性能,因为它在每个时间间隔期满发送一个查询。
PrimeFaces有PrimePush它基于Atmosphere Framework,它打开网络套接字,似乎更适合创建通知系统。
但我不知道应该使用哪些组件及其属性。它有p:socket
组件和channel
属性。我应该使用用户名作为channel
值吗?下面从PrimeFaces代码来展示和总结了最后一句:
<p:socket onMessage="handleMessage" channel="/notifications" />
据我了解,从this showcase example这个p:socket
监听notifications
通道。和推代码片段是:
PushContext pushContext = PushContextFactory.getDefault().getPushContext();
pushContext.push("/notifications", new FacesMessage(summary, detail));
但是,这将通知所有用户的页面,我需要它通知特定用户的推动。假设有2个用户,并假设User1将User2添加为朋友。一定有某事。像这样:
pushContext.push("User2/notifications", new FacesMessage("friendship request", "from User1"));
但我不确定这是否正确使用这种功能要求或不。考虑到应用程序的可扩展性,每个进程开放如此多的通道可能需要昂贵的成本。
感谢您的帮助。
你想让一个用户发送即时消息给其他用户吗? – 2013-04-12 07:03:42
@RongNK,这取决于你如何理解'消息'。在这个问题中,我提到了包含通知的列表。如果user1将user2添加为朋友或对他/她的状态发表评论,则应将通知添加到user2的通知列表中,该列表可以是一个纯字符串列表或模型类列表,该列表更适合于我的实现。所以是的,那必须是立竿见影的。 – 2013-04-12 07:20:10
(对不起,我的英语)好吧,我想你不想使用民意调查,所以服务器会播放按摩,每个客户端都会过滤,或者服务器必须存储客户端的地址并发送到特定的地址,我想。让亲解决你的问题:) – 2013-04-12 07:55:13