2

We have configured the redis backplane in owin startup code of the web app.

var config = new RedisScaleoutConfiguration(hangfireRedisConnection, scaleoutEventKey);
GlobalHost.DependencyResolver.UseRedis(config);

app.MapSignalR();

The web app runs a background job on a timer, that wakes up and notifies the client if an important event took place. After querying the backend, the background job calls into a simple HubService wrapper that takes IHubContext as a dependency and eventually calls Client.All.notify method on the hub to push down to the client:

HubService:

private readonly IHubContext applicationHub;

public HubService(IHubContext applicationHub)
{
    this.applicationHub = applicationHub;
} 

public void NotifyClient()
{
    hubContext.Client.All.nofify(message); // <- this is always called, with and without the backplane, however with the backplane it doesn't make it to the client
}

HubContext is registered at the startup:

Container.RegisterInstance<IHubContext>(GlobalHost.ConnectionManager.GetHubContext<ApplicationHub>());

This works fine without the backplane, but doesn't with the backplane configured. I have verified in the debugger that the call is being made, but it doesn't make it down to the client.

Also, if we call signalr hub from the client (outside of the web app) either through js or signalr.client clients, the backplane works as advertised.

Is there something missing in the scenario where we're calling directly into hub context from within the web app itself without initiating the call from the client first?

tstojecki
  • 1,480
  • 2
  • 19
  • 29
  • Are you using some sort of dependency resolver? – radu-matei Mar 01 '16 at 21:38
  • Is your Redis instance running inside a cluster? – radu-matei Mar 01 '16 at 21:38
  • Please share (if possible) the code in `Startup` and in the job notifying the clients. Thanks! – radu-matei Mar 01 '16 at 21:39
  • Updated the question with code references. It is using Autofac for DI. Redis is not inside a cluster. – tstojecki Mar 02 '16 at 10:04
  • Can you follow this [document](http://docs.autofac.org/en/latest/integration/signalr.html) – Erkan Demirel Apr 17 '16 at 14:16
  • @ErkanDemirel can you explain why you think this is relevant? The document describes wiring up Autofac for DI. The question is about a specific scenario where the scaleout isn't working. – tstojecki Apr 19 '16 at 08:33
  • Yes it is because you register your hubcontext with autofac. I'm using autofac and service bus backplane. It's not just showing configuration also it shows how you should manage lifetime of hub and the lifetimescope in hub. – Erkan Demirel Apr 19 '16 at 08:36
  • any updates on this one ? I have a similar problem , but I am using my custom DI container . – Claudiu Jan 31 '17 at 09:36
  • Any updates? Got the same issue.. – Casper TL Dec 11 '19 at 14:17
  • It can be fixed by updating a context before broadcasting like: hubContext = GlobalHost.ConnectionManager.GetHubContext(); hubContext.Client.All.nofify(message); Adding Redis backplane somehow invalidates initially registered one. I'm still investigating it... – Maksim Ramanovich Nov 09 '21 at 13:55

0 Answers0