basic-durable-streaming-exp

command
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

This sample demonstrates durable streaming: a stream a caller can rejoin, whether it is still running or already finished.

countdown streams one chunk a second. An ordinary stream is gone the moment the connection drops, so a caller that loses the network loses the run. A durable stream survives that: the manager buffers every chunk under a stream ID, and a caller who reconnects with that ID gets the buffered chunks replayed before live updates resume. Reconnect after the run has finished and the whole stream comes back, final result included.

The stream manager lives in core/x/streaming, whose API is still in preview, which is what the -exp in this sample's name marks.

Run it:

go run .

Or with the Dev UI, to call the flow from a browser and read a trace of every run at http://localhost:4000/traces:

curl -sL cli.genkit.dev | bash    # install the Genkit CLI, once
genkit start -- go run .

Or over HTTP. Ask for a stream and keep the X-Genkit-Stream-Id it answers with, which is why this curl passes -i:

curl -N -i -X POST http://localhost:8080/countdown \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -d '{"data": {"count": 5}}'

Then rejoin that stream from anywhere, as many times as you like, by sending the ID back. Do it mid-countdown to see the replay, or after "Liftoff!" to get the finished stream whole:

curl -N -X POST http://localhost:8080/countdown \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -H "X-Genkit-Stream-Id: <id-from-above>" \
  -d '{"data": {"count": 5}}'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL