Class PostgresNotificationConfiguration

java.lang.Object
io.micronaut.data.jdbc.notification.postgres.PostgresNotificationConfiguration

@Requires(classes=org.postgresql.PGConnection.class) @ConfigurationProperties("micronaut.data.jdbc.notifications.postgres") public final class PostgresNotificationConfiguration extends Object
Shared schema-generation, listener dispatch, polling, connection validation, and reconnection settings for PostgreSQL notification subscriptions.

Recovery settings apply after a listening connection fails; initial startup failures are propagated to the application. Driver connection and socket timeouts are configured separately through the datasource's PostgreSQL driver properties.

Since:
5.3.0
  • Field Details

  • Constructor Details

    • PostgresNotificationConfiguration

      public PostgresNotificationConfiguration()
      Creates configuration with default connection recovery settings.
    • PostgresNotificationConfiguration

      @Inject public PostgresNotificationConfiguration(PostgresNotificationConfiguration.ConnectionRecoveryConfiguration connectionRecovery)
      Parameters:
      connectionRecovery - the connection recovery settings
  • Method Details

    • getConnectionRecovery

      Returns:
      the connection recovery settings
    • getQueueCapacity

      public int getQueueCapacity()
      Returns the limit for waiting notifications per listener. Defaults to 1,000. The running callback is excluded. Reaching the limit replaces waiting notifications with one INVALIDATE event. This limit does not reduce notifications generated by PostgreSQL.
      Returns:
      the positive notification queue capacity
    • setQueueCapacity

      public void setQueueCapacity(int queueCapacity)
      Sets the limit for waiting notifications per listener.
      Parameters:
      queueCapacity - the positive notification queue capacity
      Throws:
      IllegalArgumentException - if the limit is less than one
    • isSchemaGenerate

      public boolean isSchemaGenerate()
      Whether schema creation also installs PostgreSQL notification functions and triggers. Defaults to false. Only datasources using CREATE or CREATE_DROP schema generation are modified. The datasource user must have permission to create functions and triggers.
      Returns:
      whether notification schema generation is enabled
    • setSchemaGenerate

      public void setSchemaGenerate(boolean schemaGenerate)
      Enables notification function and trigger creation alongside generated tables. Has no effect for NONE or VALIDATE; migrations remain responsible for those schemas.
      Parameters:
      schemaGenerate - whether notification schema generation is enabled
    • getSchemaGenerateMode

      Returns the trigger mode used by notification schema generation. Defaults to ROW. Has no effect unless notification schema generation is enabled.
      Returns:
      the notification trigger mode
    • setSchemaGenerateMode

      public void setSchemaGenerateMode(PostgresNotificationConfiguration.SchemaGenerationMode schemaGenerateMode)
      Selects row notifications or statement-level invalidations for generated triggers. Applies to all subscribed tables included in schema generation.
      Parameters:
      schemaGenerateMode - the notification trigger mode
    • getPollTimeout

      public Duration getPollTimeout()
      Returns the timeout passed to each notification poll. Defaults to one second. This setting does not limit connection establishment or SQL statement execution.

      Increasing this timeout can delay graceful shutdown when no notifications arrive. Stopping the subscription signals the receiver to exit but does not interrupt an active poll. The receiver checks the stop signal after the poll returns, then closes the listening connection. Graceful shutdown waits for that cleanup and any running listener callbacks to finish.

      Returns:
      the notification poll timeout
    • setPollTimeout

      public void setPollTimeout(Duration pollTimeout)
      Sets the notification poll timeout. Durations are used at millisecond precision.
      Parameters:
      pollTimeout - a duration whose millisecond value is between one and Integer.MAX_VALUE
      Throws:
      IllegalArgumentException - if the millisecond value is outside the supported range
    • getValidationInterval

      public Duration getValidationInterval()
      Returns the interval between listening connection checks. Defaults to thirty seconds. Checks run between notification polls, so an active poll can delay the next check.
      Returns:
      the connection validation interval
    • setValidationInterval

      public void setValidationInterval(Duration validationInterval)
      Sets the interval between round trips that detect silently broken listening connections.
      Parameters:
      validationInterval - the positive interval, in milliseconds, up to Integer.MAX_VALUE
      Throws:
      IllegalArgumentException - if the interval is outside the supported range
    • getValidationTimeout

      public Duration getValidationTimeout()
      Returns the timeout for a listening connection check. Defaults to five seconds. The JDBC validation timeout is rounded up to whole seconds.
      Returns:
      the connection validation timeout
    • setValidationTimeout

      public void setValidationTimeout(Duration validationTimeout)
      Sets the timeout for a listening connection check. Shutdown may wait for an active check.
      Parameters:
      validationTimeout - the positive timeout, in milliseconds, up to Integer.MAX_VALUE
      Throws:
      IllegalArgumentException - if the timeout is outside the supported range