基于 Java 的应用程序的发现机制 API

发布于 2024-08-14 05:50:13 字数 507 浏览 3 评论 0原文

我目前参与一个项目,我们/应用程序需要能够发现在 LAN(以下称为 Node)上运行的具有相同应用程序名称的应用程序的其他实例。

先决条件: 所有节点都知道自己的 IP 地址和 TCP 端口号 所有节点都有一个名称 所有节点都可以访问 LAN

我需要什么:

所有节点都需要知道每个其他节点的 IP 地址和 TCP 端口。 如果节点出现故障,我将必须以编程方式收到通知。 如果出现新节点,我将必须以编程方式收到通知。 至关重要的是,不需要主服务器或其他应用程序,它必须是一个可以集成到当前应用程序中的 API。 此外,它必须是开源的,并且最好获得 MIT 或 ApacheV2 许可。

就这样!

该应用程序基于 JVM,因此任何 API 都可以。我一直在研究 ZooKeeper,但它似乎对我们需要的小功能有很大的依赖。

而且,如果您不知道任何 API,但有一些很好的链接可以分享如何通过自己编写来实现这一目标(白皮书、博客、书籍等),我也很乐意接受类似的东西。

所以问题是, 我该怎么做?

I currently participate in a project where we/the applicaition need to be able to discover other instances of the application with the same application name running on a LAN (henceforth called Node).

Prerequisites:
All Nodes know their own IP address and TCP port number
All Nodes have a name
All Nodes have access to the LAN

What I need:

All Nodes needs to know the IP address and TCP port of each other Node.
If a Node goes down, I will have to be programmatically notified of this.
If a new Node comes up, I will have to be programmatically notified of this.
It's ESSENTIAL that no master server or other application is needed, it has to be an API that I can integrate into the current application.
Also, it has to be open source and preferrably MIT or ApacheV2 licensed.

That's all!

The application is JVM-based so any API will do. I've been looking at ZooKeeper but it seems to be quite a big dependency for the little functionality we need.

And, if you don't know any API, but have some good links to share as how to achieve this by writing it myself (white papers, blogs, books, whatnot), I'd more than gladly accept things like that aswell.

So the question is,
how do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

橘香 2024-08-21 05:50:13

我绝对会推荐JGroups,它非常好,非常积极致力于和支持通过任何传输进行任何类型的发现(IP 多播、固定列表、外部查找服务等)。

另一个选择是 Apache MINA,但 JGroups 在 IMO 中更适合发现(因为它支持任何类型的发现)。

I'd definitely recommend JGroups which is pretty nice and very actively worked on and supports any type of discovery (IP multicast, fixed list, external lookup service etc) over any transport.

Another option would be Apache MINA but JGroups is IMO better for discovery (because it supports any type of discovery).

牵强ㄟ 2024-08-21 05:50:13

如果你们都在同一个子网上,一个简单的解决方案是使用 多播套接字。选择一个地址(好吧,使其可配置),然后当新实例启动时,它会发送多播“ping”。这会通知其他服务器。

当然,这不会告诉您实例何时出现故障。为此,您有两种选择:

  1. 足够频繁地执行 Ping,当您在一定时间内未收到 ping 时,您会认为实例已关闭;或
  2. 当您收到新实例的通知时,您将打开到该实例的 TCP 连接。您必须少得多地 ping 该套接字才能使其保持打开状态(不活动最终仍会杀死它),并且您可以收到另一端关闭它的通知或套接字超时的 TCP 语义。

您将需要 1-2 个线程来监视此情况并触发适当的事件。

If you're all on the same subnet, a simple solution would be to use multicast sockets. Pick an address (well, make it configurable) and then when a new instance starts up it sends a multicast "ping". This notifies the other servers.

Of course this won't tell you when an instance goes down. You have two choices for that:

  1. Ping often enough that when you fail to receive a ping for a certain amount of time you assume the instance is down; or
  2. When you are notified of a new instance you open a TCP connection to that instance. You have to ping that socket far less often to keep it open (inactivity will still kill it eventually) and you can be notified of it being closed by the other side or the TCP semantics for socket timeout.

You will need 1-2 threads to monitor this and trigger appropriate events.

↘人皮目录ツ 2024-08-21 05:50:13

对于这类事情有很多选择,我个人最喜欢的是 hazelcast 它是 Apache 许可的并且具有零依赖关系和最少的配置。

更成熟的选项是 jgroups,它根据 LGPL 获得许可。

There are a bunch of options for this sort of thing, my person favourite is hazelcast it's Apache licensed and has zero dependencies and a minimum of configuration.

A more established option is jgroups this licensed under the LGPL.

我偏爱纯白色 2024-08-21 05:50:13

最简单的方法 - 在我看来也是最简单的 - 做到这一点就是使用 ZeroConf!

每个节点都会宣布自己,并监听其他节点何时出现和消失。没有中央注册表,只有多播 DNS。效果非常好 - 只需看看 OS X。

可移植的方法是使用 jmdns - http://jmdns.sourceforge.net / - OS X 方式是使用Apple Java 外观。

The absolute easiest way - and simplest in my opinion - to do this is with ZeroConf!

Each node announce themselves, and listen to when others show up and dissappear. No central registry, just multicast DNS. Works exceedingly well - just look at OS X.

The portable approach is to use jmdns - http://jmdns.sourceforge.net/ - the OS X way is to use the Apple Java facade.

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