We have an app that uses SignalR to push messages to the client from an ASP.NET MVC app. The push functionality was previously working but when trying to add a Redis backplane the notifications are no longer pushed to the client. To push the data we have this code on the server side:
public class SignalrDataSync : IDataSync
{
private readonly IHubContext _hubContext;
public SignalrDataSync(IHubContext hubContext)
{
_hubContext = hubContext;
}
public void UpdateSitePartForUser(TmoUser user, SitePart sitePart)
{
var connection = GetConnectionForUser(user);
var view = SitePartViewModel.FromEntity(sitePart);
connection.Invoke("updateClient", view);
}
private IClientProxy GetConnectionForUser(TmoUser user) => _hubContext.Clients.Group(user.UserName);
}
As you can see we push the data to a group that is the user's username. The data is an entity that get converted to a view model before being pushed. To configure the backplane we add to the configuration that is part of the app start:
public class SignalrBootstrapper
{
public void Configuration(IAppBuilder app)
{
var scaleoutConfig = new RedisScaleoutConfiguration(ConnectionStrings.Redis, "CandidateSignalrBackplane");
GlobalHost.DependencyResolver.UseStackExchangeRedis(scaleoutConfig);
// Any connection or hub wire up and configuration should go here
app.MapSignalR();
}
}
I have enabled tracing on SignalR and can see the client connecting and joining the correct group see the message bus logs below (the group here is FRED1003):
SignalR.ScaleoutMessageBus Information: 0 : OnReceived(0, 77, 1) SignalR.ScaleoutMessageBus Verbose: 0 : Received message 77: '{"WaitForAck":false,"Id":"e2786caa-df1b-4892-bfa3-4909ebb82624","CommandType":0,"Value":null}' over ScaleoutMessageBus SignalR.ScaleoutMessageBus Verbose: 0 : Message id: 77, stream : 0, eventKey: 'c-21075c00-9430-48da-91c1-4250ac117407' saved with local id: 0 SignalR.ScaleoutMessageBus Verbose: 0 : Scheduling eventkeys: c-21075c00-9430-48da-91c1-4250ac117407
SignalR.ScaleoutMessageBus Information: 0 : OnReceived(0, 78, 1) SignalR.ScaleoutMessageBus Verbose: 0 : Received message 78: '{"WaitForAck":true,"Id":"20d69878-d5d4-467a-acf5-eabe75160729","CommandType":1,"Value":"hg-SyncHub.FRED1003"}' over ScaleoutMessageBus SignalR.ScaleoutMessageBus Verbose: 0 : Message id: 78, stream : 0, eventKey: 'c-21075c00-9430-48da-91c1-4250ac117407' saved with local id: 1 SignalR.ScaleoutMessageBus Verbose: 0 : Scheduling eventkeys: c-21075c00-9430-48da-91c1-4250ac117407
SignalR.ScaleoutMessageBus Information: 0 : OnReceived(0, 79, 1) SignalR.ScaleoutMessageBus Verbose: 0 : Received message 79: '' over ScaleoutMessageBus SignalR.ScaleoutMessageBus Verbose: 0 : Message id: 79, stream : 0, eventKey: 'SIGNALR__SERVER' saved with local id: 0 SignalR.ScaleoutMessageBus Verbose: 0 : Scheduling eventkeys: SIGNALR__SERVER
SignalR.ScaleoutMessageBus Information: 0 : OnReceived(0, 80, 1) SignalR.ScaleoutMessageBus Verbose: 0 : Received message 80: '{"WaitForAck":true,"Id":"668e5f76-e305-41a4-90a3-deb494b95fb9","CommandType":2,"Value":"hg-SyncHub.FRED1003"}' over ScaleoutMessageBus SignalR.ScaleoutMessageBus Verbose: 0 : Message id: 80, stream : 0, eventKey: 'c-0abd061f-e00f-42c1-b245-fa49903c53bc' saved with local id: 2 SignalR.ScaleoutMessageBus Verbose: 0 : Scheduling eventkeys: c-0abd061f-e00f-42c1-b245-fa49903c53bc
Because this is coming through, I can tell the connection to the redis instance is working (I have also tried manually connecting to redis and subscribing to the channel and can see these messages coming in when the client connects). However, when trying to actually push data, nothing hits redis, so nothing reaches the client.