两个独立应用程序之间的通信
我开发了一个 Windows 服务,它从数据库读取数据,该数据库通过 ASP.net MVC 应用程序填充。
我需要通过向数据库发出选择查询来使服务重新加载内存中的数据。 此重新加载将由网络应用程序触发。 我想到了几种方法来完成此任务,例如远程处理、MSMQ,或者只是让服务在套接字上侦听重新加载命令。
我只是在寻找有关最佳方法的建议。
I have developed a windows service which reads data from a database, the database is populated via a ASP.net MVC application.
I have a requirement to make the service re-load the data in memory by issuing a select query to the database. This re-load will be triggered by the web app. I have thought of a few ways to accomplish this e.g. Remoting, MSMQ, or simply making the service listen on a socket for the reload command.
I am just looking for suggestions as to what would be the best approach to this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通知必须有多可靠? 如果通知丢失(假设通信管道在路由器中出现故障并丢失了套接字),世界末日会到来还是一切照常? 如果服务关闭,来自网站的通知是否需要在启动时排队等待,或者可以安全地删除?
您需要的可靠性越高,您就越需要采用排队解决方案 (MSMQ)。 如果可靠性不是问题,那么您可以从非排队解决方案(远程处理、TCP、UDP 广播、HTTP 调用等)中进行选择。
您关心安全吗? 您是否担心攻击者会 ping 您的“刷新”至死亡,从而导致至少 DoS(如果不是更糟的话)? 您想对发出“刷新”调用的网站进行身份验证吗? 您需要通知的隐私(即加密)吗? UDP 更难确保安全(无会话)。
该解决方案是否必须允许在现场轻松部署、配置和管理(即,是一个独立的、打包的产品),还是一次性部署,可以在发生变化时“及时”修复?
如果不了解所有这些因素的细节,就很难说“使用 X”。 至少有一件事是肯定的:远程处理现在已经有点过时了。
我的建议是使用 WCF,因为可以轻松地动态更改绑定,因此您可以测试各种配置(TCP、网络管道、http),而无需更改任何代码。
顺便说一句,您是否考虑过使用查询通知来检测数据更改来自网站的活动通知? 我认为这是一个盲目的尝试,但许多数据库上都存在等效的主动缓存支持。
How reliable does the notification has to be? If a notification is lost (lets say the communication pipe has a hickup in a router and drops the socket), will the world end come or is business as usual? If the service is down, do notifications from the web site ned to be queued up for when it starts up, or they can e safely dropped?
The more reliable you need it to be, the more you have to go toward a queued solution (MSMQ). If reliability is not an issue, then you can choose from the mirirad of non-queued solutions (remoting, TCP, UDP broadcast, HTTP call etc).
Do you care at all about security? Do you fear an attacker my ping your 'refresh' to death, causing at least a DoS if not worse? Do you want to authenticate the web site making the 'refresh' call? Do you need privacy of the notifications (ie. encryption)? UDP is more difficult to secure (no session).
Does the solution has to allow for easy deployment, configuration and management on the field (ie. is a standalone, packaged, product) or is a one time deployment that can be fixed 'just-in-time' if something changes?
Withous knowing the details of all these factors, is dififcult to say 'use X'. At least one thing is sure: remoting is sort of obsolete by now.
My recommendation would be to use WCF, because of the ease of changing bindings on-the-fly, so you can test various configurations (TCP, net pipe, http) w/o any code change.
BTW, have you considered using Query Notifications to detect data changes, instead of active notifications from the web site? I reckon this is a shot in the dark, but equivalent active cache support exists on many databases.
只需在 Windows 服务中托管一个 WCF 服务即可。 您可以使用
netTcpBinding
进行绑定,它将使用 TCP/IP 上的二进制文件。 这将比套接字简单得多,但更易于开发和维护。Simply host a WCF service inside the Windows Service. You can use
netTcpBinding
for the binding, which will use binary over TCP/IP. This will be much simpler than sockets, yet easier to develop and maintain.我会使用标准 TCP 套接字 - 这将在各种组件移动中幸存下来,并最大限度地减少配置问题恕我直言。
I'd use standard TCP sockets - this will survive all sorts of moving of components, and minimize configuration issues IMHO.