如何设计单向Web服务? [英] How do I design a one way web service?

查看:69
本文介绍了如何设计单向Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,这个问题的标题可能不够清楚,请允许我在这里解释一下背景:



我想设计一个生成的Web服务PDF并将其提交给打印机,这是工作流程:



1.用户向Web服务提交请求,可能请求将是一次性的,以便用户不会等待工作完成后会受到影响。用户可能会收到HTTP200并继续他们的工作。



2.一旦Web服务收到请求,因为我不想在该服务器上耗尽所有资源,可能在这里使用生产者消费者模式,可能有一个队列来排队客户端作业,并逐个处理它们。



我的问题是:

1.我是C#的新手,排队和处理它们的正确模式是什么?我应该使用ConcurrentQueue和ThreadPool进行存档吗?



2.通知用户工作成功/失败的正确方法是什么?而不是使用回调服务,异步是一种理想的方式吗?我担心的是队列中可能有很多工作,我不希望客户端等待它完成。



3. Web服务被置于后面负载均衡器,如何在其中维护进程队列?我已经尝试过使用Hangfire,看起来没问题,任何其他建议?



4.如何知道Queue中有多少个作业/当前线程如何运行? Web服务将部署在IIS上,是否有本地存档方式,或者我应该实现Web服务调用以获取它们吗?



任何帮助将不胜感激,谢谢!



我的尝试:



原型,现在我将在每个请求上创建一个新线程来处理客户端请求。但是,用户无法知道请求是否成功。

解决方案

Quote:
1。我是C#的新手,排队和处理它们的正确模式是什么?我应该使用ConcurrentQueue和ThreadPool进行存档吗?



2.通知用户工作成功/失败的正确方法是什么?而不是使用回调服务,异步是一种理想的方式吗?我担心的是队列中可能有很多工作,我不希望客户端等待它完成。



3. Web服务被置于后面负载均衡器,如何在其中维护进程队列?我已经尝试过使用Hangfire,看起来没问题,任何其他建议?



4.如何知道Queue中有多少个作业/当前线程如何运行? Web服务将部署在IIS上,是否有本地存档方式,或者我应该实现Web服务调用来获取它们?





1在编程中有许多不同但同样有效的方法来解决问题。作为设计师,您可以根据所提供的规范(如果有的话)确定以哪种方式解决问题的方式,您可以理解和实施。



2.再次没有正确的方法,如果你要求开发一些东西,那么所需的方法应该在规范中。您可以使用webhooks进行回叫,如果您要通知最终用户,可以使用短信或电子邮件,所有有效的通知方法取决于要求。



3. Hangfire是一个很棒的工具,我是一个忠实的粉丝,或者,消息队列/公共汽车等选项也值得考虑。



4. Hangfire或消息总线将具有队列中可用的作业计数。你需要查询这些,IIS不会存储这些信息。



祝你好运!


Hi all, the title of the question may not clear enough, allow me to explain the background here:

I would like to design a web service that generates PDF and submit it to printer, here is the workflow:

1. User submit a request to the web service, probably the request will be one off so that user wouldn't suffer from waiting the job complete. User may received a HTTP200 and continue their work.

2. Once web service received the request, as I don't want the drain all resource on that server, I may use producer consumer pattern here, there might be a queue to to queue client jobs, and process them one by one.

My Questions is that:
1. I'm new to C#, what is the proper pattern to queue and process them? Should I use ConcurrentQueue and ThreadPool to archive it?

2. What is the proper way to notify user about the job is success/fail? Instead of using callback service, is async an ideal way? My concern is that there may be lots of jobs in the queue and I don't want client suffer from waiting it complete.

3. The web service is placed behind a load balancer, how can I maintain a 'process queue' among them? I've tried using Hangfire and it seems okay, any alternative suggest?

4. How can I know how many jobs are in the Queue/ how may thread is currently running? The webservice will be deployed on IIS, is there a Native way to archive it, or should I implement a web service call to obtain them?

Any help will be appreciated, thanks!

What I have tried:

For prototype, now I will just create a new thread on each request to process client request. However there is no way the user know the request is success or not.

解决方案

Quote:

1. I'm new to C#, what is the proper pattern to queue and process them? Should I use ConcurrentQueue and ThreadPool to archive it?

2. What is the proper way to notify user about the job is success/fail? Instead of using callback service, is async an ideal way? My concern is that there may be lots of jobs in the queue and I don't want client suffer from waiting it complete.

3. The web service is placed behind a load balancer, how can I maintain a 'process queue' among them? I've tried using Hangfire and it seems okay, any alternative suggest?

4. How can I know how many jobs are in the Queue/ how may thread is currently running? The webservice will be deployed on IIS, is there a Native way to archive it, or should I implement a web service call to obtain them?



1. There are many different but equally valid ways to solve a problem in programming. As the designer it's up to you to determine which way solves the problem in a way that you can both understand and implement, based on the provided specifications if there are any.

2. Again there is no 'proper way' and if you;re asked ot develop something then the required way should be in the specification. You could use webhooks for call backs, you could use SMS or E-Mail if you're notifying an end user, all valid notification methods depending on the requirements.

3. Hangfire is a great tool, I'm a big fan, alternatively, options such as message queues/busses may also be worth considering.

4. Hangfire or message busses will have a count of jobs in the queue that would be available. You'd need to queries these, IIS would not store this information.

Good luck!


这篇关于如何设计单向Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆