Skip to main content

spawn_consumer_with_cursor

Function spawn_consumer_with_cursor 

Source
pub async fn spawn_consumer_with_cursor<S>(
    config: &StreamConfig,
    pool: &DbPool,
    consumer_id: &str,
    state: S,
    handler: EventHandler<S>,
) -> Result<JoinHandle<()>>
where S: Clone + Send + Sync + 'static,
Expand description

Spawn a Jetstream consumer with cursor persistence.

Like spawn_consumer, but loads the initial cursor from the database and periodically saves the latest processed event timestamp. This allows the consumer to resume from where it left off after a restart.

The consumer_id is a stable identifier for this consumer instance, used as the key in the cursor persistence table. Use a meaningful name like "my-app-aggregator" so multiple consumers can coexist.

Cursor behaviour is controlled by StreamConfig::cursor:

  • None or "live" — always start from now (no cursor in the URL).
  • "auto" — resume from the last stored cursor in the database.
  • A numeric string — use that value as the initial cursor timestamp.