Interface PostgresNotificationConnectionFactory

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface PostgresNotificationConnectionFactory
Opens dedicated PostgreSQL connections for change notification subscriptions.

Applications can provide a bean implementing this interface to replace the default driver-based factory. This allows connection settings, authentication, and credential refresh to come from the application's own configuration without coupling notification support to a connection pool implementation.

The factory is called for initial subscription startup and for every reconnection attempt. The default implementation reads the datasource's JDBC URL, credentials, and configured driver properties. It cannot discover properties or authentication hooks set only on a pool. Implementations supplying programmatic settings must resolve their current values on each call.

Since:
5.3.0
  • Method Summary

    Modifier and Type
    Method
    Description
    openConnection(String dataSourceName)
    Opens a new connection for one datasource's notification subscription.
  • Method Details

    • openConnection

      Connection openConnection(String dataSourceName) throws SQLException
      Opens a new connection for one datasource's notification subscription.

      The connection must support unwrapping to org.postgresql.PGConnection and remain outside the application connection pool. The subscription takes ownership, enables autocommit, executes LISTEN, and closes or aborts the connection when it is no longer needed. Implementations must use finite connection and socket timeouts so startup, recovery, and shutdown cannot wait indefinitely on driver operations. The default implementation's timeout defaults are not applied to custom factories.

      Parameters:
      dataSourceName - the datasource selected by the listeners
      Returns:
      a new dedicated PostgreSQL connection
      Throws:
      SQLException - if the connection cannot be opened