需要关于后台工作人员的建议
我想开发一个交付应用程序(自托管 WCF 服务),它允许安排电子邮件。用户将分配一个时间表到电子邮件并发送。 WCF 服务应该能够选择电子邮件并在预定时间发送。
我在这里应该使用什么方法?我正在考虑以下替代方案
- 使用后台工作线程来执行此任务
- 任何第三方调度服务(我尚未对此进行调查)
除了上述两个之外,任何人都可以建议我一个可能的解决方案吗?
[编辑]:我可以使用 SQL 代理吗?
谢谢,
拉姆
I want to develope a delivery application(self hosted WCF service ) which allows scheduling of the emails. User will assign a schedule to email and send it. The WCF service should be able to pick the email and send it on its scheduled time.
What approach shall I use here? I am thinking about following alternatives
- Use background worker thread to perform this task
- Any third party scheduling service (I yet to investigate on this)
Can anyone suggest me a possible solution for this apart from above mentioned two?
[Edit] : Can I use SQL Agents for this?
Thanks,
Ram
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
让您的 WCF 服务将电子邮件请求排队到数据库表中。然后编写一个 Windows 服务,定期扫描表、发送电子邮件,然后用结果更新表。
如果您使用的是 SQL Server,则可以直接从它发送电子邮件,还可以安排作业发送电子邮件,从而无需部署 Windows 服务。
Have your WCF service queue the email requests either to a database table. Then write a Windows service that periodically scans the table, sends the email, and then update the table with the results.
If you're using a SQL Server, you can send emails directly from it and also schedule jobs to send the emails, saving you from having to deploy a Windows service.
我看到了“...除了上面提到的两个...”,但我认为没有其他方法可以实现这一点:)
要么在 Windows 服务内部构建一个无限循环,如下所示:
... 其中 TheThing 有一个 Run 方法,它每 1 秒执行一次您需要的所有操作。这看起来很傻(while(true) - 是的,没错),但自 .NET 1.0 以来,它一直在至少 30 个服务器上不间断地工作:) 只需确保在新线程中启动 Windows 服务时调用此 DoTheThing 方法即可。
希望这有帮助:)
I saw the "...apart from above mentioned two..." but I think there is nothing else to achieve this :)
Either build an infinite loop inside of windows service like this:
... where TheThing has a method Run which does all that you need every 1 second. This looks silly (while(true) - yeah, right) but has been working non-stop since .NET 1.0 on at least 30 servers :) Just make sure you call this DoTheThing method on Start of your windows service in a new thread.
Hope this helps :)
这取决于您的非功能性需求......:-)
我可以想象您会希望这项服务具有一定的可靠性。 WCF 服务的生命周期取决于其主机。例如。如果这是 IIS,应用程序池将在一定的空闲时间后被回收(没有请求进入 IIS)。这需要与后台工作人员不同的解决方案。正如您所建议的,这可能是第三方调度程序,但 Windows 中也有调度程序。 (请参阅 http://technet.microsoft.com/en- us/library/dd363786(WS.10).aspx) 使用小型控制台程序,您可以让 Windows 调度程序调用您的服务,或者自行发送电子邮件。
It depends on your non-functional requirements... :-)
I can imagine that you would want some reliability in this service. The life-time of the WCF service depends on its host. Eg. if this is IIS, the app pool will be recycled after a certain idle time (no requests coming in to IIS). This would plead for a different solution than a background worker. As you suggest, this could be a third party scheduler but there is also scheduler in Windows. (see http://technet.microsoft.com/en-us/library/dd363786(WS.10).aspx) With a small console program, you could have the Windows scheduler call your service, or alternatively, send the email itself.