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

    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 (this step is 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:

    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). 
    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 Depedency

    Add the following Ignite dependencies in your project’s pom.xml file:
    <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

    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.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

    Review project directory structure.
    Click on the image to view full size.

    7.  Set VM Options in IDEA

    Go to Run --> Edit Configurations --> VM options (under Configuration tab) and enter:
    -DIGNITE_HOME=<path-to-Ignite-installation-folder>
    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
    Click on the image to view full size.


    On both terminals
    Click on the image to view full size.

    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.




  2. Businesses are accumulating data at enormous rates requiring huge amounts of storage. Managing large data is hard, but processing it is even more challenging. With terabytes of data to store and process, it is often the case that developers find themselves in a quandary about how to strike the right balance between speed, scalability, and cost. 

    Storing data in cache can significantly enhance the speed of your application. It reduces the network overhead caused due to frequent data movement between an application and the database. 

    Apache Ignite allows you to store the most frequently accessed data in memory. It evenly distributes the data across a cluster of computers in either partitioned or replicated manner. Ignite allows you to access the data from any underlying data store – RDBMS, NoSQL, or HDFS.


    You may ask - Once a cluster is formed with n nodes, what if the size of the data set increases? In that case, you can dynamically add nodes to the Ignite cluster without restarting the entire cluster. Ignite has virtually unlimited scale.

    Ignite database caching provides the following configurable options: 

    Write-Through and Read-Through 
    In write-through mode, when data is updated in cache, it is also updated in the underlying database. In case of read-through mode, when the requested data is not available in cache, it is automatically loaded from the database.

    Write-Behind Caching
    Ignite provides an option to asynchronously perform updates to the database. By default, each update in a write-through mode involves a corresponding request to the underlying database. With write-behind caching enabled, cache data updates are accumulated and sent to the database in batches. For applications where put and remove operations are frequent, write-behind caching can provide a performance boost.

    Automatic Persistence
    Ignite ships with its own user-friendly database schema-mapping wizard that provides automatic support for integrating with persistent stores. This utility automatically connects to the underlying database and generates all the required XML OR-mapping configuration and Java domain model POJOs.

    SQL Queries
    To query the Ignite cache, you can simply use the standard SQL syntax (ANSI 99). Ignite lets you use any SQL function, aggregation, or grouping. It also supports distributed SQL joins. Here is an example of how to execute an SQL query in Ignite:

    IgniteCache<Long, Person> cache = ignite.cache("mycache");
    
    // ‘Select’ query to concatenate the first and last name of all persons.
    SqlFieldsQuery sql = new SqlFieldsQuery(
      "select concat(firstName, ' ', lastName) from Person");
    
    // Execute the query on Ignite cache and print the result.
    try (QueryCursor<List<?>> cursor = cache.query(sql)) {
      for (List<?> row : cursor)
        System.out.println("Full name: " + row.get(0));
    }

    Conclusion

    Apache Ignite is an open source project focused towards distributed in-memory computing. Ignite stores data in memory, distributed across multiple nodes providing fast data access. The option to asynchronously propagate data to the persistence layer is an added advantage. Additionally, the ability to integrate with a variety of databases also makes Ignite an easy choice for developers to use it for database caching.

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

Blog Archive
Loading
Dynamic Views theme. Powered by Blogger.