.NET Web服务 - 承认很快,但继续处理背景背景、继续、NET、Web

2023-09-03 17:26:30 作者:Serious(高冷)

我建设将由供应商的应用程序使用.NET Web服务,我不知道如何完成以下任务:

I'm building a .NET web service that will be consumed by a vendor's application, and I'm not sure how to accomplish the following:

在卖方将打电话给我webserivce有一些信息,但要确认快速恢复,只是说,我接受了他们的信息。他们不在乎什么,我用它做,并且不希望,我已经处理完毕的确认。 在我传递需要做幕后的东西,并采取行动以时间敏感的方式信息的信息 - 例如,需要在几分钟之内的一些行动。我会接触一些其他的网络服务,以及做一些数据库工作。很显然,这将是我的答复是成功来调用应用程序后。

我没有在供应商访问我的服务控制的方式,和他们使用称它为方法是同步的,所以我需要快速响应,让调用应用程序继续工作。在我看来,有两个选择,虽然我开给别人:

I don't have control over the way the vendor accesses my service, and the method they're using to call it is synchronous, so I need to respond quickly to let the calling app continue its work. As I see it, there are two choices, though I'm open to others:

由于调用应用程序基本上是提交到一个队列,以便我写可以对其进行处理的过程中,我可以有Web服务刚刚提交的项目数据库(或MSMQ或另一个队列),然后返回成功。队列进程将拿起处理从那里。 在理想情况下,我想象我的服务可能返回成功,然后就继续自己的加工,但我不知道这是可能的。因为我的处理是对时间敏感,开始了新的要求的关闭后端处理是理想的,所以等待时间是最小的。

还有没有其他的想法,或者做这些声音preferable一个?

Are there any other ideas, or does one of these sound preferable?

推荐答案

我觉得第一是唯一可能的解决方案。第二个很糟糕的设计。假设你处理每个请求为1秒,并且有2请求未来在1秒钟内平均。您会快速运行资源输出(因为越来越多线程将被使用)

I think 1st is the only possible solution. 2nd is very bad design. Assume you process each request for 1 second, and there are 2 requests coming in 1 second in average. You will quickly run out of resources (because more and more threads will be used)

由于您对如何存储和处理请求所有的控制第一个1是好的。良好的设计是让Web服务作为前端,只会回答成功和排队的请求。作为永久存储我建议MSMQ或数据库。然后创建一个服务应用程序,将有线程池,并选择从队列(DB)。

1st one is good because you have all control on how you will store and process requests. Good design is to have web service as frontend that will just answer "Success" and enqueue requests. As a persistent storage i recommend MSMQ or database. Then create a service app that will have pool of threads and will pick from queue(db).