SignalR.Orleans
2.1.0
See the version list below for details.
dotnet add package SignalR.Orleans --version 2.1.0
NuGet\Install-Package SignalR.Orleans -Version 2.1.0
<PackageReference Include="SignalR.Orleans" Version="2.1.0" />
paket add SignalR.Orleans --version 2.1.0
#r "nuget: SignalR.Orleans, 2.1.0"
// Install SignalR.Orleans as a Cake Addin #addin nuget:?package=SignalR.Orleans&version=2.1.0 // Install SignalR.Orleans as a Cake Tool #tool nuget:?package=SignalR.Orleans&version=2.1.0
Orleans is a framework that provides a straight-forward approach to building distributed high-scale computing applications, without the need to learn and apply complex concurrency or other scaling patterns.
ASP.NET Core SignalR is a new library for ASP.NET Core developers that makes it incredibly simple to add real-time web functionality to your applications. What is "real-time web" functionality? It's the ability to have your server-side code push content to the connected clients as it happens, in real-time.
SignalR.Orleans is a package that allow us to enhance the real-time capabilities of SignalR by leveraging Orleans distributed cloud platform capabilities.
Installation
Installation is performed via NuGet
From Package Manager:
PS> Install-Package SignalR.Orleans
.Net CLI:
# dotnet add package SignalR.Orleans
Paket:
# paket add SignalR.Orleans
Configuration
Silo
We need to configure the Orleans Silo with the below:
- Use
.UseSignalR()
onISiloHostBuilder
. - Make sure to call
RegisterHub<THub>()
whereTHub
is the type of the Hub you want to be added to the backplane.
Example
var silo = new SiloHostBuilder()
.UseSignalR()
.RegisterHub<MyHub>() // You need to call this per `Hub` type.
.AddMemoryGrainStorage("PubSubStore") // You can use any other storage provider as long as you have one registered as "PubSubStore".
.Build();
await silo.StartAsync();
Configure Silo Storage Provider and Grain Persistance
Optional configuration to override the default implementation for both providers which by default are set as Memory
.
Example
.UseSignalR(cfg =>
{
cfg.ConfigureBuilder = (builder, config) =>
{
builder
.AddMemoryGrainStorage(config.PubSubProvider)
.AddMemoryGrainStorage(config.StorageProvider);
};
})
.RegisterHub<MyHub>()
Client
Now your SignalR application needs to connect to the Orleans Cluster by using an Orleans Client:
- Use
.UseSignalR()
onIClientBuilder
.
Example
var client = new ClientBuilder()
.UseSignalR()
.Build();
await client.Connect();
Somewhere in your Startup.cs
:
- Add
IClusterClient
(created in the above example) toIServiceCollection
. - Use
.AddSignalR()
onIServiceCollection
(this is part ofMicrosoft.AspNetCore.SignalR
nuget package). - Use
AddOrleans()
on.AddSignalR()
.
Example
public void ConfigureServices(IServiceCollection services)
{
...
services
.AddSingleton<IClusterClient>(client)
.AddSignalR()
.AddOrleans();
...
}
Great! Now you have SignalR configured and Orleans SignalR backplane built in Orleans!
Features
Hub Context
HubContext
gives you the ability to communicate with the client from orleans grains (outside the hub).
Sample usage: Receiving server push notifications from message brokers, web hooks, etc. Ideally first update your grain state and then push signalr message to the client.
Example
public class UserNotificationGrain : Grain<UserNotificationState>, IUserNotificationGrain
{
private HubContext<IUserNotificationHub> _hubContext;
public override async Task OnActivateAsync()
{
_hubContext = GrainFactory.GetHub<IUserNotificationHub>();
// some code...
await _hubContext.User(this.GetPrimaryKeyString()).Send("Broadcast", State.UserNotification);
}
}
Complete examples
Cohosting aspnetcore website and orleans
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Orleans;
using Orleans.Hosting;
// Cohosting aspnetcore website and Orleans with signalR
var host = Host.CreateDefaultBuilder(args)
// Add the webhost with SignalR configured.
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureServices((webBuilderContext, services) =>
{
// Add response compression used by the SignalR hubs.
services.AddResponseCompression(opts =>
{
opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
new[] { "application/octet-stream" });
});
// Adds SignalR hubs to the aspnetcore website
services.AddSignalR(options =>
{
})
.AddOrleans(); // Tells SignalR to use Orleans as the backplane.
});
webBuilder.Configure((ctx, app) =>
{
// Adds response compression for use by the SignalR hubs
app.UseResponseCompression();
// Map SignalR hub endpoints
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<MyHubType1>("/hub1"); // use your own hub types
endpoints.MapHub<MyHubType2>("/hub2"); // use your own hub types
// ... etc
});
});
})
// Add Orleans with SignalR configured
.UseOrleans((context, siloBuilder) =>
{
siloBuilder
.UseSignalR(signalRConfig =>
{
// Optional.
signalRConfig.UseFireAndForgetDelivery = true;
signalRConfig.Configure((siloBuilder, signalRConstants) =>
{
// **************************************************************************
// Use memory storage ONLY when your app is not clustered, otherwise you'll
// need to use proper external storage providers
// **************************************************************************
siloBuilder.AddMemoryGrainStorage(signalRConstants.StorageProvider);
// This wouldn't be be necessary if you already added "PubSubStore" elsewhere.
siloBuilder.AddMemoryGrainStorage(signalRConstants.PubSubProvider /*Same as "PubSubStore"*/);
});
})
// Allows Orleans grains to inject IHubContext<HubType>
.RegisterHub<MyHubType1>()
.RegisterHub<MyHubType2>();
// ... etc
})
.UseConsoleLifetime()
.Build();
await host.StartAsync();
await host.WaitForShutdownAsync(default);
Contributions
PRs and feedback are very welcome!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- Microsoft.Orleans.Core (>= 3.5.0)
- Microsoft.Orleans.OrleansProviders (>= 3.5.0)
- Microsoft.Orleans.Runtime.Abstractions (>= 3.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 |
---|---|---|
7.2.0 | 10,903 | 8/28/2023 |
7.1.0 | 9,285 | 2/15/2023 |
7.0.1 | 829 | 2/14/2023 |
2.2.1 | 6,548 | 1/19/2023 |
2.2.0 | 10,752 | 8/8/2022 |
2.1.0 | 20,483 | 10/5/2021 |
2.0.1 | 6,515 | 2/15/2021 |
1.5.0 | 22,619 | 11/1/2019 |
1.4.4 | 12,757 | 11/1/2019 |
1.4.3 | 7,502 | 9/23/2019 |
1.4.2 | 2,891 | 9/8/2019 |
1.4.0 | 4,003 | 7/8/2019 |
1.3.2 | 3,635 | 6/13/2019 |
1.3.1 | 1,622 | 6/10/2019 |
1.2.0 | 3,036 | 3/21/2019 |
1.1.2 | 1,456 | 2/25/2019 |
1.1.1 | 1,885 | 1/24/2019 |
1.0.6 | 3,890 | 10/12/2018 |
1.0.5 | 2,138 | 7/24/2018 |
1.0.4 | 1,502 | 7/24/2018 |
1.0.3 | 1,508 | 7/4/2018 |
1.0.2 | 1,660 | 7/4/2018 |
1.0.1 | 1,695 | 6/23/2018 |
1.0.0-preview-65 | 1,719 | 5/31/2018 |
1.0.0-preview-63 | 1,549 | 5/8/2018 |
1.0.0-preview-60 | 1,458 | 4/25/2018 |
1.0.0-preview-58 | 1,391 | 4/24/2018 |
1.0.0-preview-52 | 1,555 | 3/28/2018 |
1.0.0-preview-50 | 1,719 | 3/28/2018 |
1.0.0-preview-47 | 1,508 | 3/16/2018 |
1.0.0-preview-44 | 1,503 | 3/13/2018 |
1.0.0-preview-42 | 1,472 | 3/5/2018 |
1.0.0-preview-39 | 1,497 | 3/5/2018 |
1.0.0-preview-37 | 1,441 | 3/2/2018 |
1.0.0-preview-32 | 1,895 | 12/21/2017 |
1.0.0-preview-26 | 1,388 | 12/12/2017 |
1.0.0-preview-22 | 1,365 | 11/24/2017 |
1.0.0-preview-19 | 1,333 | 11/22/2017 |