Over a million developers have joined DZone.

Getting Started With Apache Ignite

This tutorial shows you how to create a simple "Hello World" example in Apache Ignite.

· Big Data Zone

Hortonworks DataFlow is an integrated platform that makes data ingestion fast, easy, and secure. Download the white paper now.  Brought to you in partnership with Hortonworks

The following technologies were used in this example:

  1. Java Development Kit (JDK) 1.8
  2. Apache Ignite 1.5.0-b1
  3. Maven 3.1.1
  4. IntelliJ IDEA 15 CE

Note: JDK 1.7 or above is required.

1. Download and Install Ignite

Download the latest binary distribution from the Apache Ignite website and extract the resulting .zip file to a location of your choice:

$ unzip apache-ignite-fabric-1.5.0-b1-bin.zip
$ cd apache-ignite-fabric-1.5.0-b1-bin

2. Set Environment Variable (Optional)

Set IGNITE_HOME environment variable to point to the installation folder and make sure there is no trailing / in the path. On my Mac, I have set this environment variable in .bash_profile file, like so:

export IGNITE_HOME=<path-to-ignite-installation-folder>

3. Start Ignite Cluster

Start a node using bin/ignite.sh command and specify an example configuration file provided in the Ignite installation:

$ bin/ignite.sh examples/config/example-ignite.xml

If the installation was successful, your Ignite node startup message should look like this:

Image title

Click on the image to view full size.

I have started one more node in another terminal, by repeating the above command (in step 3). 

Image title

Click on the image to view full size.

I now have an Ignite cluster setup with two server nodes running. You can start as many nodes as you like. Ignite will automatically discover all the nodes.

4. Add Ignite Maven Dependency

Add the following Ignite dependencies in your project’s pom.xml file:



5. HelloWorld.java

Here is a sample HelloWord.java file that prints ‘Hello World’ on all the nodes in the cluster.

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteException;
import org.apache.ignite.Ignition;

public class HelloWorld {
  public static void main(String[] args) throws IgniteException {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
      // Put values in cache.
      IgniteCache<Integer, String> cache = ignite.getOrCreateCache("myCache");

      cache.put(1, "Hello");
      cache.put(2, "World!");

      // Get values from cache
      // Broadcast 'Hello World' on all the nodes in the cluster.
      ignite.compute().broadcast(()->System.out.println(cache.get(1) + " " + cache.get(2)));

6. Project Structure

Review project directory structure:

Image title

7. Set VM Options in IDEA

Go to Run —> Edit Configurations —> VM options (under Configuration tab) and enter:


This step is required only because we are trying to provide a relative path to the configuration file in our code (line #7). You can skip this step and provide an absolute path instead.

8. Output

Run HelloWorld.java. You will see ‘Hello World!’ printed on all three nodes. 

On IDEA console:

Image title

Click on the image to view full size.

On both terminals:

Image title

Click on the image to view full size.


If you prefer to watch a running example, here is a short screencast.

For more information, documentation, and screencasts, visit the Apache Ignite website.

Hortonworks Sandbox is a personal, portable Apache Hadoop® environment that comes with dozens of interactive Hadoop and it's ecosystem tutorials and the most exciting developments from the latest HDP distribution, brought to you in partnership with Hortonworks.

caching,apache ignite,tutorial,getting started,database,data grid,compute grid,sql

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}