Skip to main content

Crate ruststream_fred

Crate ruststream_fred 

Source
Expand description

Redis and Valkey broker for the RustStream messaging framework, backed by the fred client.

Three Redis transports sit behind one broker. Redis Streams is the durable one, a log read through consumer groups with acknowledgement, redelivery and crash recovery. A Redis list is a work queue whose every entry goes to one consumer. Pub/Sub delivers to the subscribers connected when a message is published. Four topologies serve all three: a standalone server, a cluster, a sentinel set, and a fred Pool a service built for itself.

§A service

A handler is an async fn over the decoded payload, mounted on a broker inside the application object, and the attribute writes the main:

use ruststream_fred::stream::prelude::*;
use serde::Deserialize;

#[derive(Deserialize)]
struct Order {
    id: u64,
}

#[subscriber("orders")]
async fn handle(order: &Order) -> HandlerOutcome {
    tracing::info!(order.id, "accepted");
    HandlerOutcome::ack()
}

#[ruststream::app]
fn app() -> impl App {
    RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
        RedisBroker::standalone("redis://localhost:6379").default_group("workers"),
        |b| {
            b.include(handle);
        },
    )
}

cargo run -- run starts it. RedisBroker::standalone only records the address; the runtime connects the broker at startup and shuts it down when the service stops. A bare key in #[subscriber] reads that stream through the broker’s default consumer group.

§Where things are

The guides take a Redis service from installation to production, in this order: getting started, choosing a transport, consumer groups and crash recovery, work queues on lists, retries, delays and dead letters, fan-out with Pub/Sub, side effects with the acknowledgement, transactions, replay and seeking, Redis Cluster, running in production, testing and interoperating with other clients. The architecture pages show how Redis delivers messages and where the crate sits between fred and the runtime, and the benchmarks what it costs.

Each topic below links to its component page on the site, which shows it in a service; the item’s own documentation keeps the detail.

§Broker

§Subscriptions

  • Subscriptions: the descriptors, what each settles and where its retry copy goes.
  • block: RedisSubscribeExt::block, how long one read waits on the server.
  • Batches: a slice handler, a native COUNT on a stream.
  • Framing: the binary frame or the codec envelope of a list entry and a channel message.

§Streams

§Positions

§Lists

§Pub/Sub

§Acknowledgement

§Context

§Pipelining

§Publishing

§Transactions

§Tooling

§Cargo features

All off by default: the crate ships the three transports and the broker with no feature on. testing adds the in-process mode TestApp::start connects the broker through, and asyncapi the Redis extension of the generated document. tls-rustls, tls-rustls-ring and tls-native-tls map onto fred’s TLS backends. sentinel-auth adds credentials of their own for the sentinels, and credential-provider rotating credentials through a callback.

Re-exports§

pub use list::RedisList;
pub use list::RedisListMessage;
pub use list::RedisListPublish;
pub use list::RedisListPublisher;
pub use list::RedisListSubscriber;
pub use pipeline::RedisListAtomic;
pub use pipeline::RedisListPipeline;
pub use pipeline::RedisPubSubAtomic;
pub use pipeline::RedisPubSubPatternAtomic;
pub use pipeline::RedisPubSubPatternPipeline;
pub use pipeline::RedisPubSubPipeline;
pub use pipeline::RedisStreamAtomic;
pub use pipeline::RedisStreamPipeline;
pub use pubsub::PubSubMode;
pub use pubsub::RedisPubSub;
pub use pubsub::RedisPubSubMessage;
pub use pubsub::RedisPubSubPattern;
pub use pubsub::RedisPubSubPublish;
pub use pubsub::RedisPubSubPublisher;
pub use pubsub::RedisPubSubSubscriber;
pub use stream::RedisStream;
pub use stream::StreamStart;

Modules§

context
Per-delivery and per-batch context fields exposed to handlers.
list
Redis lists: a work queue whose every entry goes to one consumer.
pipeline
Consumer-side pipelining: a subscription settles in a window, and a handler queues its own Redis commands into the delivery’s segment of that window.
prelude
The core prelude plus everything a service mixing all three Redis forms writes.
pubsub
Redis Pub/Sub: delivery to the subscribers connected when a message is published.
stream
Redis Streams: a stream read through a consumer group, the durable form.

Structs§

ClosedRedisBroker
The terminal witness returned by shutting down a ConnectedRedisBroker.
ConnectedRedisBroker
The typed witness that Broker::connect succeeded: it owns the live fred pool.
EntryId
A Redis Streams entry id: the <milliseconds>-<sequence> pair the server assigns to every entry.
RedisBroker
An unconnected Redis broker: the recorded topology and its options, no I/O performed yet.
RedisDefaultPublish
The broker’s default policy, what a registration publishes through when its mount site names none: a reply, a retry copy, a dead-letter move.
RedisDefaultPublisher
The live form of RedisDefaultPublish: writes each name the way this connection’s subscriptions read it. Cheap to clone.
RedisGroupSeeker
Moves a consumer group’s cursor.
RedisMessage
A Redis Streams delivery, read from a consumer group via XREADGROUP or XAUTOCLAIM.
RedisPublish
The declaration half of the stream publisher: pure policy, constructible anywhere.
RedisPublishOptions
The per-message settings of every publisher and transaction in this crate.
RedisPublisher
The live stream publisher: RedisPublish paired with a connection. Cheap to clone.
RedisSubscriber
A Redis Streams subscription bound to a consumer group.
RedisTransaction
An owned Redis transaction, opened by transaction on a RedisPublisher.
RedisTransactionalPublish
The stream publisher’s policy for a mount that publishes in transactions: it pairs into the same RedisPublisher as RedisPublish, and only where the topology can run one.
TlsConfig
TLS configuration for a client.

Enums§

DelayedRetry
How a subscription should handle retry_after / nack_after delays.
RedisError
Errors surfaced by the Redis broker implementation.
RedisGroupPosition
Where a consumer group’s cursor sits, for RedisGroupSeeker::seek and the start_at(..) clause of #[subscriber].
TlsConnector
An enum for interacting with various TLS libraries and interfaces.

Constants§

DELIVERY_COUNT_HEADER
Header carrying the native Redis Streams delivery count, so a handler can branch on how many attempts a message has already had.
IDLE_MS_HEADER
Header carrying how long (milliseconds) the delivery had been pending before this read. Zero on an entry a claiming subscription read off the tail.
PARTITION_KEY_HEADER
The well-known header key for per-message routing / partitioning.

Traits§

CredentialProvider
A trait that can be used to override the credentials used in each AUTH or HELLO command.
RedisPublishSteps
The steps this crate adds to the publish builder.
RedisSubscribeExt
The Redis subscription options a mount site names, chained after the core’s settings steps.