Using PostgreSQL to push messages to the client
#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 ("Sent message (" + session.getid () + "):" + notifications[i].getparameter ());
} catch (Exception e) {
Logger.error ("Session" + ((session! = NULL)? Session.getid (): "") + ") Send failed:" + e.getmessage ());
Continue
}
}
}
}
Liao Bowen PostgreSQL listen/notify Push message