Apache Ignite Hello world ! 配置

系统:ubuntu 16.04
IDE:IDEA 2016.3
Apache Ignite 版本: 1.8.0
Java 版本 1.8.0_101

下载并安装ignite

去官网下载最新版即可

设置环境变量

将下载下来的压缩包解压,然后

export IGNITE_HOME=/home/abc/ignite1.8

等号后面是解压的目录,目录下有bin,examples等目录

启动ignite集群(cluster)

进入刚才解压的目录,使用命令+配置文件的方法启动ignite,多开两个终端,然后多开两个ignite。
命令如下:

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

cd

添加依赖项目

上面是系统里面的操作,下面要打开idea这个IDE进行操作。
首先新建一个maven项目,添加依赖到pom.xml文件中<dependencies>这个选项。
整个pom.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>igniteHelloWorld</groupId>
    <artifactId>igniteHelloWorld</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-core</artifactId>
            <version>1.8.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.ignite/ignite-spring -->
        <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-spring</artifactId>
            <version>1.8.0</version>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.3.175</version>
        </dependency>
    </dependencies>
</project>

这边依赖项一开始的时候我没有加入h2database,然后ignite就无法启动,只好把他加上。

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);
      });
    }
  }
}

设置java虚拟机选项

在Run –> Edit Configurations –> VM options (在Configuration页面) 输入:

-DIGNITE_HOME=ignite安装路径

查看输出结果

/usr/java/jdk/bin/java -DIGNITE_HOME=/home/whh/apache-ignite-fabric-1.8.0-bin -Didea.launcher.port=7532 -Didea.launcher.bin.path=/home/whh/idea-IU-162.2228.15/bin -Dfile.encoding=UTF-8 -classpath /usr/java/jdk/jre/lib/charsets.jar:/usr/java/jdk/jre/lib/deploy.jar:/usr/java/jdk/jre/lib/ext/cldrdata.jar:/usr/java/jdk/jre/lib/ext/dnsns.jar:/usr/java/jdk/jre/lib/ext/jaccess.jar:/usr/java/jdk/jre/lib/ext/jfxrt.jar:/usr/java/jdk/jre/lib/ext/localedata.jar:/usr/java/jdk/jre/lib/ext/nashorn.jar:/usr/java/jdk/jre/lib/ext/sunec.jar:/usr/java/jdk/jre/lib/ext/sunjce_provider.jar:/usr/java/jdk/jre/lib/ext/sunpkcs11.jar:/usr/java/jdk/jre/lib/ext/zipfs.jar:/usr/java/jdk/jre/lib/javaws.jar:/usr/java/jdk/jre/lib/jce.jar:/usr/java/jdk/jre/lib/jfr.jar:/usr/java/jdk/jre/lib/jfxswt.jar:/usr/java/jdk/jre/lib/jsse.jar:/usr/java/jdk/jre/lib/management-agent.jar:/usr/java/jdk/jre/lib/plugin.jar:/usr/java/jdk/jre/lib/resources.jar:/usr/java/jdk/jre/lib/rt.jar:/home/whh/labshare/whh/igniteHelloWorld/target/classes:/home/whh/.m2/repository/org/apache/ignite/ignite-core/1.8.0/ignite-core-1.8.0.jar:/home/whh/.m2/repository/javax/cache/cache-api/1.0.0/cache-api-1.0.0.jar:/home/whh/.m2/repository/org/jetbrains/annotations/13.0/annotations-13.0.jar:/home/whh/.m2/repository/org/gridgain/ignite-shmem/1.0.0/ignite-shmem-1.0.0.jar:/home/whh/.m2/repository/org/apache/ignite/ignite-spring/1.8.0/ignite-spring-1.8.0.jar:/home/whh/.m2/repository/org/springframework/spring-core/4.1.0.RELEASE/spring-core-4.1.0.RELEASE.jar:/home/whh/.m2/repository/org/springframework/spring-aop/4.1.0.RELEASE/spring-aop-4.1.0.RELEASE.jar:/home/whh/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar:/home/whh/.m2/repository/org/springframework/spring-beans/4.1.0.RELEASE/spring-beans-4.1.0.RELEASE.jar:/home/whh/.m2/repository/org/springframework/spring-context/4.1.0.RELEASE/spring-context-4.1.0.RELEASE.jar:/home/whh/.m2/repository/org/springframework/spring-expression/4.1.0.RELEASE/spring-expression-4.1.0.RELEASE.jar:/home/whh/.m2/repository/org/springframework/spring-tx/4.1.0.RELEASE/spring-tx-4.1.0.RELEASE.jar:/home/whh/.m2/repository/org/springframework/spring-jdbc/4.1.0.RELEASE/spring-jdbc-4.1.0.RELEASE.jar:/home/whh/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar:/home/whh/.m2/repository/com/h2database/h2/1.3.175/h2-1.3.175.jar:/home/whh/idea-IU-162.2228.15/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain my.ignite.example.Demo
[11:42:46]    __________  ________________ 
[11:42:46]   /  _/ ___/ |/ /  _/_  __/ __/ 
[11:42:46]  _/ // (7 7    // /  / / / _/   
[11:42:46] /___/\___/_/|_/___/ /_/ /___/  
[11:42:46] 
[11:42:46] ver. 1.8.0#20161205-sha1:9ca40dbe
[11:42:46] 2016 Copyright(C) Apache Software Foundation
[11:42:46] 
[11:42:46] Ignite documentation: http://ignite.apache.org
[11:42:46] 
[11:42:46] Quiet mode.
[11:42:46]   ^-- Logging to file '/home/whh/apache-ignite-fabric-1.8.0-bin/work/log/ignite-4a096a44.0.log'
[11:42:46]   ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or "-v" to ignite.{sh|bat}
[11:42:46] 
[11:42:46] OS: Linux 4.4.0-57-generic amd64
[11:42:46] VM information: Java(TM) SE Runtime Environment 1.8.0_101-b13 Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.101-b13
[11:42:46] Initial heap size is 124MB (should be no less than 512MB, use -Xms512m -Xmx512m).
[11:42:46] Configured plugins:
[11:42:46]   ^-- None
[11:42:46] 
[11:42:46] Security status [authentication=off, tls/ssl=off]
[11:42:49] Performance suggestions for grid  (fix if possible)
[11:42:49] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true
[11:42:49]   ^-- Disable peer class loading (set 'peerClassLoadingEnabled' to false)
[11:42:49]   ^-- Disable grid events (remove 'includeEventTypes' from configuration)
[11:42:49] 
[11:42:49] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}
[11:42:49] 
[11:42:49] Ignite node started OK (id=4a096a44)
[11:42:49] Topology snapshot [ver=8, servers=4, clients=0, CPUs=4, heap=4.7GB]
Hello World!
[11:42:50] Ignite node stopped OK [uptime=00:00:00:639]

大致就是以上过程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值