每个网络一个应用程序实例 [英] Single application instance per network

查看:135
本文介绍了每个网络一个应用程序实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经开发了一些长期运行的C#控制台应用程序,这些应用程序将由Windows Scheduled任务运行.

We have developed some long running C# console applications which will be run by Windows Scheduled tasks.

这些应用程序可能在Intranet/Extranet上的许多不同服务器计算机上运行. 我们无法确保它们在一台计算机上运行,​​因为每个应用程序可能需要访问某些资源,这些资源仅在特定计算机上可用.

These applications might be run on many different server machines on intranet/extranet. We cannot ensure that they run on one machine because each application might need access to some resources, which are available only on a certain machine.

仍然,所有这些应用程序都使用通用的WCF服务来访问数据库.

Still, all these applications are using a common WCF service to access the database.

我们需要确保在任何时候都只有一个应用程序实例在运行. 由于这些应用可能位于不同的Extranet计算机上,因此我们无法使用每台计算机的互斥锁或MSMQ.

We need to ensure, that there is only instance of one of our applications running at any moment. As the apps might be on different extranet computers, we cannot use per-machine mutexes or MSMQ.

我已经考虑过以下解决方案-WCF Mutex服务超时.当一个应用程序运行时,它会检查它是否已经启动(可能在另一台计算机上),然后(在专用线程中)定期ping WCF Mutex服务以更新时间戳(如果ping失败,则该应用程序立即退出).如果时间戳记过期,则意味着该应用程序已崩溃,因此可以再次运行.

I have thought about the following solution - WCF Mutex service with a timeout. When one app runs, it checks to see if it is already launched (maybe on another machine) and then (in a dedicated thread) periodically pings the WCF Mutex service to update the timestamp (if ping fails, the app exits immediately). If the timestamp gets expired, this means, that the application has crashed, so it can be run again.

我想知道,此"WCF互斥锁"是否是解决我的问题的最佳解决方案.也许已经有一些第三方库实现了这种功能?

推荐答案

互斥体解决方案具有竞争条件.

You mutex solution has a race condition.

如果其他服务器上的应用在时间戳过期之后但在当前服务更新时间戳之前在窗口中检查了时间戳,则您将有两个实例在运行.

If an app on a different server checks the timestamp in the window after the timestamp expired, but before the current service had updated the timestamp you will have two instances running.

我可能会选择相反的路线.我将有一个中央监控服务.该服务将持续监视系统的运行状况.如果它检测到服务中断,则会在该计算机或另一台计算机上重新启动该服务.

I'd probably go the opposite route. I'd have a central monitoring service. This service would continually monitor the health of the system. If it detects a service went down, it would restart it on either that machine or a different one.

您可能要硬着头皮,选择配备完整的Enterprise Service Bus.查看Wikipedia文章中的ESB.它列出了十几个商业和开源系统.

You may want to bite the bullet and go with a full Enterprise Service Bus. Check the Wikipedia article for ESBs. It lists over a dozen commercial and open source systems.

这篇关于每个网络一个应用程序实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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