Skip to main content

Posts

Showing posts with the label Hazelcast

Hazelcast : Auto Reconnect to Hazelcast Server

Points To Remember You can call the method getLifecycleService().isRunning()  to check if the hazelcast clinet is up and running. Auto Reconnect to Hazelcast Server You can use the following code to reconnect to Hazelcast server, in case the hazelcast client looses the connection to the hazelcast server. if(!(hazelcastInstance!=null && hazelcastInstance.getLifecycleService().isRunning())){ // create a new hazelcast connection } return hazelcast instance

Hazelcast : Setup Hazelcast Server in Spring Boot Application

Following are the steps to setup to Hazelcast server Put data in hazelcast Retrieve data from hazelcast Step 1 : Add the Hazelcast dependency compile("com.hazelcast:hazelcast:3.3.5") compile("com.hazelcast:hazelcast-client:3.3.5") Step 2 : Initialize the Hazelcast Instance (Hazelcast Server) Config config = new XmlConfigBuilder().build(); HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config); The above code will start the Hazelcast server with default settings. For more settings you can refer this blog . Step 3 : Connect to Hazelcast server using a Hazelcast Client Now to need to get a Hazelcast client to get and post data to the hazelcast server. Following is an example of how to get the hazelcast client. ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig().addAddress(address); clientConfig.getNetworkConfig().setConnectionAttemptLimit(10); clientConfig.getNetworkConfig().setConnectionAttemptPeriod(24 * 60); ...