public static void AddSignalRHubEndpoints <THub, TEndpointConfigurator>(this IBusFactoryConfigurator configurator, IServiceProvider serviceProvider, IHost host, Action <TEndpointConfigurator> configureEndpoint = null) where TEndpointConfigurator : class, IReceiveEndpointConfigurator where THub : Hub { var consumers = HubConsumersCache.GetOrAdd <THub>(); var queueNameBase = host.Topology.CreateTemporaryQueueName($"signalRBackplane-{typeof(THub).Name}-"); // Loop through our 5 hub consumers and create a temporary endpoint for each foreach (var consumerType in consumers) { // remove `1 from generic type var name = consumerType.Name; int index = name.IndexOf('`'); if (index > 0) { name = name.Remove(index); } configurator.ReceiveEndpoint(new HubEndpointDefinition <THub>(), null, e => { configureEndpoint?.Invoke((TEndpointConfigurator)e); e.ConfigureConsumer(serviceProvider, consumerType); }); } }
public static void AddSignalRHubConsumers <THub>(this IServiceCollectionConfigurator configurator) where THub : Hub { configurator.AddRequestClient <GroupManagement <THub> >(TimeSpan.FromSeconds(10)); var consumers = HubConsumersCache.GetOrAdd <THub>(); foreach (var consumer in consumers) { configurator.AddConsumer(consumer); } }
public static void AddMassTransitBackplane(this ISignalRServerBuilder signalRServerBuilder, params Assembly[] hubAssemblies) { IEnumerable <Type> hubs = from a in hubAssemblies from t in a.GetTypes() where typeof(Hub).IsAssignableFrom(t) select t; foreach (var hub in hubs) { var consumerTypes = HubConsumersCache.GetOrAdd(hub); foreach (var consumer in consumerTypes) { signalRServerBuilder.Services.AddScoped(consumer); } } signalRServerBuilder.Services.AddSingleton(typeof(HubLifetimeManager <>), typeof(MassTransitHubLifetimeManager <>)); }