SignalR.Orleans

by OrleansContrib

OrleansContrib / SignalR.Orleans

SignalR backend based on Orleans.

140 Stars 29 Forks Last release: 12 months ago (v1.5.0) MIT License 114 Commits 30 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

SignalR.Orleans

SignalR.Orleans

Build Package Version NuGet Downloads License Gitter

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()
on
ISiloHostBuilder
.

Example ```cs var silo = new SiloHostBuilder() .UseSignalR() .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

cs
.UseSignalR(cfg =>
{
  cfg.ConfigureBuilder = (builder, config) =>
  {
    builder
      .AddMemoryGrainStorage(config.PubSubProvider)
      .AddMemoryGrainStorage(config.StorageProvider);
  };
})

Client

Now your SignalR application needs to connect to the Orleans Cluster by using an Orleans Client: * Use

.UseSignalR()
on
IClientBuilder
.

Example ```cs var client = new ClientBuilder() .UseSignalR() .Build();

await client.Connect(); ```

Somewhere in your

Startup.cs
: * Add
IClusterClient
(created in the above example) to
IServiceCollection
. * Use
.AddSignalR()
on
IServiceCollection
(this is part of
Microsoft.AspNetCore.SignalR
nuget package). * Use
AddOrleans()
on
.AddSignalR()
.

Example

cs
public void ConfigureServices(IServiceCollection services)
{
  ...
  services
    .AddSingleton(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, IUserNotificationGrain
{
  private HubContext _hubContext;

public override async Task OnActivateAsync() { _hubContext = GrainFactory.GetHub(); // some code... await _hubContext.User(this.GetPrimaryKeyString()).Send("Broadcast", State.UserNotification); } }

Contributions

PRs and feedback are very welcome!

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.