basic-durable-streaming-exp

command
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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