Please star this project if you find it useful. Thank you.
I wanted to make it super easy to set up a Relay Hybrid Connection for Azure. And I wanted to base it on Reactive Extensions (Rx). Rx is an API for asynchronous programming with observable streams and make perfect sense in a relay scenario.
For an introduction to Azure Relay Hybrid Connects see: Get started with Relay Hybrid Connections
Using this library is super easy. Follow these examples or see the console sample application
var relayListener = new RelayListenerService();
var listener = await relayListener.RelayListenerInitializeAsync(relayNameSpace, connectionName, keyName, key);
listener.relayConnectionStateObservable.Subscribe(state =>
{
Console.WriteLine($"Listener state: {state}");
},
ex => Console.WriteLine($"State Listener State exception: {ex}"),
() => Console.WriteLine("State Listener Completed"));
listener.messageObservable.Subscribe(async msg =>
{
Console.WriteLine($"Listener Recieved Message: {msg.IncomingMessage}");
// Send an echo back to the client
await msg.ResponseMessageAsync($"Echo: {msg.IncomingMessage}");
},
ex => Console.WriteLine($"Message Listener exception: {ex}"),
() => Console.WriteLine("Message Listener Completed"));
var relayClient = new RelayClientService();
var clientObservable = await relayClient.RelayClintObservableInitializeAsync(relayNameSpace, connectionName, keyName, key);
clientObservable.Subscribe(msg =>
{
Console.WriteLine($"Client received: {msg}");
},
ex => Console.WriteLine($"Client exception: {ex}"),
() => Console.WriteLine("Client Completed"));
await relayClient.SendAsync("Test");
Note: The client myst be initilized before messages can be send.