asp.netsignalrsignalr-huborleans

Broadcast SignalR message to all clients in Orleans


Regular SignalR has ability to broadcast messages without filtering.

https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-server#selectingclients

Clients.All.Send()

This would broadcast message to all clients connected to Hub. Meanwhile, SignalR.Orleans seems to provide only messages to specific group.

HubContext.Group(groupName).Send()

https://github.com/OrleansContrib/SignalR.Orleans/blob/master/samples/ChatSample/Grains/UserNotificationGrain.cs

Question

Is there a way to broadcast SignalR message in Orleans without filtering and creating groups?

enter image description here


Solution

  • you can use IHubContext<THub>.Clients.All and it would work fine.

    The SignalR.Orleans package implement its own HublifetimeManager(github) and when you config SignalR to AddOrleans it would replace the DefaultHublifetimeManager(github) with its own implementation so any usage of IHubContext<THub>.Clients or IHubContext<THub>.Groups would use Orleans implementation of HublifetimeManager. So when you use IHubContext<THub>.Clients.All it would use OrleansHubLifetimeManager<THub> to send message and in detail it would broadcast your message to all silos with help of Orleans Streams

    Just For More Info: IHubContext<THub>.Clients.All return an instance of AllClientProxy<THub> which it's using HublifetimeManager.SendAllAsync method to send messages