码迷,mamicode.com
首页 > 数据库 > 详细

姚博文 postgresql listen/notify push message

时间:2015-01-13 19:58:45      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:姚博文 postgresql liste

使用postgresql向客端推送消息

#listen message_channel;

notify message_channel,‘hello todd‘;


jdbc:


Statement stmt = conn.createStatement();
stmt.execute("LISTEN message_channel");
stmt.close();

notifications = conn.getNotifications();
if (notifications != null && notifications.length > 0) {
for( final Session session: sessions ) {
for (int i=0; i<notifications.length; i++) {
// System.out.println("Got notification: " + notifications[i].getName());
// System.out.println("Got notification: " + notifications[i].getParameter());
// System.out.println("Got notification: " + notifications[i].getPID());
try {
session.getBasicRemote().sendObject(notifications[i].getParameter());
logger.debug("发送了消息(" + session.getId() + "):" + notifications[i].getParameter());
} catch (Exception e) {
logger.error("session(" + ((session != null)?session.getId():"") + ")发送失败:" + e.getMessage());
continue;
}
}
}
}

姚博文 postgresql listen/notify push message

标签:姚博文 postgresql liste

原文地址:http://blog.csdn.net/tianyawudie/article/details/42679617

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!