Open Closed

Redis backplane for ABP SignalR #1380


User avatar
0
vishalnikam created
  • ABP Framework version: v3.0.4
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:

We have AWS hosting and the SingleR AbpHub is hosted in multiple ECS containers. The SignalR Redis backplane uses the pub/sub feature to forward messages to other servers. could you please help on how to enble radis backplane in ABP SignalR.


16 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Have you tried the steps on this document?

    https://docs.microsoft.com/en-us/aspnet/core/signalr/redis-backplane?view=aspnetcore-5.0

    Configure ISignalRServerBuilder in module.

    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
    	context.Services.PreConfigure<ISignalRServerBuilder>(builder =>
    	{
    		builder.AddStackExchangeRedis("connectionString", options =>
    		{
    			options.Configuration.ChannelPrefix = "MyApp";
    		});
    	});
    }
    
  • User Avatar
    0
    vishalnikam created

    i didnt try steps given in microsoft documnet as it required install Microsoft.AspNetCore.SignalR.StackExchangeRedis and add config setp services.AddSignalR().AddStackExchangeRedis("<your_Redis_connection_string>");

    But i tried your suggeted preconfig in my appservice module but it didnt worked in AWS ECS. please find below current config and let me know, if anything else is required

    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        var hostingEnvironment = context.Services.GetHostingEnvironment();
    
        var configuration = context.Services.GetConfiguration();
    
        if (!hostingEnvironment.IsDevelopment())
        {
            context.Services.PreConfigure<ISignalRServerBuilder>(builder =>
            {
                builder.Services.AddStackExchangeRedisCache(options =>
                {
                    options.Configuration = configuration["Redis:Configuration"];
                });
            });
        }
      }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You should follow the steps and code in the document to try. If it doesn't work, please check the logs to know what's wrong.

  • User Avatar
    0
    vishalnikam created

    Hi,

    As per Microsoft document, we need to add services.AddSignalR().AddStackExchangeRedis("<your_Redis_connection_string>"); in configservices but as per ABP documement, it says that You don't need to use the services.AddSignalR() and the app.UseEndpoints(...), it's done by the AbpAspNetCoreSignalRModule. we are using AbpAspNetCoreSignalRModule module

    https://docs.abp.io/en/abp/latest/SignalR-Integration

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    we need to add services.AddSignalR().AddStackExchangeRedis("<your_Redis_connection_string>");

    Yes, but you need to configure the ISignalRServerBuilder.

    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
    	context.Services.PreConfigure<ISignalRServerBuilder>(builder =>
    	{
    		builder.AddStackExchangeRedis("connectionString", options =>
    		{
    			options.Configuration.ChannelPrefix = "MyApp";
    		});
    	});
    }
    
  • User Avatar
    0
    vishalnikam created

    Yes, i did. here is sample code. i dont get option for AddStackExchangeRedis

    public override void PreConfigureServices(ServiceConfigurationContext context) { var hostingEnvironment = context.Services.GetHostingEnvironment();

    var configuration = context.Services.GetConfiguration();
    
    if (!hostingEnvironment.IsDevelopment())
    {
        context.Services.PreConfigure&lt;ISignalRServerBuilder&gt;(builder =>
        {
            builder.Services.AddStackExchangeRedisCache(options =>
            {
                options.Configuration = configuration["Redis:Configuration"];
            });
        });
    }
    

    }

    also, do you mein i need to add services.AddSignalR().AddStackExchangeRedisCache("<your_Redis_connection_string>"); in configservice as well ?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You need install the Microsoft.AspNetCore.SignalR.StackExchangeRedis package. https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.StackExchangeRedis/

    Then

    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
    	context.Services.PreConfigure<ISignalRServerBuilder>(builder =>
    	{
    		builder.AddStackExchangeRedis("connectionString", options =>
    		{
    			options.Configuration.ChannelPrefix = "MyApp";
    		});
    	});
    }
    
  • User Avatar
    0
    vishalnikam created

    Hi,

    I tried with given approach but no success. still facing same issue. SingalR pub/sub is working fine with single ECS container but not with multiple.

    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        var hostingEnvironment = context.Services.GetHostingEnvironment();
    
        var configuration = context.Services.GetConfiguration();
    
        if (!hostingEnvironment.IsDevelopment())
        {
            var redis = configuration["Redis:Configuration"];
    
            context.Services.PreConfigure<ISignalRServerBuilder>(builder =>
            {
                builder.AddStackExchangeRedis(redis, options =>
                {
                    options.Configuration.ChannelPrefix = "InvoiceManagement";
                });
            });
    
        }
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    HI

    Is there any messages in the logs?

  • User Avatar
    0
    vishalnikam created

    Hi,

    There is no issue found in logs related to SignalR but it is not working as expected . 1 ECS container message is not getting to other container.

  • User Avatar
    0
    alper created
    Support Team Director

    any logs in browser?

  • User Avatar
    0
    vishalnikam created

    Hi,

    there is no issue log in browser either. as said we are running this invoice service in multiple container so one only get the hub notification to the user connetced to the same container and rest users connected to other container not getting notification. this should be solve by Redis backplane but given solution is not working.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I can't think of any possible reasons, we have followed Microsoft's documentation.

    Can you try to use redis backplane in non-abp applications?

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

  • User Avatar
    1
    petro.samoshkin@advantiss.com created

    We had the same issue after disabling "sticky" sessions on the scaled-out Azure AppService host. Appeared that SignalR protocol performs first call to negotiate protocol, then second call randomly can be sent to another node. This can be fixed by disabling negotiation on client side. This fix helped us. Please add this point to the ABP SignalR integration documentation because it makes pain for everybody who tries to scaling out the backend with use of custom Redis backplane.

    const options = {
          skipNegotiation: true,
          transport: 1 // WebSockets
        };
    

    https://github.com/dotnet/aspnetcore/issues/11678

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Thanks petro.samoshkin

Made with ❤️ on ABP v9.1.0-preview. Updated on November 18, 2024, 05:54