{"id":28939,"date":"2015-10-26T16:31:34","date_gmt":"2015-10-26T11:01:34","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=28939"},"modified":"2024-01-02T17:48:40","modified_gmt":"2024-01-02T12:18:40","slug":"hazelcast-integration-with-grails","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/hazelcast-integration-with-grails\/","title":{"rendered":"Getting started with Hazelcast using Grails in 10 minutes"},"content":{"rendered":"<p>In computing, Hazelcast is an open source in-memory data grid based on Java. This blog will help you to tune the performance of your Grails application using Hazelcast.<\/p>\n<h3>Integrating Hazelcast with Grails<\/h3>\n<p><strong>Step 1:<\/strong> Setup Hazelcast\u00a0server using server.sh (Packaged within Hazelcast zipped bundle):<\/p>\n<div style=\"margin-left: 50px\">\n<ul>\n<li>Download the Hazelcast .zip from this link http:\/\/hazelcast.org\/download\/<\/li>\n<li>Execute server.sh from hazelcast-&lt;version&gt;\/bin<\/li>\n<li>This will start Hazelcast\u00a0cluster.<\/li>\n<\/ul>\n<h3>You will see something like this when you execute server.sh.<\/h3>\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-28980\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/10\/hazelcast.png\" alt=\"hazelcast\" width=\"534\" height=\"209\" \/>\\\u00a0<\/code><\/div>\n<p>Voila !! this is your first Hazelcast\u00a0cluster.<\/p>\n<\/div>\n<p><strong>Step 2: \u00a0<\/strong>Setting up Hazelcast client:<\/p>\n<div style=\"margin-left: 50px\">\n<ul>\n<li>Add dependency in your BuildConfig.groovy:<\/li>\n<\/ul>\n<p><code>compile(\"com.hazelcast:hazelcast-client:3.5.2\")<\/code><\/p>\n<ul>\n<li>Create a HazelcastClient.groovy file in your Grails application&#8217;s <code>~\/src\/groovy<\/code>:<\/li>\n<\/ul>\n<p><code>class HazelcastClient {<\/code><\/p>\n<p><code>private static HazelcastInstance _client<\/code><br \/>\n<code><br \/>\npublic static HazelcastInstance getClient() {<br \/>\nif (!(_client != null &amp;&amp; _client.getLifecycleService().isRunning()))<br \/>\n{<br \/>\nClientConfig clientConfig = new ClientConfig()<br \/>\nclientConfig.getNetworkConfig().addAddress(HAZELCAST SERVER URL)<br \/>\n_client = com.hazelcast.client.HazelcastClient.newHazelcastClient(clientConfig)<br \/>\n}<br \/>\nreturn _client<br \/>\n}<br \/>\n}<br \/>\n<\/code><br \/>\nThis <code>getClient()<\/code> method will create a Hazelcast client and connects to Hazelcast server in <code>HAZELCAST SERVER URL<\/code><\/p>\n<\/div>\n<p><strong>Step 3: \u00a0<\/strong>Populating data in Hazelcast:<\/p>\n<div style=\"margin-left: 50px\">\n<p><code>IMap&lt;Integer, String&gt; map=getClient().getMap(&lt;YOUR MAP NAME&gt;)<br \/>\nmap.put(1,\"BOB\")<br \/>\nmap.put(2,\"ROY\")<br \/>\n<\/code><\/p>\n<\/div>\n<p><strong>Step 4: \u00a0<\/strong>Fetching data from Hazelcast :<\/p>\n<div style=\"margin-left: 50px\">\n<p><code>IMap&lt;Integer, String&gt; map=getClient().getMap(&lt;YOUR MAP NAME&gt;)<br \/>\nmap.get(1) \/\/ \"BOB\"<br \/>\n<\/code><\/p>\n<\/div>\n<p>Hope this will help!!<\/p>\n<p>Also, there&#8217;s a lot about Grails 3.0 going the rounds in the Grails community, here&#8217;s a compilation of latest TOP 8 updates on Grails 3.0 &#8211;<\/p>\n<p><span id=\"hs-cta-wrapper-505049df-fcc7-41a6-a8fc-41c13216e267\" class=\"hs-cta-wrapper\"><span id=\"hs-cta-505049df-fcc7-41a6-a8fc-41c13216e267\" class=\"hs-cta-node hs-cta-505049df-fcc7-41a6-a8fc-41c13216e267\"> <a href=\"http:\/\/www.tothenew.com\/insights\"><img decoding=\"async\" id=\"hs-cta-img-505049df-fcc7-41a6-a8fc-41c13216e267\" class=\"hs-cta-img\" style=\"border-width: 0px\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/481864\/505049df-fcc7-41a6-a8fc-41c13216e267.png\" alt=\"Grails 3.0\" \/><\/a><br \/>\n<\/span><\/span><\/p>\n<p>For more reference: visit\u00a0https:\/\/hazelcast.com\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In computing, Hazelcast is an open source in-memory data grid based on Java. This blog will help you to tune the performance of your Grails application using Hazelcast. Integrating Hazelcast with Grails Step 1: Setup Hazelcast\u00a0server using server.sh (Packaged within Hazelcast zipped bundle): Download the Hazelcast .zip from this link http:\/\/hazelcast.org\/download\/ Execute server.sh from hazelcast-&lt;version&gt;\/bin [&hellip;]<\/p>\n","protected":false},"author":421,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":9},"categories":[1],"tags":[2659,2660],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/28939"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/421"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=28939"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/28939\/revisions"}],"predecessor-version":[{"id":59878,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/28939\/revisions\/59878"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=28939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=28939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=28939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}