Skip to main content

PgListenerOptions

Struct PgListenerOptions 

Source
#[non_exhaustive]
pub struct PgListenerOptions { pub reconnect: bool, pub backoff_initial: Duration, pub backoff_max: Duration, pub keepalive_idle: Duration, pub ping_interval: Duration, pub buffer: usize, pub max_reconnect_attempts: Option<u32>, }
Expand description

Tuning for a PgListener; see PgListener::builder.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§reconnect: bool

Reconnect after the connection is lost, re-issuing LISTEN for every tracked channel: the loss is reported as PgListenerEvent::Disconnected and the re-established connection as PgListenerEvent::Reconnected. When false, connection loss is terminal and PgListener::recv returns the error (no Disconnected). Default: true.

§backoff_initial: Duration

Delay before the first reconnect attempt; it doubles after every attempt, up to backoff_max, and only starts over once a re-established connection has stayed up for a ping_interval (so a server that keeps dropping new connections is not hammered). Each delay is scaled by a random factor between 0.5 and 1 (jitter). Must be non-zero and at most backoff_max. Default: 100 ms.

§backoff_max: Duration

Upper bound on the reconnect delay. Default: 30 s.

§keepalive_idle: Duration

TCP keepalive idle time on the listener connection. Counted in whole seconds; must be at least 1 s. Default: 60 s.

§ping_interval: Duration

Liveness check period. When no notification arrived during an interval, SELECT 1 is sent; if it fails or is not answered within another interval, the connection is treated as lost. This detects half-open connections long before TCP keepalive does. The same bound applies to LISTEN / UNLISTEN commands: one not answered in time fails with a timeout error and the connection is treated as lost. Each connection attempt (TCP connect, TLS and the startup handshake) is bounded by PgConfig::connect_timeout plus this (the driver applies connect_timeout to each address the host resolves to, so an address that times out leaves this long for the next one and the handshake). Must be at least 100 ms and at most one day. Default: 30 s.

§buffer: usize

Capacity of the notification queue. When it is full, further notifications are dropped and reported as PgListenerEvent::Lagged. Must be at least 1 and at most tokio’s Semaphore::MAX_PERMITS, the largest bounded channel tokio supports. Default: 1024.

§max_reconnect_attempts: Option<u32>

Give up after this many failed reconnect attempts in a row (counted per outage): the listener then stops, and PgListener::recv returns the last attempt’s error once the queue is drained. None retries for as long as the listener exists. Must be at least 1; to never reconnect, disable reconnect.

Whatever this is set to, the listener also gives up after three attempts in a row that the server refuses with SQLSTATE class 28 (invalid authorization: a wrong password, a pg_hba.conf rejection) or 3D000 (the database does not exist). Retrying cannot fix those, and retrying bad credentials forever can lock the role or trip intrusion detection. Default: None.

Trait Implementations§

Source§

impl Clone for PgListenerOptions

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PgListenerOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PgListenerOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more