https://github.com/managedcode/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.
https://github.com/managedcode/orleans.signalr
orleans signalr signalr-server
Last synced: 5 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/managedcode/orleans.signalr
- Owner: managedcode
- License: mit
- Created: 2023-04-04T07:30:15.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-19T12:27:41.000Z (10 months ago)
- Last Synced: 2024-11-02T05:19:10.975Z (6 months ago)
- Topics: orleans, signalr, signalr-server
- Language: C#
- Homepage:
- Size: 163 KB
- Stars: 19
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```csharp
clientBuilder.Services
.AddSignalR()
.AddOrleans();
```### Server Configuration
To use Orleans.SignalR on the server, add the following code to your server configuration:
```csharp
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```csharp
public class TestGrain : Grain, ITestGrain
{
private readonly IHubContext _hubContext;public TestGrain(IHubContext hubContext)
{
_hubContext = hubContext;
}public Task PushRandom()
{
return _hubContext.Clients.All.SendAsync("SendRandom", new Random().Next());
}
}
```You can use typed Orleans client, with interface IOrleansHubContext
```csharp
public class TestGrain : Grain, ITestGrain
{
private readonly IOrleansHubContext _hubContext;public TestGrain(IOrleansHubContext 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:```csharp
public async Task GetMessage(string connectionId)
{
var message = await Task.Run(() => _hubContext.Clients.Client(connectionId)
.InvokeAsync("GetMessage", CancellationToken.None));
return message;
}
```## Contributing
We welcome contributions! If you encounter any bugs or have feature requests,
please [open an issue](https://github.com/managedcode/Orleans.SignalR/issues).
If you want to contribute code, please fork the repository and submit a pull request.## License
Orleans.SignalR is licensed under the [MIT License](LICENSE).
## Credits
Orleans.SignalR is based on the work of the Orleans community and the SignalR team at Microsoft.