Rebus.SignalR icon indicating copy to clipboard operation
Rebus.SignalR copied to clipboard

Intermittent missed messages with SQL Server

Open elylv opened this issue 2 years ago • 2 comments

I am using Rebus with SQL Server backing, to send SignalR messages from the server to the client.

        services.AddSignalR()
            .AddRebusBackplane<NotificationHub>();
        var conn = configuration["ConnectionStrings:DefaultConnection"];
        services.AddRebus(conf => conf
        .Transport(t => t.UseSqlServer(new SqlServerTransportOptions(conn), "MessageQueue").SetEnsureTablesAreCreated(false))
        .Options(o => { o.EnableSynchronousRequestReply(); o.SimpleRetryStrategy("MessageErrors", 10); })
        .Logging(l => l.Serilog())
        .Routing(r => r.TypeBased()
                .MapSignalRCommands<NotificationHub>("MessageQueue"))
            .Subscriptions(s => s.StoreInSqlServer(conn, "MessageSubscriptions", false))
        );

When it comes to sending a message e.g. await hubContext.Clients.User(user.UserName).SendAsync("NewNotification", unreadNotifs, notifdtos); it works, but very intermittently.

I can view the websocket communication between the browser and the server, and I see valid pings back and forward between them, but intermittently, it doesn't send some messages (no websocket communication seen, but no errors raised), and I can't work out why. If I remove the AddRebusBackplane and just use normal SignalR, everything works fine. But in my production environment, I am load balanced and need to have the SignalR hubs centralized, so need to use Rebus.

Any ideas?

elylv avatar Oct 17 '22 20:10 elylv

@rsivanov Any idea what could cause this?

mookid8000 avatar Nov 07 '22 21:11 mookid8000

Are you working behind a "special" firewall? For test purposes change the HttpTransportType from your Hub to HttpTransportType.WebSockets | HttpTransportType.LongPolling:

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHub<RegistrationHub>("/registrationHub", options =>
                {
                    options.Transports = HttpTransportType.WebSockets | HttpTransportType.LongPolling;
                });
            });

I had a similar issue with load balancer. This is probably not an issue with Rebus package.

kzimny avatar Sep 26 '23 11:09 kzimny