Reputation: 113
I have a task (i describe it a bit later) and as far as I understand, Hazelcast is a best choice for it. But it has so many features and usages, so I can't understand what exactly to choose.
Actually the task is:
I have Java server app A and Java server app B. I have several Java servers, some of them holding A app instance, some of them holding B instance, some holding both.
I need to store one map between all servers. Both A and B can put in map, and B can read from the map by key.
So I think I need a distributed map, but I cant understand what other features do I need? What will be a backup configuration? Do I need distributed query for B to lookup by key? Do I need a "Hazelcast client"?
Upvotes: 2
Views: 1372
Reputation: 113
Steve! Thank you very mach for your answer. Finally in my logic class i created a singleton to work with Hazelcast instance - like
final static String DistributedMapName = "SystemUserActivityMap";
private static HazelcastInstance instance = Hazelcast.newHazelcastInstance();
I also created a hazelcast.xml, pretty simple
<network>
<port auto-increment="true">5701</port>
<join>
<multicast enabled="false">
<multicast-group>224.2.2.3</multicast-group>
<multicast-port>54327</multicast-port>
</multicast>
<tcp-ip enabled="true">
<interface>127.0.0.1</interface>
</tcp-ip>
<aws enabled="false">
</aws>
</join>
</network>
<map name="SystemUserActivityMap">...
everything seemed to working fine at first, but later i noticed in tomcat errorlog messages that hazelcast starts new port from time to time, so soon after start it was
Members [1] {
Member [127.0.0.1]:5701 this
}
now its
Members [9] {
Member [127.0.0.1]:5701
Member [127.0.0.1]:5702
Member [127.0.0.1]:5703
Member [127.0.0.1]:5704
Member [127.0.0.1]:5705
Member [127.0.0.1]:5706
Member [127.0.0.1]:5707 this
Member [127.0.0.1]:5708
Member [127.0.0.1]:5709
}
and continue growing... i don't understand why it uses all these ports on this machine
Upvotes: 0
Reputation: 40388
Hazelcast is a great tool. Agree it can be daunting to see what you need, but it's simpler than you think :)
You first need to run one or more Hazelcast nodes to get your grid running (recommend 2 or more to give redundancy).
It's up to you if server A/B have embedded hazelcast nodes, or if you run a hazelcast grid externally to server A/B and use HazelcastClient to talk to it.
You're best placed to evaluate this decision. It's probably easier to start by embedding a hazelcast grid node into server A/B. If you find it doesn't work for you, run a separate hazelcast grid and switch to using HazelcastClient in server A/B.
You will need to configure some ports for your grid to run on, the most common configuration is localhost:5701, and incremental ports up from here (5702, 5703, etc).
To distribute your data, this is dead easy - configure a hazelcast Map, give it a name, and set the backup count (a value of 1 would be fine).
I can't see that you need a distributed query here, since IMap<K,V>
should give you access to the data you need.
Does this help? Do you have further specific questions?
The Hazelcast documentation is rather good and there is also an active user community.
Good luck!
Upvotes: 2