Giter VIP home page Giter VIP logo

rebus.signalr's Introduction

Rebus.SignalR

install from nuget

Rebus-based SignalR backplane is useful, if you are using Rebus already and/or would like to leverage Rebus' integration with various transports not supported by SignalR's own backplane integrations.

How to use

Just add AddRebusBackplane<THub>() method call for each hub, that you're going to use with Rebus.SignalR backplane.

services.AddSignalR()
    .AddRebusBackplane<ChatHub>();

Configure Rebus IBus as usual, but keep in mind several things:

  • Use an auto generated unique name for the input queue, that will be used as a backplane. In case of Rebus.RabbitMq you should probably configure the input queue as auto-delete.
  • Enable Rebus.Async with EnableSynchronousRequestReply() method call, if you're going to use AddToGroupAsync() and RemoveFromGroupAsync() in SignalR hubs.
  • If you're using a decentralized subscription storage, for example Sql Server configured with isCentralized option set to false (by default), you have to map Rebus.SignalR backplane commands for each hub to your queue. To do that, just call MapSignalRCommands<THub>() extension method for type-based router:

Sample application 1 (RabbitMq is used as a transport with the centralized subscription storage)

If you have RabbitMq already installed locally, you can run Rebus.SignalR.Samples from your IDE or using "dotnet run" command. Another option is to use Docker Compose command from the root repository directory:

docker-compose up
private static string GenerateTransientQueueName(string inputQueueName)
{
    return $"{inputQueueName}-{Environment.MachineName}-{Guid.NewGuid().ToString()}";
}

public void ConfigureServices(IServiceCollection services)
{
    services.AddSignalR()
        .AddRebusBackplane<ChatHub>();

    var rabbitMqOptions = Configuration.GetSection(nameof(RabbitMqOptions)).Get<RabbitMqOptions>();
            
    var rabbitMqConnectionString =
        $"amqp://{rabbitMqOptions.User}:{rabbitMqOptions.Password}@{rabbitMqOptions.Host}:{rabbitMqOptions.Port.ToString()}";

    services.AddRebus(configure => configure
        .Transport(x =>
        {
            x.UseRabbitMq(rabbitMqConnectionString, GenerateTransientQueueName("Rebus.SignalR"))
            .InputQueueOptions(o =>
            {
                o.SetAutoDelete(true);
                o.SetDurable(false);
            });
        })
        .Options(o => o.EnableSynchronousRequestReply())
        .Routing(r => r.TypeBased()));
}

Sample application 2 (SQL Server is used as a transport with the decentralized subscription storage)

You can modify Rebus.SignalR.Samples application to try out SqlServer transport:

public void ConfigureServices(IServiceCollection services)
{
	services.AddSignalR()
        .AddRebusBackplane<ChatHub>();

	var queueName = GenerateTransientQueueName("Rebus.SignalR");
	services.AddRebus(configure => configure
		.Transport(x => x.UseSqlServer(SignalRBackplaneConnectionString, queueName, isCentralized: false))
        .Options(o => o.EnableSynchronousRequestReply())
        .Routing(r => r.TypeBased()
            .MapSignalRCommands<ChatHub>(queueName))
		.Subscriptions(s => s.StoreInSqlServer(SignalRBackplaneConnectionString, "Subscriptions", false)));                    
}


rebus.signalr's People

Contributors

rsivanov avatar mookid8000 avatar mts44 avatar

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.