Hazelcast Cluster with Jelastic PaaS
Hazelcast is a platform designed specially for sharing and distributing the data inside the application cluster. In this tutorial we will show how to configure Hazelcast clustering inside the Jelastic cloud.
1. Log in to the Jelastic dashboard.
2. Click the Create environment button to open the topology wizard. Pick up Tomcat as an application server, enable Public IP, and turn on High-availability. This will pair up the nodes and create Tomcat cluster in such a way. The NGINX load balancer will be added automatically.
Set the resource limits within cloudlet sliders for the both instances and click Create.
In about a minute your environment will appear at the dashboard.
Download Hazelcast Package
1. Open the official web-site and download the latest stable Hazelcast platform release.
2. Extract the downloaded .zip package.
Let’s use the Hazelcast cluster to create a simple Java server and a client application.
1. Create a new Java class server application.
2. Import the libraries from the Hazelcast package you’ve downloaded before (they are located in hazelcast-x.x.x/lib folder).
In this example we will work with application, which runs the first server and uses the customer’s queue and map:
3. Create the listener for your servlet, which will be used for automatic running your code after it was deployed.
4. Modify the web.xml file by adding the < listener > section to it.
5. Finally, build your .war project file.
Use the Native Hazelcast Java Client API to create a new Java class.
The following sample performs connection to all the cluster’s nodes and shows the amount of customers in the map:
Note: To see public IP addresses of your nodes click the additional button for the cluster.
In the case your cluster includes 2 different nodes the port number for each of them should be the similar.
1. Navigate back to the dashboard and use Deployment Manager for uploading earlier created .war application.
2. Deploy the uploaded package to the environment with Tomcat cluster.
3. Then press the Config button next to the Tomcat nodes to open the configuration manager. Navigate to the lib folder and upload hazelcast-all-2.6.jar file there.
4. To apply the new configurations restart your application servers by clicking Restart node button.
5. To make sure your Hazelcast cluster was successfully created open the Tomcat server logs.
As it is shown in the picture above, both instances of Tomcat server were clustered and Hazelcast server apps can communicate between themselves.
6. Run your client application locally. It will connect to each of server nodes and display the map size for both of them.
Now you have your own clustered highly reliable and scalable Hazelcast hosting.