基于 Java 的应用程序的发现机制 API
我目前参与一个项目,我们/应用程序需要能够发现在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我绝对会推荐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).
如果你们都在同一个子网上,一个简单的解决方案是使用 多播套接字。选择一个地址(好吧,使其可配置),然后当新实例启动时,它会发送多播“ping”。这会通知其他服务器。
当然,这不会告诉您实例何时出现故障。为此,您有两种选择:
您将需要 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:
You will need 1-2 threads to monitor this and trigger appropriate events.
对于这类事情有很多选择,我个人最喜欢的是 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.
最简单的方法 - 在我看来也是最简单的 - 做到这一点就是使用 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.