具有 MassTransit、RabbitMQ 和 SignalR 的分布式架构

Distributed architecture with MassTransit, RabbitMQ and SignalR(具有 MassTransit、RabbitMQ 和 SignalR 的分布式架构)

本文介绍了具有 MassTransit、RabbitMQ 和 SignalR 的分布式架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在

2) 与第一个一样,但使用 Rest API 调用而不是来自 IIS 端的消费者

3) 这篇文章的想法

解决方案

我使用 SignalR 的 hubs 执行此操作,并使用常规 MassTransit 消费者在服务器上观察事件.当观察到事件时,我触发事件处理程序,该处理程序使用集线器向连接的客户端分派.这样,事件会立即推送到浏览器,而不会在控制器中的服务器上留下未决的异步调用.

您可以在 Fooidity 中看到这一点,它做了类似的事情:

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

使用GlobalHost解析Hub,然后在Hub上提升方法.可以使用组来区分事件上下文,这是按节点处理的 SignalR 功能.因此,只要每个节点都在观察事件,客户端就可以连接到任何集线器并得到通知.这非常适合负载平衡,而不必为 SignalR 使用繁重的集群背板——因为 RabbitMQ 对于事件分发来说是超级轻量级​​的.

您也可以使用非持久队列来执行此操作,这使其速度更快——因为服务器重置/连接断开比代理崩溃更可能发生.

身份验证在 ApplicationHub 内部处理,如相邻的源文件所示:https://github.com/phatboyg/Fooidity/blob/develop/src/Fooidity.Management.Web/Hubs/ApplicationHub.cs

看看吧,希望对你有帮助.

I'm developing distributed application with help of MassTransit and rabbitmq

I have to provide ability to generate report on a web page without page reloading by click on a button, also I should call a windows service for data preparation (The service handles each request for 30sek - 1min).

My first try based on this sample: https://github.com/MassTransit/Sample-RequestResponse

    [HttpPost]
    public async Task<HttpStatusCodeResult> GenerateReport(string someJsonData)
    {    
        var serviceAddress = new Uri(ConfigurationManager.AppSettings["BaseLineRecordService"]);
        var client = this.Bus.CreateRequestClient<ICreateReportRequest, ICreateReportResponse>(serviceAddress, TimeSpan.FromHours(1));
        ICreateReportResponse response = await client.Request(new CreateReportRequest());
        reportHub.ShowRepordData(response); // Update data by SingleR
        return new HttpStatusCodeResult(200);
    }

But as I understand it' not a better approach, because I'm keeping connection during all data preparation.

I've read many articles and I have found three ways. Which way is preferred?

1) Like on this article http://www.maldworth.com/2015/07/19/signalrchat-with-masstransit-v3/

2) As first but with Rest API calling instead of Consumers from IIS side

3) Idea from this article http://weblog.west-wind.com/posts/2013/Sep/04/SelfHosting-SignalR-in-a-Windows-Service

解决方案

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.

这篇关于具有 MassTransit、RabbitMQ 和 SignalR 的分布式架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:具有 MassTransit、RabbitMQ 和 SignalR 的分布式架构

基础教程推荐