Distributed architecture with MassTransit, RabbitMQ and SignalR

巧了我就是萌 提交于 2019-12-03 05:51:59

I do this using hubs from SignalR, and observe events at the server using regular MassTransit consumers. When events are observed, I trigger the event handler, which dispatches using the Hub to connected clients. That way, the events are pushed down to the browser instantly without leaving an async call pending at the server in a controller.

You can see this in Fooidity which does something similar:

https://github.com/phatboyg/Fooidity/blob/develop/src/Fooidity.Management.Web/Hubs/ApplicationHubEventHandler.cs#L18

Using the GlobalHost to resolve the Hub, then raising the method on the hub. The event context can be discriminated by using groups, which are a SignalR feature that is handled per node. So as long as every node is observing the event, clients can be connected to any hub and get notified. This works nicely for load balancing, without having to use a heavy cluster backplane for SignalR -- since RabbitMQ is super lightweight for event distribution.

You can do it with non-durable queues as well, which makes it even faster -- since a server reset/connection drop is more likely than a broker crash.

Authentication is handled inside the ApplicationHub, as shown in the adjacent source file: https://github.com/phatboyg/Fooidity/blob/develop/src/Fooidity.Management.Web/Hubs/ApplicationHub.cs

Check it out, hopefully it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!