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.
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:
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()));
}
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)));
}