ASP.NET MVC 的队列解决方案

发布于 2024-08-02 23:14:36 字数 910 浏览 7 评论 0原文

我研究了 Web 应用程序排队的概念(即,将某些类型的作业放入队列中,由单独的工作人员完成,而不是在 Web 请求周期中完成)。

我想知道是否有任何好的解决方案可以在 ASP.NET MVC 环境中使用。

有人有过任何(好的或坏的)经历吗?

谢谢你!

更新:

只是为了澄清一下,我不是在谈论对传入请求进行排队。我将尝试说明我的意思...

1) 标准情况:

  • 来自浏览器的请求
  • 服务器处理开始
  • 长作业开始
  • 长作业完成< /em>
  • 服务器处理完成
  • 响应返回到浏览器

2) 我正在调查:

  • 来自浏览器的请求
  • 服务器处理开始
  • 放入队列中的长作业
  • 服务器处理完成
  • 响应返回到浏览器

在另一个进程中(可能在发送响应之后):

  • 从队列中取出长作业
  • 长作业开始
  • 长作业完成

在第一个实例中,用户等待服务器响应很长时间,在第二个实例中,它很快。

当然,有些类型的工作适合于此,有些则不适合。

UPDATE2:

客户端不必立即更新长期作业的结果。每当用户刷新页面时(当然是在作业完成之后),这些更改就会在应用程序中显示出来。

想想堆栈溢出中发生的一些事情 - 它们不会立即在应用程序的每个部分中更新,但这种情况发生得相当快 - 我怀疑其中一些作业正在排队。

I looking into the concept of queueing for web apps (i.e. putting some types of job in a queue for completion by a seperate worker, rather than being completed in the web request cycle).

I would like to know if there are any good solutions existing for this which can be utilised in an ASP.NET MVC environemnt.

Has anyone had any (good or bad) experiences?

Thank you!

UPDATE:

Just to clarify, I'm not talking about queueing incoming requests. I'll try to illustrate what I mean...

1) Standard situation:

  • Request from browser
  • Server processing starts
  • Long job starts
  • Long job finished
  • Server processing finished
  • Response returned to browser

2) What I'm looking into:

  • Requsest from browser
  • Server processing starts
  • Long job placed in queue
  • Server processing finished
  • Response returned to browser

And in another process (possibly after the response was sent):

  • Long job taken from queue
  • Long job starts
  • Long job finished

In the first instance the user has waited a long time for server resoponse, in the second it was quick.

Of course there are certain types of jobs that would be appropriate for this, some that would not be.

UPDATE2:

The client doesn't have to be updated immediately with the results of the long job. The changes would just show themselves in the application whenever the user happened to refresh a page (after the job had completed of course).

Think of some of the things that happen in stack overflow - they are not immediately updated in each part of the application, but this happends quite quickly - I suspect some of these jobs are being queued.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦境 2024-08-09 23:14:36

将作业数据发布到 MSMQ 队列 并拥有 Windows 服务进程队列中的项目。或者,让 Web 请求生成一个进程来处理队列中的项目。

Post the job data in an MSMQ queue and have a Windows Service process the items in the queue. Or, let the web request spawn a process that process the items in the queue.

潇烟暮雨 2024-08-09 23:14:36

Rhino 服务总线是另一个可能适合您的解决方案:
http://ayende.com/Blog/archive/ 2008/12/17/rhino-service-bus.aspx

The Rhino Service Bus is another solution that may work for you:
http://ayende.com/Blog/archive/2008/12/17/rhino-service-bus.aspx

_失温 2024-08-09 23:14:36

您可能会考虑使用 ESB。我尝试过 MassTransit:http://code.google.com/p/masstransit/< /a> - 文档(或者至少是)有点稀疏,但很容易实现。

此外,我开发了在 Amazon EC2 上运行的应用程序,并且非常喜欢他们的 AmazonSQS 服务。

谢谢,

哈尔

You might check into using an ESB. I've played around with MassTransit: http://code.google.com/p/masstransit/ - the documentation is (or at least was) a little sparse, but it's easy to implement.

In addition, I develop apps for running on Amazon EC2 and absolutely love their AmazonSQS Service.

Thanks,

Hal

傲影 2024-08-09 23:14:36

由于您在另一条评论中提到您正在寻找与亚马逊的 sqs 服务相当的服务...您可能想研究一下 Windows Azure。他们有一个等效的队列 API:
http://msdn.microsoft.com/en-us/library/dd179363。 ASPX

Since you mentioned in another comment that you were looking for an equivalent to amazon's sqs service ... you might want to look into Windows Azure. They have an equivalent queue api:
http://msdn.microsoft.com/en-us/library/dd179363.aspx

嘿咻 2024-08-09 23:14:36

我通过让 Web 服务器异步调用 WCF 服务来实现此模式。当您使用 WCF 服务时,VS 向导将为您生成异步代理。如果必须保证将请求传送到服务,则可以使用 MSMQ 作为 WCF 服务的传输层。

I have implemented this pattern by having the web server call a WCF service asynchronously. The VS wizards will generate async proxies for you when you consume a WCF service. If you must have guaranteed delivery on the request to the service, you could use MSMQ as the transport layer for the WCF service.

心凉怎暖 2024-08-09 23:14:36

我认为 Chrisitan 的评论可能是您的答案,但考虑到我对 IIS 及其排队了解不多,我的解决方案是:

发出异步请求并在数据库中加载作业详细信息。然后有一个作业循环访问数据库并处理作业详细信息。我为我的一个网站执行此操作。可能不是最好的解决方案,但它可以完成工作。

编辑

我的答案可能仍然有效,但是您需要在客户端上有一些轮询机制来连续检查数据库以查看该用户的工作是否完成,然后获取您需要的数据。

I think Chrisitan's comment might be your answer, but considering I don't know much about IIS and queueing with it, my solution would be:

Make an asynchronous request and load the job details in the database. Then have a job to loop through the database and process the job details. I do this for one of my sites. Might not be the best solution out there, but it gets the job done.

EDIT

My answer might still work, but you will need to have some polling mechanism on the client to continuously check the database to see if that user's job is done, then grab the data you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文