pub struct MySqlOutboxWorkerBuilder { /* private fields */ }Expand description
Fluent builder for an OutboxWorker backed by MySqlOutboxStore.
§Pool sizing and acquire timeout
The worker and every concurrent publisher draw connections from the same
pool. To avoid indefinite blocking under pressure, configure an acquire
timeout on the MySqlPool before passing it here:
use sqlx::mysql::MySqlPoolOptions;
use std::time::Duration;
let pool = MySqlPoolOptions::new()
// 1 connection for the claim cycle + 1 per concurrent publisher + 2 headroom
.max_connections(batch_size + num_publishers + 2)
// surface PoolTimeout instead of blocking indefinitely
.acquire_timeout(Duration::from_secs(5))
.connect("mysql://...")
.await?;
let worker = MySqlOutboxWorkerBuilder::new(pool)
.batch_size(batch_size)
.build()?;When acquire_timeout expires, OutboxStore::acquire returns
OutboxError::PoolTimeout instead of hanging. The worker logs the
error and retries after OutboxWorkerConfig::poll_interval.
Implementations§
Source§impl MySqlOutboxWorkerBuilder
impl MySqlOutboxWorkerBuilder
Sourcepub fn table_name(self, name: impl Into<String>) -> Self
pub fn table_name(self, name: impl Into<String>) -> Self
Override the outbox table name (default "audit_outbox").
Sourcepub fn dead_letter_table(self, name: impl Into<String>) -> Self
pub fn dead_letter_table(self, name: impl Into<String>) -> Self
Enable dead-letter persistence for poison messages.
Sourcepub fn register_handler<E, H>(self, handler: H) -> Self
pub fn register_handler<E, H>(self, handler: H) -> Self
Register a typed handler for the event type E.
Registering twice for the same event type silently replaces the previous handler.
Register a handler already shared behind an Arc.
Sourcepub fn poll_interval(self, d: Duration) -> Self
pub fn poll_interval(self, d: Duration) -> Self
Override the poll interval (default 100 ms).
Sourcepub fn batch_size(self, n: usize) -> Self
pub fn batch_size(self, n: usize) -> Self
Override the batch size per poll (default 10).
Sourcepub fn max_attempts(self, n: u32) -> Self
pub fn max_attempts(self, n: u32) -> Self
Override the maximum number of attempts per envelope (default 5).
Sourcepub fn retry_base_delay(self, d: Duration) -> Self
pub fn retry_base_delay(self, d: Duration) -> Self
Override the base delay for exponential backoff (default 1 s).
Sourcepub fn retry_max_delay(self, d: Duration) -> Self
pub fn retry_max_delay(self, d: Duration) -> Self
Override the maximum backoff delay (default 5 min).
Sourcepub fn jitter(self, enabled: bool) -> Self
pub fn jitter(self, enabled: bool) -> Self
Enable or disable full jitter on the backoff delay (default true).
Sourcepub fn dispatch_timeout(self, d: Duration) -> Self
pub fn dispatch_timeout(self, d: Duration) -> Self
Override the per-envelope handler deadline and soft-lease unit (default 30 s).
Each handler invocation is wrapped in a hard tokio timeout of this
duration; the batch lease is sized as batch_size x dispatch_timeout
internally. Set it to the worst-case duration of a single handler.
Sourcepub fn build(self) -> Result<OutboxWorker<MySqlOutboxStore>, OutboxError>
pub fn build(self) -> Result<OutboxWorker<MySqlOutboxStore>, OutboxError>
Consume the builder and produce an OutboxWorker ready to spawn.
§Errors
Returns OutboxError::Internal if the configured table_name
is not a valid identifier.
Auto Trait Implementations§
impl !RefUnwindSafe for MySqlOutboxWorkerBuilder
impl !UnwindSafe for MySqlOutboxWorkerBuilder
impl Freeze for MySqlOutboxWorkerBuilder
impl Send for MySqlOutboxWorkerBuilder
impl Sync for MySqlOutboxWorkerBuilder
impl Unpin for MySqlOutboxWorkerBuilder
impl UnsafeUnpin for MySqlOutboxWorkerBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more