Java LISTEN/NOTIFY client library work-around

Started by Joel Jacobsonabout 14 years ago7 messages
#1Joel Jacobson
joel@gluefinance.com

Hi,

As you know, LISTEN/NOTIFY is broken in the Java client library. You have
to do a SELECT 1 in a while-loop to receive the notifications.

http://jdbc.postgresql.org/documentation/head/listennotify.html

Is there some other library with a proper implementation where you don't
have to spam the database with queries to get the notifications?

If not, my company is willing to sponsor development of a patch fixing this
problem.

--
Best regards,

Joel Jacobson

#2Jan Urbański
wulczer@wulczer.org
In reply to: Joel Jacobson (#1)
Re: Java LISTEN/NOTIFY client library work-around

On 30/11/11 13:07, Joel Jacobson wrote:

Hi,

As you know, LISTEN/NOTIFY is broken in the Java client library. You have
to do a SELECT 1 in a while-loop to receive the notifications.

http://jdbc.postgresql.org/documentation/head/listennotify.html

Is there some other library with a proper implementation where you don't
have to spam the database with queries to get the notifications?

You mean a Java library? If Java is not a requirement, the psycopg2
Python library supports notifies well.

Cheers,
Jan

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Jan Urbański (#2)
Re: Java LISTEN/NOTIFY client library work-around

On 11/30/2011 07:27 AM, Jan Urbański wrote:

On 30/11/11 13:07, Joel Jacobson wrote:

Hi,

As you know, LISTEN/NOTIFY is broken in the Java client library. You
have
to do a SELECT 1 in a while-loop to receive the notifications.

http://jdbc.postgresql.org/documentation/head/listennotify.html

Is there some other library with a proper implementation where you don't
have to spam the database with queries to get the notifications?

You mean a Java library? If Java is not a requirement, the psycopg2
Python library supports notifies well.

... and probably most libraries that (unlike JDBC) are libpq-based, like
the perl DBD::Pg.

cheers

andrew

#4Joel Jacobson
joel@gluefinance.com
In reply to: Jan Urbański (#2)
Re: Java LISTEN/NOTIFY client library work-around

On 30 nov 2011, at 13:27, Jan Urbański <wulczer@wulczer.org> wrote:

On 30/11/11 13:07, Joel Jacobson wrote:

Hi,

As you know, LISTEN/NOTIFY is broken in the Java client library. You have
to do a SELECT 1 in a while-loop to receive the notifications.

http://jdbc.postgresql.org/documentation/head/listennotify.html

Is there some other library with a proper implementation where you don't
have to spam the database with queries to get the notifications?

You mean a Java library? If Java is not a requirement, the psycopg2 Python library supports notifies

I need a Java-library for this

Show quoted text

Cheers,
Jan

#5Kris Jurka
books@ejurka.com
In reply to: Joel Jacobson (#1)
Re: Java LISTEN/NOTIFY client library work-around

On Wed, 30 Nov 2011, Joel Jacobson wrote:

As you know, LISTEN/NOTIFY is broken in the Java client library. You have to
do a SELECT 1 in a while-loop to receive the notifications.

http://jdbc.postgresql.org/documentation/head/listennotify.html

This documentation is out of date. Currently you can get notifications
without polling the database if you are not using a SSL connection. You
still must poll the driver, using PGConnection.getNotifications, but it
will return new notifications received without an intermediate database
query. This doesn't work over SSL and potentially some other connection
types because it uses InputStream.available that not all
implementations support.

Kris Jurka

#6Joel Jacobson
joel@trustly.com
In reply to: Kris Jurka (#5)
Re: Java LISTEN/NOTIFY client library work-around

2011/12/1 Kris Jurka <books@ejurka.com>

On Wed, 30 Nov 2011, Joel Jacobson wrote:

As you know, LISTEN/NOTIFY is broken in the Java client library. You

have to

do a SELECT 1 in a while-loop to receive the notifications.

http://jdbc.postgresql.org/documentation/head/listennotify.html

This documentation is out of date. Currently you can get notifications
without polling the database if you are not using a SSL connection. You
still must poll the driver, using PGConnection.getNotifications, but it
will return new notifications received without an intermediate database
query. This doesn't work over SSL and potentially some other connection
types because it uses InputStream.available that not all
implementations support.

I know it works without SSL, but we need SSL for this.

If it would be possible to fix it, my company is as I said willing to pay
for the cost of such a patch.

Kris Jurka

--
Joel Jacobson
Trustly
+46703603801
https://trustly.com

#7Merlin Moncure
mmoncure@gmail.com
In reply to: Joel Jacobson (#6)
Re: Java LISTEN/NOTIFY client library work-around

On Thu, Dec 1, 2011 at 6:21 AM, Joel Jacobson <joel@trustly.com> wrote:

2011/12/1 Kris Jurka <books@ejurka.com>

On Wed, 30 Nov 2011, Joel Jacobson wrote:

As you know, LISTEN/NOTIFY is broken in the Java client library. You
have to
do a SELECT 1 in a while-loop to receive the notifications.

http://jdbc.postgresql.org/documentation/head/listennotify.html

This documentation is out of date.  Currently you can get notifications
without polling the database if you are not using a SSL connection.  You
still must poll the driver, using PGConnection.getNotifications, but it
will return new notifications received without an intermediate database
query.  This doesn't work over SSL and potentially some other connection
types because it uses InputStream.available that not all
implementations support.

I know it works without SSL, but we need SSL for this.

If it would be possible to fix it, my company is as I said willing to pay
for the cost of such a patch.

I certainly don't want to discourage you from cleaning up the jdbc ssl
situation, but one workaround might be to use stunnel.

merlin