Skip to main content

Module context

Module context 

Source
Expand description

Optional typed per-delivery context exposing native Redis metadata by compile-time key. Optional typed per-delivery context exposing native Redis metadata, one struct per transport.

A handler can read native Redis metadata for the message it is processing by compile-time [Field] key, with no hashing, boxing, or downcasting. The runtime builds the context value once per delivery (via [BuildContext]) from the concrete broker message, then the handler reads a field with ctx.context(key).

This is purely additive. A handler that declares the default () context (the vast majority) is unaffected: the blanket impl BuildContext<M> for () still applies, so opting in costs nothing to those who do not.

§What is exposed

Only genuinely-native metadata that is not already reachable off the payload or Headers is surfaced here:

  • [StreamContext] (Redis Streams) - the stream entry id and the consumer group. The native reclaim delivery-count and idle time stay header-surfaced (DELIVERY_COUNT_HEADER / IDLE_MS_HEADER) and are deliberately not duplicated.
  • [PubSubContext] (Redis Pub/Sub) - the concrete channel the message arrived on and whether it matched through a PSUBSCRIBE pattern (for a pattern subscription the channel differs from the registered glob).

§Examples

use ruststream::runtime::{Context, HandlerResult};
use ruststream_fred::context::{StreamContext, keys};

// A handler over the Streams transport reading the native entry id and consumer group.
async fn handle(order: &Vec<u8>, ctx: &mut Context<'_, StreamContext>) -> HandlerResult {
    if let Some(id) = ctx.context(keys::EntryId) {
        let _ = id; // e.g. log the stream entry id `1700000000000-0`
    }
    let _group = ctx.context(keys::ConsumerGroup);
    HandlerResult::Ack
}

Modules§

keys
Compile-time Field keys, one per native field, read with ctx.context(key).

Structs§

PubSubContext
Per-delivery context for a Redis Pub/Sub delivery (RedisPubSubMessage).
StreamContext
Per-delivery context for a Redis Streams delivery (RedisMessage).