Observable channels extension
The observable channels extension layers support for IObserver over the existing Channel API.
It gives the ability to leverage the RX framework and apply RX operators to streams of messages being received over a channel.
To use the extension:
- Reference the OpenFin.Net.Adapter.Extensions.Observable package from NuGet.
- Activate the extension as part of the Runtime builder process by adding a call to UseObservableChannels.
IRuntime runtime = new RuntimeFactory()
.UseObservableChannels()
.GetRuntimeInstance(new RuntimeOptions
{
Version = "stable",
UUID = "UUID_STRING",
LicenseKey = "LICENSE_KEY"
});
To access the API, query the Runtime for IObservableChannels. For example:
// Ask for the observable channels api
var channels = runtime.GetService<IObservableChannels>();
// Create an observable client
IObservableChannelClient client = observableChannels.CreateClient("CHANNEL_NAME");
await client.ConnectAsync();
// Register topic returns an IObservable instance
var unsubscriber = client.RegisterTopic<string>("TOPIC_NAME")
.Throttle( Timespan.FromSeconds( 2 ) )
.Subscribe((payload) =>
{
Debug.WriteLine(payload);
});