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?
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With