PGConnection.getNotifications() over an ssl=true connection does not seem to work... #2638
-
Hi, It seems that retrieving notifications using PGConnection.getNotifications() over a connection having ssl=true does not work. This works: Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost:5432?ssl=false";
conn = Connection.getConnection(url, "user", "pwd");
Statement stmt = conn.createStatement();
stmt.execute("LISTEN some_channel");
pgConn = conn.unwrap(org.postgresql.PGConnection.class);
PGNotification[] notifications = pgConn.getNotifications(); This does not (getNotifications always returns null): Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost:5432?ssl=true";
conn = Connection.getConnection(url, "user", "pwd");
Statement stmt = conn.createStatement();
stmt.execute("LISTEN some_channel");
pgConn = conn.unwrap(org.postgresql.PGConnection.class);
PGNotification[] notifications = pgConn.getNotifications(); Note that for testing I send NOTIFY statements directly from a psql client. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 7 replies
-
hi @mat-chartier I'm going to presume this works fine with non-ssl connections ? If so then yes, this does make some sense. We can't read ahead with ssl connections. I will spend some time on this today though. Thanks for the report. not sure what you are using notifications for but they are usually not my first choice. I'd prefer to use logical replication to get notifications of changes. Dave |
Beta Was this translation helpful? Give feedback.
-
FYI, it's no longer necessary to use |
Beta Was this translation helpful? Give feedback.
-
@mat-chartier So I checked and this code below works fine. I was wrong
You have to put the getNotifications in a thread though. I put a breakpoint in and then sent the notification and read it after. Dave |
Beta Was this translation helpful? Give feedback.
-
you can use ssl or verify-ca that part is not relevant to the problem. I installed sslinfo to make sure it was an ssl connection. The relevant part is that you need to have a thread running to read the notification. |
Beta Was this translation helpful? Give feedback.
-
Ok, I haven't actually tried a thread, so I'll try that in a bit |
Beta Was this translation helpful? Give feedback.
-
good to know, thanks for letting me know! you can just not use ssl at all if you don't want an ssl connection |
Beta Was this translation helpful? Give feedback.
Ok, I haven't actually tried a thread, so I'll try that in a bit