Pool transport that combines multiple transports with various load balancing and failover strategies.
This transport implements the same Transport interface, making it a drop-in
replacement for any single transport. It distributes messages across multiple
underlying transports based on the configured strategy.
Round-robin load balancing
Round-robin load balancing
import { PoolTransport } from "@upyo/pool"; const transport = new PoolTransport({ strategy: "round-robin", transports: [ { transport: mailgunTransport }, { transport: sendgridTransport }, { transport: sesTransport }, ], });
Priority-based failover
Priority-based failover
const transport = new PoolTransport({ strategy: "priority", transports: [ { transport: primaryTransport, priority: 100 }, { transport: backupTransport, priority: 50 }, { transport: lastResortTransport, priority: 10 }, ], });
Custom routing with selectors
Custom routing with selectors
const transport = new PoolTransport({ strategy: "selector-based", transports: [ { transport: bulkEmailTransport, selector: (msg) => msg.tags?.includes("newsletter"), }, { transport: transactionalTransport, selector: (msg) => msg.priority === "high", }, { transport: defaultTransport }, // Catches everything else ], });
PoolTransport(config: PoolConfig)
Creates a new PoolTransport instance.
config: ResolvedPoolConfig
The resolved configuration used by this pool transport.
[Symbol.asyncDispose](): Promise<void>
Disposes of all underlying transports that support disposal.
This method is called automatically when using the await using syntax.
It ensures proper cleanup of resources held by the underlying transports.
createSendOptions(options?: TransportOptions): TransportOptions | undefined
Creates send options with timeout if configured.
createStrategy(strategy: PoolStrategy | Strategy): Strategy
Creates a strategy instance based on the strategy type or returns the provided strategy.
Sends a single email message using the pool strategy.
The transport is selected based on the configured strategy. If the selected transport fails, the pool will retry with other transports up to the configured retry limit.
sendMany(messages: Iterable<Message> | AsyncIterable<Message>,options?: TransportOptions,): AsyncIterable<Receipt>
Sends multiple email messages using the pool strategy.
Each message is sent individually using the send method, respecting
the configured strategy and retry logic.