如何使用Postgres数据库在Java中获得异步/事件驱动的LISTEN / NOTIFY支持? [英] How do I get asynchronous / event-driven LISTEN/NOTIFY support in Java using a Postgres database?

查看:641
本文介绍了如何使用Postgres数据库在Java中获得异步/事件驱动的LISTEN / NOTIFY支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,Java中LISTEN / NOTIFY的JDBC驱动程序不支持真正的事件驱动通知。你必须经常轮询数据库以查看是否有新的通知。

From what I can tell, the JDBC drivers for LISTEN/NOTIFY in Java do NOT support true event-driven notifications. You have to poll the database every so often to see if there's a new notification.

我在Java中有哪些选项(可能是JDBC以外的东西?),如果有的话,以真正的事件驱动方式异步获取通知而不进行轮询?

What options do I have in Java (possibly something other than JDBC?), if any, to get notifications asynchronously in a true event-driven manner without polling?

推荐答案

使用pgjdbc-ng驱动程序。

Use the pgjdbc-ng driver.

http://impossibl.github.io/pgjdbc-ng/

它支持异步通知,无需轮询。我成功地使用了它。

It supports async notifications, without polling. I have used it successfully.

参见 http://blog.databasepatterns.com/2014/04/postgresql-nofify-websocket-spring-mvc.html

Oleg有一个很好的例子答案

Oleg has a nice example answer as well

这篇关于如何使用Postgres数据库在Java中获得异步/事件驱动的LISTEN / NOTIFY支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆