Re: Connecting to NOTIFY with telnet - Mailing list pgsql-general

From Jeff Janes
Subject Re: Connecting to NOTIFY with telnet
Date
Msg-id CAMkU=1xPwx-1jd+x9xC74DTvPRXE85znaqiS4rRm2XSi5eOqcw@mail.gmail.com
Whole thread Raw
In response to Re: Connecting to NOTIFY with telnet  (Igal Sapir <igal@lucee.org>)
Responses Re: Connecting to NOTIFY with telnet
List pgsql-general
On Sat, May 4, 2019 at 3:04 PM Igal Sapir <igal@lucee.org> wrote:
Jeff,

On Sat, May 4, 2019 at 11:34 AM Jeff Janes <jeff.janes@gmail.com> wrote:
On Sat, May 4, 2019 at 1:49 PM Igal Sapir <igal@lucee.org> wrote:
Christoph,

On Sat, May 4, 2019 at 10:44 AM Christoph Moench-Tegeder <cmt@burggraben.net> wrote:
## Igal Sapir (igal@lucee.org):

> My main "issue" is that the official pgjdbc driver does not support the
> notifications with listen and I was trying to figure out why.

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


I should have been more explicit.  My main issue is with the following statement from the link that you posted:

> A key limitation of the JDBC driver is that it cannot receive asynchronous notifications and must poll the backend to check if any notifications were issued

Polling is much less efficient than event handling and I'm sure that there's a major performance hit with that.

Isn't that addressed here?:

                // If this thread is the only one that uses the connection, a timeout can be used to
                // receive notifications immediately:
                // org.postgresql.PGNotification notifications[] = pgconn.getNotifications(10000);


It "helps", but it's still not the same as keeping the connection open and receiving messages in real time.

But it is the same as that.  It keeps the connection open, and receives the messages in real time.  It blocks either until it gets a NOTIFY, or for 10 seconds, whichever occurs first.  You can use 0 to block forever until a NOTIFY arrives.  Maybe you didn't remove the sleep a few lines further down?  Or is there some other problem here? 

Cheers,

Jeff

pgsql-general by date:

Previous
From: Igal Sapir
Date:
Subject: Re: Connecting to NOTIFY with telnet
Next
From: Igal Sapir
Date:
Subject: Re: Connecting to NOTIFY with telnet