通知非 Web 应用程序有关网页更改的最佳方式是什么?
假设我有两个应用程序,它们必须在一定程度上协同工作。
- Web 应用程序(PHP、Ruby on Rails 等)
- 桌面应用程序(Java、C++ 等)
桌面应用程序必须从 Web 应用程序收到通知,并且发送和接收通知之间的延迟必须很短。 (<10 秒)
有哪些可能的方法可以做到这一点? 我可以考虑以 10 秒的间隔进行轮询,但如果必须通知许多桌面应用程序,这会产生大量流量。 在 LAN 上,我会使用 UDP 广播,但不幸的是,这在这里不可能......
我很感激您能给我的任何想法。
Let's say I have two applications which have to work together to a certain extent.
- A web application (PHP, Ruby on Rails, ...)
- A desktop application (Java, C++, ...)
The desktop application has to be notified from the web application and the delay between sending and receiving the notification must be short. (< 10 seconds)
What are possible ways to do this? I can think of polling in a 10 second interval, but that would produce much traffic if many desktop applications have to be notified. On a LAN I'd use an UDP broadcast, but unfortunately that's not possible here...
I appreciate any ideas you could give me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这里的“最佳实践”将取决于您期望服务的桌面客户端的数量。 如果只有一个桌面需要通知,那么轮询可能是一种很好的方法 - 是的,轮询比基于事件的通知开销要大得多,但它肯定是最容易实现的解决方案。
如果轮询的开销确实不可接受,那么我会看到两种基本的替代方案:
但请注意——这两种选择都充满了陷阱。 几个要点:
为了减轻一些问题,您可以通过引入中间通知服务器将不可靠的桌面与 Web 服务器解耦——Web 服务器可以在某处发布更新,而桌面可以在那里轮询/连接/注册以获得通知。 为了避免在这里重新发明轮子,这可能涉及某种 MessageQueue 系统......当然,这增加了维护新中介的复杂性。
同样,所有这些方法可能都非常复杂,所以我认为轮询可能是最好的选择。
I think the "best practice" here will depend on the number of desktop clients you expect to serve. If there's just one desktop to be notified, then polling may well be a fine approach -- yes, polling is much more overhead than an event-based notification, but it'll certainly be the easiest solution to implement.
If the overhead of polling is truly unacceptable, then I see two basic alternatives:
Be warned, though -- both alternatives are chock full of gotchas. A few highlights:
To mitigate some of the concerns, you might decouple the unreliable desktop from the web-server by introducing an intermediary notification server -- the web-server could post an update somewhere, and the desktop could poll/connect/register there to be notified. To avoid reinventing the wheel here, this could involve some sort of MessageQueue system... This, of course, adds the complexity of needing to maintain the new intermediary.
Again, all of these approaches are probably quite complex, so I'd say polling is probably the best bet.
我可以看到两种方式:
您的 Web 应用程序可以发布 RSS 提要,但您的桌面应用程序仍然必须每 10 秒轮询一次提要。
流量不需要很大:如果您使用 HTTP HEAD< /a> 请求,您将收到一个小数据包,其中包含上次修改的日期(方便地命名为Last-Modified)。
I can see two ways:
Your web app could publish an RSS feed, but your desktop app will still have to poll the feed every 10 s.
The traffic need not be huge: if you use an HTTP HEAD request, you'll get a small packet with the date of the last modification (conveniently named Last-Modified).
我不知道具体该怎么做才能完成您的任务,但我可以建议在桌面应用程序 PC 上创建一个 Windows 服务。
该服务每隔一段时间检查一次 Web 应用程序是否有新更改,如果发生更改,它可以运行桌面应用程序,并通知 Web 应用程序中存在更改,并且当发生任何更改时,您可以在 Web 应用程序中做出响应并确认
我希望这可能很有用,我没有完全尝试过,但我建议使用这样的想法。
I don't know exactly what to do to achieve your task but I can suggest to create a windows service at the desktop application PC.
This service checks the web application every interval of time for new changes and if changes occurred it can run the desktop application with notification that there is a change in the web application and in the web application when any change occurrs you can response with acknowledgment
I hope that this may be useful I didn't try it exactly but I am suggesting using like this idea.
联合层将有助于扩展系统。
桌面应用程序可以向“发布者”服务(在几台/多台计算机中的一台上运行)注册自己。该发布者服务从您的网络应用程序接收到某些内容已更改的“通知”,并立即开始通知其所有注册订阅者。
您需要的发布商数量将随着用户数量的增加而增加。
编辑:忘记提及桌面应用程序需要侦听套接字。
A layer of syndication would help to scale out the system.
The desktop app can register itself with a "publisher" service (running on one of several/many machines) This publisher service receives the "notice" from your web app that something has changed, and immediately starts notifying all of its registered subscribers.
The number of publishers you need will increase with the number of users.
Edit: Forgot to mention that the desktop app will need to listen on a socket.