[翻译]  Message queues in ASP.Net Web API

[CHINESE]  ASP.Net Web API中的消息队列


I am developing a client-side single-page-application (SPA) with AngularJS and ASP.Net WebAPI.

我正在使用AngularJS和ASP.Net WebAPI开发客户端单页面应用程序(SPA)。

One of the features of the SPA includes uploading large CSV file, processing it on the server, and returning the output to the user.

SPA的一个功能包括上载大型CSV文件,在服务器上处理它,以及将输出返回给用户。

Obviously, this kind of computation can not be done online, and therefore I implemented an UploadController in charge of receiving the file, and a PollingController in charge of notifying the user when the computation is complete.

显然,这种计算不能在线完成,因此我实现了一个负责接收文件的UploadController,以及一个负责在计算完成时通知用户的PollingController。

The client side application monitors the PollingController every few seconds.

客户端应用程序每隔几秒钟监视一次PollingController。

I have no experience in Message Queues, but my gut tells me that they are required in this situation.

我没有消息队列的经验,但我的直觉告诉我他们在这种情况下是必需的。

How would you recommend to implement this functionality in a non-blocking, efficient way ?

您如何建议以非阻塞,有效的方式实现此功能?

diagram

Examples will be highly appreciated

举例将受到高度赞赏

2 个解决方案

#1


6  

I've used message based service bus frameworks for this in the past.

我过去曾经使用过基于消息的服务总线框架。

You write an application (running as a windows service), that listens for messages broadcast across a event bus.

您编写一个应用程序(作为Windows服务运行),用于侦听通过事件总线广播的消息。

Your frontend can publish these messages into the bus.

您的前端可以将这些消息发布到总线中。

The most popular framework for this in .NET is NServiceBus, however it recently became commercial. You can also look into MassTransit, though this one has very poor documentation.

.NET中最流行的框架是NServiceBus,但它最近变得商业化。您也可以查看MassTransit,虽然这个文档很差。

The workflow you would do:

您将要执行的工作流程:

  • MVC App accepts upload and places it into some directory accessible by the windows service
  • MVC App接受上传并将其放入windows服务可访问的某个目录中
  • MVC App publishes "UploadReady" message.
  • MVC App发布“UploadReady”消息。
  • Service receives message, processes file, and updates some state for the polling controller.
  • 服务接收消息,处理文件,并更新轮询控制器的某些状态。
  • Polling controller watches for this state to change. Usually a DB record etc.
  • 轮询控制器监视此状态的变化。通常是DB记录等

The nice bit about using a framework like this is that if your service goes down, or you redeploy it, any processing can queue and resume, so you won't have any downtime.

关于使用这样的框架的好处是,如果您的服务出现故障,或者您重新部署它,任何处理都可以排队和恢复,因此您不会有任何停机时间。

#2


4  

For long running operations you need separate Windows Service application (or Worker Role, if it is Windows Azure). IIS may kill ASP.NET processes on pool recycling and your operation will not finish.

对于长时间运行的操作,您需要单独的Windows服务应用程序(或者工作者角色,如果它是Windows Azure)。 IIS可能会在池回收时终止ASP.NET进程,您的操作将无法完成。

Message queue is mostly for communication. You can use it between your web and worker parts. But it is not required there unless your data is not super critical. You can establish communication using database, cache, file system or 100 other different ways :)

消息队列主要用于通信。您可以在Web和工作器部件之间使用它。但除非您的数据不是超级关键,否则不需要它。您可以使用数据库,缓存,文件系统或其他100种方式建立通信:)

You can use SignalR to notify your client about finished processing.

您可以使用SignalR通知您的客户已完成处理。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号