1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-06 21:48:12 -05:00

signalr redis support. remove old azure signalr refs

This commit is contained in:
Kyle Spearrin 2020-03-04 21:57:42 -05:00
parent 7b91fe55f0
commit c8d7f04826
3 changed files with 13 additions and 20 deletions

View File

@ -157,7 +157,7 @@ namespace Bit.Core
public class NotificationsSettings : ConnectionStringSettings public class NotificationsSettings : ConnectionStringSettings
{ {
public string AzureSignalRConnectionString { get; set; } public string RedisConnectionString { get; set; }
} }
public class NotificationHubSettings public class NotificationHubSettings

View File

@ -8,8 +8,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.0" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="3.1.2" />
<PackageReference Include="Microsoft.Azure.SignalR" Version="1.2.3" /> <PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="3.1.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -57,9 +57,13 @@ namespace Bit.Notifications
MessagePack.Resolvers.ContractlessStandardResolver.Instance MessagePack.Resolvers.ContractlessStandardResolver.Instance
}; };
}); });
if(!string.IsNullOrWhiteSpace(globalSettings.Notifications?.AzureSignalRConnectionString)) if(!string.IsNullOrWhiteSpace(globalSettings.Notifications?.RedisConnectionString))
{ {
signalRServerBuilder.AddAzureSignalR(globalSettings.Notifications.AzureSignalRConnectionString); signalRServerBuilder.AddStackExchangeRedis(globalSettings.Notifications.RedisConnectionString,
options =>
{
options.Configuration.ChannelPrefix = "Notifications";
});
} }
services.AddSingleton<IUserIdProvider, SubjectUserIdProvider>(); services.AddSingleton<IUserIdProvider, SubjectUserIdProvider>();
services.AddSingleton<ConnectionCounter>(); services.AddSingleton<ConnectionCounter>();
@ -105,25 +109,14 @@ namespace Bit.Notifications
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
// Add SignlarR
var useAzureSignalR = !string.IsNullOrWhiteSpace(
globalSettings.Notifications?.AzureSignalRConnectionString);
if(useAzureSignalR)
{
app.UseAzureSignalR(routes => routes.MapHub<NotificationsHub>("/hub"));
}
// Add endpoints to the request pipeline. // Add endpoints to the request pipeline.
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
if(!useAzureSignalR) endpoints.MapHub<NotificationsHub>("/hub", options =>
{ {
endpoints.MapHub<NotificationsHub>("/hub", options => options.ApplicationMaxBufferSize = 2048; // client => server messages are not even used
{ options.TransportMaxBufferSize = 4096;
options.ApplicationMaxBufferSize = 2048; // client => server messages are not even used });
options.TransportMaxBufferSize = 4096;
});
}
endpoints.MapDefaultControllerRoute(); endpoints.MapDefaultControllerRoute();
}); });
} }