- Java Development Kit (JDK) 1.8
- Apache Ignite 1.5.0-b1
- Maven 3.1.1
- IntelliJ IDEA 15 CE
1. Download and Install Ignite
$ unzip apache-ignite-fabric-1.5.0-b1-bin.zip $ cd apache-ignite-fabric-1.5.0-b1-bin
2. Set Environment Variable (this step is optional)
export IGNITE_HOME=<path-to-ignite-installation-folder>
3. Start Ignite Cluster
$ bin/ignite.sh examples/config/example-ignite.xml
I have started one more node in another terminal, by repeating the above command (in step 3).
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 Depedency
<dependency> <groupId>org.apache.ignite</groupId> <artifactId>ignite-core</artifactId> <version>1.5.0-b1</version> </dependency> <dependency> <groupId>org.apache.ignite</groupId> <artifactId>ignite-spring</artifactId> <version>1.5.0-b1</version> </dependency>
5. HelloWorld.java
import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; 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 and // broadcast 'Hello World' on all the nodes in the cluster. ignite.compute().broadcast(() -> { String hello = cache.get(1); String world = cache.get(2); System.out.println(hello + " " + world); }); } } }
6. Project Structure
7. Set VM Options in IDEA
-DIGNITE_HOME=<path-to-Ignite-installation-folder>
8. Output
Screencast
If you prefer to watch a running example, here is a short screencast.For more information, documentation, and screencasts, visit the Apache Ignite website.