通知非 Web 应用程序有关网页更改的最佳方式是什么?

发布于 2024-07-18 21:54:28 字数 315 浏览 7 评论 0原文

假设我有两个应用程序,它们必须在一定程度上协同工作。

  1. Web 应用程序(PHP、Ruby on Rails 等)
  2. 桌面应用程序(Java、C++ 等)

桌面应用程序必须从 Web 应用程序收到通知,并且发送和接收通知之间的延迟必须很短。 (<10 秒)

有哪些可能的方法可以做到这一点? 我可以考虑以 10 秒的间隔进行轮询,但如果必须通知许多桌面应用程序,这会产生大量流量。 在 LAN 上,我会使用 UDP 广播,但不幸的是,这在这里不可能......

我很感激您能给我的任何想法。

Let's say I have two applications which have to work together to a certain extent.

  1. A web application (PHP, Ruby on Rails, ...)
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

冷月断魂刀 2024-07-25 21:54:28

我认为这里的“最佳实践”将取决于您期望服务的桌面客户端的数量。 如果只有一个桌面需要通知,那么轮询可能是一种很好的方法 - 是的,轮询比基于事件的通知开销要大得多,但它肯定是最容易实现的解决方案。

如果轮询的开销确实不可接受,那么我会看到两种基本的替代方案:

  1. 在桌面和 Web 服务器之间保持持久连接打开(可能是“彗星”式 Web 请求,或原始套接字连接)
  2. 从以下位置公开服务在桌面应用程序中,并向网络服务器注册服务的地址。 这样,网络服务器就可以根据需要调用桌面。

但请注意——这两种选择都充满了陷阱。 几个要点:

  • 保持连接打开可能很棘手,因为您希望 Web 服务器可热插拔
  • 从 Web 服务器调用外部服务(例如,您的桌面)是危险的,因为此请求可能会挂起。 您希望将此通知移至单独的线程,以避免占用网络服务器。

为了减轻一些问题,您可以通过引入中间通知服务器将不可靠的桌面与 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:

  1. Keep a persistent connection open between the desktop and web-server (could be a "comet"-style web request, or a raw socket connection)
  2. Expose a service from within the desktop app, and register the address of the service with the web-server. This way, the web-server can call out to the desktop as needed.

Be warned, though -- both alternatives are chock full of gotchas. A few highlights:

  • Keeping a connection open can be tricky, since you want your web-servers to be hot-swappable
  • Calling out to an external service (eg, your desktop) from a web-server is dangerous, because this request could hang. You'd want move this notification onto a separate thread to avoid tying up the webserver.

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.

还不是爱你 2024-07-25 21:54:28

我可以看到两种方式:

  • 您的桌面应用程序轮询 Web 应用程序
  • 您的 Web 应用程序通知桌面应用程序

您的 Web 应用程序可以发布 RSS 提要,但您的桌面应用程序仍然必须每 10 秒轮询一次提要。

流量不需要很大:如果您使用 HTTP HEAD< /a> 请求,您将收到一个小数据包,其中包含上次修改的日期(方便地命名为Last-Modified)。

I can see two ways:

  • Your desktop application polls the web app
  • Your web app notifies the desktop application

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).

禾厶谷欠 2024-07-25 21:54:28

我不知道具体该怎么做才能完成您的任务,但我可以建议在桌面应用程序 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.

我的影子我的梦 2024-07-25 21:54:28

联合层将有助于扩展系统。

桌面应用程序可以向“发布者”服务(在几台/多台计算机中的一台上运行)注册自己。该发布者服务从您的网络应用程序接收到某些内容已更改的“通知”,并立即开始通知其所有注册订阅者。

您需要的发布商数量将随着用户数量的增加而增加。

编辑:忘记提及桌面应用程序需要侦听套接字。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文