Skip to main content

PubSub

RedisPubSub reads one channel; a message reaches only the subscribers connected when it is published, and nothing is settled.

RedisPubSub::new("prices") subscribes to the channel prices with SUBSCRIBE. Every subscription of the channel receives every message, in this service and in any other. Redis keeps nothing: a message published while no subscription is connected is gone. After a dropped connection the subscription subscribes again, and the messages published while it was down are not delivered. An outcome settles nothing: an ack, a retry and a drop all report AckError::Unsupported, and the runtime logs a warning for each. A retry_after still comes back, as a copy the runtime publishes to the channel. A subscription holds the messages that arrive while its handler is busy in a buffer. RedisPubSubPattern reads every channel a glob matches, and PubSubMode chooses between classic and sharded delivery.

Example​

Every price published on prices while the service runs.

/// Every price published on `prices` while the service is subscribed.
#[subscriber(RedisPubSub::new("prices"))]
async fn on_price(tick: &Tick) -> HandlerOutcome {
tracing::info!(symbol = %tick.symbol, tick.cents, "price");
HandlerOutcome::ack()
}