SignalR.Azure.Serverless
1.0.1
Install-Package SignalR.Azure.Serverless -Version 1.0.1
dotnet add package SignalR.Azure.Serverless --version 1.0.1
<PackageReference Include="SignalR.Azure.Serverless" Version="1.0.1" />
paket add SignalR.Azure.Serverless --version 1.0.1
#r "nuget: SignalR.Azure.Serverless, 1.0.1"
// Install SignalR.Azure.Serverless as a Cake Addin
#addin nuget:?package=SignalR.Azure.Serverless&version=1.0.1
// Install SignalR.Azure.Serverless as a Cake Tool
#tool nuget:?package=SignalR.Azure.Serverless&version=1.0.1
SignalR.Azure.Serverless
A helper library for publishing and subscribing to SignalR service running on Azure in serverless mode.
With SignalR serverless, you can publish and subscribe to messages without the need to create an ASP.NET Core API App. You may use this library in ASP.NET Core, Xamarin, WinForm, WPF, or Console applications. Unlike SNS or Azure Event Grid, any app can subscribe to the feed (and publish) so long as the app knows the AccessKey
.
SignalR is not a queue, it's an opportunistic broadcaster. SignalR will broadcast an event to whichever clients are connected to the hub at the time of the event. Any clients which are not connected will miss the event. Sometimes this behaviour is desired.
There are two samples: A WFP App RestaurantTableTracker and a PubSubConsoleApp. See the WPF App for an example on how to handle connection drops.
Sample
public class PubSubSample
{
SignalRHubHelper signalRHubHelper;
HubConnection signalRHubConnection;
public async Task ListenToEvents(string connString)
{
signalRHubHelper = new SignalRHubHelper(connString);
var hubUrl = signalRHubHelper.ClientUrl("default_hub");
// define a connection to receive published events
signalRHubConnection = new HubConnectionBuilder().WithUrl(hubUrl, option =>
{
option.AccessTokenProvider = () =>
{
var token = signalRHubHelper.GenerateAccessToken(hubUrl, "user-x");
return Task.FromResult(token);
};
}).Build();
// define an event handler for received messages
signalRHubConnection.On<string, string>("StatusChanged", (deviceId, status) =>
{
Console.WriteLine($"Device {deviceId} changed status to {status}");
});
// start listening to published events
await signalRHubConnection.StartAsync();
Console.WriteLine("Listening for events...");
}
public async Task PublishTestMessage()
{
using (var httpClient = new HttpClient()) // it is recommened that you re-use the HttpClient
{
var signalRApiClient = new SignalRApiClient(httpClient, signalRHubHelper);
var msg = new SignalRMessage()
{
target = "StatusChanged",
arguments = new object[] { "device_1", "offline" }
};
await signalRApiClient.BroadcastToAllClients(senderUserId: "user-x", hubName: "default_hub", msg);
}
}
public async Task StopListeningToEvents()
{
await signalRHubConnection.DisposeAsync();
}
}
The code is based on samples published by Jeeva Subburaj and is written against v1 of SignalR API.
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net461 net462 net463 net47 net471 net472 net48 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 12.0.2)
- System.IdentityModel.Tokens.Jwt (>= 5.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1 | 914 | 7/1/2019 |
v1.0.1 - Initial Release