Search code examples
signalrazureservicebussignalr-backplane

How can we send notifcation to authenticate user on Signalr which uses BackPlane?


We are using Azure Service Bus Topics as a backplane for signalR and we have at least 2 web instances. We want to send a notification to a specific user with SignalR. We are using "context.Clients.User" method on a web instance.

If the user is connected to this web instance and authenticated, he/she gets notification.

The problem is that: if the user is authenticated on other web instance, this does not work.

How can we send notification to user on another web instance ?

We are using Autofac.SignalR and SignalR.ServiceBus

IOC Configuration:

var builder = new ContainerBuilder();
                        .
                        .
                        .
                        .
                        .

 Container = builder.Build();
            RegisterGlobalCommonServiceLocator();

            var resolver = new AutofacWebApiDependencyResolver(Container);

            GlobalConfiguration.Configuration.DependencyResolver = resolver;
            DependencyResolver.SetResolver(new AutofacDependencyResolver(Container));

            var connectionString = ConfigurationManager.AppSettings["SignalRBrokerServiceBus"];
            var appName = ConfigurationManager.AppSettings["SignalRApplicationName"];

            GlobalHost.DependencyResolver = new Autofac.Integration.SignalR.AutofacDependencyResolver(Container);
            var scaleOutConfig = new ServiceBusScaleoutConfiguration(connectionString, appName);
            GlobalHost.DependencyResolver.UseServiceBus(scaleOutConfig);

Usage of contex ExchangeRate is derived class from Hub:

var user = _userService.FindById(orderBook.UserId);
        var context =GlobalHost.ConnectionManager.GetHubContext<ExchangeRate>();
        context.Clients.User(user.Email).deleteMyOrder(myOrder);

Solution

  • It's related with topic configuration on azure. We crated a topics with "enable partitioning". We were missing many messages.Now, Topics are created by IOC. It's work fine. I have tested on both instances. context.Clients.User works fine.