Code Monkey home page Code Monkey logo

managedcode / orleans.signalr Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 0.0 153 KB

Orleans.SignalR is a lightweight, open-source library that enables easy integration of SignalR with Orleans, a distributed virtual actor model framework for building scalable, fault-tolerant systems. The library provides a SignalR backplane, allowing you to effortlessly add real-time communication capabilities to your distributed systems.

License: MIT License

C# 100.00%
orleans signalr signalr-server

orleans.signalr's Introduction

Orleans.SignalR

Orleans.SignalR is a lightweight, open-source library that enables easy integration of SignalR with Orleans, a distributed virtual actor model framework for building scalable, fault-tolerant systems. The library provides a SignalR backplane, allowing you to effortlessly add real-time communication capabilities to your distributed systems.

Features

Orleans.SignalR offers the following features:

  • Simple and clear implementation
  • Seamless integration with SignalR
  • Support for all SignalR functions, including ClientInvocation

Installation

You can install Orleans.SignalR using Nuget

For Client

Install-Package ManagedCode.Orleans.SignalR.Client

For Server

Install-Package ManagedCode.Orleans.SignalR.Server

Usage

Client Configuration

To use Orleans.SignalR on the client, add the following code to your client configuration:

clientBuilder.Services
    .AddSignalR()
    .AddOrleans();

Server Configuration

To use Orleans.SignalR on the server, add the following code to your server configuration:

siloBuilder.ConfigureOrleansSignalR();
siloBuilder.AddMemoryGrainStorage(OrleansSignalROptions.OrleansSignalRStorage);
siloBuilder.Services            
    .AddSignalR()
    .AddOrleans();

Using HubContext in Grain

In this example, TestGrain defines the interface for the grain, and TestGrain inject the interface for sending messages using SignalR

public class TestGrain : Grain, ITestGrain
{
    private readonly IHubContext<InterfaceTestHub> _hubContext;

    public TestGrain(IHubContext<InterfaceTestHub> hubContext)
    {
        _hubContext = hubContext;
    }

    public Task PushRandom()
    {
        return _hubContext.Clients.All.SendAsync("SendRandom", new Random().Next());
    }
}

You can use typed Orleans client, with interface IOrleansHubContext

public class TestGrain : Grain, ITestGrain
{
    private readonly IOrleansHubContext<InterfaceTestHub, IClientInterfaceHub> _hubContext;

    public TestGrain(IOrleansHubContext<InterfaceTestHub, IClientInterfaceHub> hubContext)
    {
        _hubContext = hubContext;
    }

    public Task PushRandom()
    {
        return _hubContext.Clients.All.SendMessage(this.GetPrimaryKeyString());
    }
}

Using ClientInvocation

Orleans.SignalR supports all functions from SignalR, including ClientInvocation. However, to avoid blocking tasks, use Task.Run. Here's an example:

public async Task<string> GetMessage(string connectionId)
{
    var message = await Task.Run(() => _hubContext.Clients.Client(connectionId)
        .InvokeAsync<string>("GetMessage", CancellationToken.None));
        
    return message;
}

Contributing

We welcome contributions! If you encounter any bugs or have feature requests, please open an issue. If you want to contribute code, please fork the repository and submit a pull request.

License

Orleans.SignalR is licensed under the MIT License.

Credits

Orleans.SignalR is based on the work of the Orleans community and the SignalR team at Microsoft.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.