Lightbend Activator

Hazelcast with Akka and Spray

Activator will be EOL-ed on May 24, 2017.

We’re making it easier and simpler for developers to get started with Lightbend technologies. This unfortunately means that future releases of Play, Akka and Scala will no longer include Activator support, and Lightbend’s Activator server will be decommissioned by the end of 2017. Instead of supporting Activator to create and set up development projects, we'll be supporting standard Giter8 templates for sbt users and Maven archetypes for Maven users. So going forward,

To create new Lightbend projects

Instead of using the Activator command, make sure you have sbt 0.13.13 (or higher), and use the “sbt new” command, providing the name of the template. For example, “$ sbt new akka/hello-akka.g8”. You can find a list of templates here.

Also, as a convenience, the Lightbend Project Starter allows you to quickly create a variety of example projects that you just unzip and run.

To create new templates

If you want to create new templates, you can now do that in Giter8.

To migrate templates from Activator to Giter8

If you created Activator templates in the past, please consider migrating them to Giter8 with this simple process.

Hazelcast with Akka and Spray

June 6, 2014
scala akka spray hazelcast scaladays2014

An example of an In-Memory Data Grid using Hazelcast.

How to get "Hazelcast with Akka and Spray" on your computer

There are several ways to get this template.

Option 1: Choose hazelcast-spray-akka in the Lightbend Activator UI.

Already have Lightbend Activator (get it here)? Launch the UI then search for hazelcast-spray-akka in the list of templates.

Option 2: Download the hazelcast-spray-akka project as a zip archive

If you haven't installed Activator, you can get the code by downloading the template bundle for hazelcast-spray-akka.

  1. Download the Template Bundle for "Hazelcast with Akka and Spray"
  2. Extract the downloaded zip file to your system
  3. The bundle includes a small bootstrap script that can start Activator. To start Lightbend Activator's UI:

    In your File Explorer, navigate into the directory that the template was extracted to, right-click on the file named "activator.bat", then select "Open", and if prompted with a warning, click to continue:

    Or from a command line:

     C:\Users\typesafe\hazelcast-spray-akka> activator ui 
    This will start Lightbend Activator and open this template in your browser.

Option 3: Create a hazelcast-spray-akka project from the command line

If you have Lightbend Activator, use its command line mode to create a new project from this template. Type activator new PROJECTNAME hazelcast-spray-akka on the command line.

Option 4: View the template source

The creator of this template maintains it at

Option 5: Preview the tutorial below

We've included the text of this template's tutorial below, but it may work better if you view it inside Activator on your computer. Activator tutorials are often designed to be interactive.

Preview the tutorial

What is Hazelcast?

Hazelcast is an in-memory data grid technology. By using Hazelcast, in-memory distributed data structures can be easily implemented. This kind of structures are very useful for sharing key data among several hosts, among other uses.

The example in this template implements a server and a client that share an IMap (distributed map). This map will represent a shopping list. One instance, aka the mother, can add and remove items from the list. The other instance, aka the child, can only read the elements in the list.

Let's see how this is implemented.

Hazelcast Server

In order to create an IMap, a Hazelcast instance must be created first:

      val hazelcastInstance = Hazelcast.newHazelcastInstance(new Config())

Afterwards, an IMap named "shoppingList" is created. This map contains the name of the item of the shopping-list and the number of items of that type:

      val shoppingList = hazelcastInstance.getMap[String, Int]("shoppingList")

The logic for adding new items to the map is implemented in the following piece of code:

      shoppingList.put(item, amount)

For removing items from the list, the following code is used:


Hazelcast Client

In order to obtain an IMap, a Hazelcast client instance must be created first:

      val hazelcastClient = HazelcastClient.newHazelcastClient(new ClientConfig())

For obtaining the map, the next action is performed:

      val shoppingList = hazelcastClient.getMap[String, Int]("shoppingList")

Finally, the items of the map can be extracted by means of their keys and corresponding values.

How can I test it?

An API has been created for testing the functionality of the example: ApiActor.

For simulating the behaviour of the child and reading the shopping list, you can access to the URL

For simulating the addition of an element (done by the mother instance), a POST request must be performed. For example, if you want to add three oranges, you should send a POST request to

For simulating the removal of all the items of a product (all oranges, all apples...), a DELETE request must be performed to, where product_name is substituted by the name of the product (apple, orange...)