Ignite 快速开始

Ignite 快速开始

一、创建IgniteServer

  • 创建 Maven工程,在pom.xm中添加
 
org.apache.ignite 
ignite-core 
${ignite.version} 
  
org.apache.ignite 
ignite-spring 
${ignite.version} 
  
org.apache.ignite 
ignite-indexing 
${ignite.version} 
 
  • 在IgniteServerApplication类中添加如下代码
public static void main(String[] args) { 
Ignite ignite = Ignition.start("config/server-ignite.xml");
} 
  • 添加配置文件 server-ignite.xml
 
 
 
  
 
  • 添加 example-default.xml
 
 
 
  
 
 
 





 



 
  
 

 
 

 
 
 
127.0.0.1:47500..47509 
 
 
 
 
 
 
 
 
  • 启动 IgniteServer程序

二、创建IgniteClient

  • 创建 Maven工程,在pom.xm中添加
 
org.apache.ignite 
ignite-core 
${ignite.version} 
  
org.apache.ignite 
ignite-spring 
${ignite.version} 
  
org.apache.ignite 
ignite-indexing 
${ignite.version} 
 
  • 在 IgniteClientApplication类中添加如下代码
public static void main(String[] args) throws IgniteException { 
// Preparing IgniteConfiguration using Java APIs 
IgniteConfiguration cfg = new IgniteConfiguration(); // The node will be started as a client node. 
cfg.setClientMode(true); // Classes of custom Java logic will be transferred over the wire from this app. 
cfg.setPeerClassLoadingEnabled(true); // Setting up an IP Finder to ensure the client can locate the servers. 
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder(); 
ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509"));
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder)); // Starting the node 
Ignite ignite = Ignition.start(cfg); // Create an IgniteCache and put some values in it. 
IgniteCache cache = ignite.getOrCreateCache("myCache"); 
cache.put(1, "Hello"); 
cache.put(2, "World!"); System.out.println(">> Created the cache and add the values."); // Executing custom Java compute task on server nodes.
ignite.compute(ignite.cluster().forServers()).broadcast(new RemoteTask()); System.out.println(">> Compute task is executed, check for output on the server nodes."); // Disconnect from the cluster. 
ignite.close(); 
} /** 
* A compute tasks that prints out a node ID and some details about its OS and JRE. 
* Plus, the code shows how to access data stored in a cache from the compute task. 
*/ 
private static class RemoteTask implements IgniteRunnable { 
@IgniteInstanceResource 
Ignite ignite; @Override 
public void run() { 
System.out.println(">> Executing the compute task"); System.out.println( 
" Node ID: " + ignite.cluster().localNode().id() + "\n" + 
" OS: " + System.getProperty("os.name") + 
" JRE: " + System.getProperty("java.runtime.name")); IgniteCache cache = ignite.cache("myCache"); System.out.println(">> " + cache.get(1) + " " + cache.get(2)); 
} 
} 
  • 启用IgniteClient程序


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部