Ignite hello world

it2023-10-06  70

根据Ignite官网的Hello world 例子,

1.直接启动:./ignite.sh,这个命令会使用默认的配置文件,default-config.xml

2.书写例子

public static void main(String[] args) { IgniteConfiguration config = new IgniteConfiguration(); config.setClientMode(true); config.setPeerClassLoadingEnabled(true); TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder(); ipFinder.setAddresses(Collections.singletonList("192.168.10.234:47500..47509")); config.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder)); Ignite ignite = Ignition.start(config); IgniteCache<Integer, String> cache = ignite.getOrCreateCache("demo"); cache.put(1, "hello"); cache.put(2, "world"); System.out.println(">> Created the cache and add the values."); 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(); } public 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<Integer, String> cache = ignite.cache("demo"); System.out.println(">> " + cache.get(1) + " " + cache.get(2)); } }

3.启动main函数,异常,与远程节点有不同的 peerClassLoadingEnabled配置,原因是默认的配置文件没有这一项,默认值是false

4.修改配置文件,给IgniteConfiguration增加选项

5.重新启动ignite,运行代码

最新回复(0)