aspnet / SignalR

[Archived] Incredibly simple real-time web for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
2.38k stars 448 forks source link

Is it possible to configure Channel names when using Redis? #2671

Closed josemaia closed 6 years ago

josemaia commented 6 years ago

Hello,

In an application that is using SignalR and has Redis configured, is there a way we can customize the channel names used?

My situation is as follows:

From what I can tell of the way SignalR uses redis pub/sub, this would lead to potential conflicts - while for two VMs of the same customer, we do want the SignalR channels to be shared, we don't want to receive messages from one customer in the other.

An example would be: imagine I am logged in on Customer A and Customer B's installations, with the same email, and a web page open on both. One of my hubs has a pubsub channel with the format "WebApi.Services.SignalR.NotificationHub:user:jose.maia@example.com". Upon doing an async API request for Customer A, whether it hits server A1 or A2, I should get my notification on web page A. However, if the channel has the same format on customer B's hubs, I will also get the notification on web page B, correct?

From looking at the code, I believe that RedisChannels's usage of a prefix would allow for this, if instead of the RedisHubLifetimeManager instancing RedisChannels just with the Hub's FullName, there was an option to allow a custom prefix (or... pre-prefix, I guess? :) ).

Is there a way to avoid this or, by design, each customer would require a separate Redis server?

Thanks in advance.

analogrelay commented 6 years ago

You can get access to the Configuration options for StackExchange.Redis (the Redis client we use) by providing a delegate to the .AddRedis call. Those options should have a ChannelPrefix somewhere that allows you to specify a prefix for all channels.

That's the only customization we have for Redis channel names.

josemaia commented 6 years ago

That works, for our purposes. Thanks!