Legacy Streaming Examples
Section titled “Legacy Streaming Examples”Archived and unsupported. This material is retained only to help migrate existing applications. There is no new Legacy release line, feature or compatibility work, or security fixes. New development must use the current functional API.
Streaming examples for the original Orleans.FSharp grain authoring model.
The streaming modules remain current. This page only isolates the old grain-definition examples which previously appeared in the current guide. New actors use the functional
grainContract/grainForsubscription operations.
On the classic grain { } / C# class path
Section titled “On the classic grain { } / C# class path”Implicit subscriptions there are a per-grain Orleans attribute. The universal grain pattern shares
a single FSharpGrainImpl class, so it cannot carry a per-grain
[ImplicitStreamSubscription("namespace")]. When maintaining a legacy application which already
has an application-owned concrete C# grain class, annotate that class directly. The repository’s
CodeGen project is archived, non-packable source, and its retained generator does not create
ordinary grain classes. For new actors, use the functional subscription operations; for explicit
subscriptions from any grain, use Stream.subscribe (shown above), which works with the universal
pattern.
Complete Example
Section titled “Complete Example”open Orleans.FSharp.Runtimeopen Orleans.FSharp.Streaming
// Configurelet config = siloConfig { useLocalhostClustering addMemoryStorage "Default" addMemoryStreams "Events" addBroadcastChannel "Alerts"}
// Publish from a grain handlerlet publisher = grain { defaultState () handleWithContext (fun ctx state msg -> task { let streamProvider = GrainContext.getService<IClusterClient> ctx |> fun c -> c.GetStreamProvider("Events") let stream = Stream.getStream<string> streamProvider "logs" "app" do! Stream.publish stream $"Event: {msg}" return (), box () }) }
// Subscribe from client codelet streamProvider = client.GetStreamProvider("Events")let stream = Stream.getStream<string> streamProvider "logs" "app"
let! sub = Stream.subscribe stream (fun msg -> task { printfn "Log: %s" msg })
// Pull-based consumptionlet events = Stream.asTaskSeq streamfor event in events do printfn "Pulled: %s" eventCurrent guide
Section titled “Current guide”See Streaming for functional onStream and onBroadcast subscriptions.