• ignite + spring boot + 本地服务器


    1.安装ignite服务器

    下载链接: https://ignite.apache.org/download.cgi#binaries

    解压之后本地启动,进入安装目录之后,使用命令: ignite.bat ..examplesconfigexample-ignite.xml

     启动成功示例如下:
    


    本地启动多台,构建集群

    2.spring boot 项目搭建 github链接:https://github.com/lick468/ignite_demo

    pom.xml 依赖 ignite的pom版本需要和下载的版本一致,本文使用的都是2.11.0版本

    <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <optional>true</optional>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <!--ignite 配置 -->
    
            <dependency>
                <groupId>org.apache.ignite</groupId>
                <artifactId>ignite-core</artifactId>
                <version>2.11.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.ignite</groupId>
                <artifactId>ignite-spring</artifactId>
                <version>2.11.0</version>
            </dependency>
            
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    

    特别的,设置一下h2的版本,否则启动失败

    <properties>
        <h2.version>1.4.197</h2.version>
    </properties>
    

    配置文件 igniteConfig.java

        @Bean
        public Ignite igniteInstance() {
            // 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
            return Ignition.start(cfg);
        }
    

    测试controller : IgniteController

    package com.nenu.controller;
    
    import lombok.extern.slf4j.Slf4j;
    import org.apache.ignite.Ignite;
    import org.apache.ignite.IgniteCache;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import javax.annotation.Resource;
    
    /**
     * @author :lichuankang
     * @date :2021/10/25 14:45
     * @description :ignite控制器
     */
    @RestController
    @Slf4j
    public class IgniteController {
    
        @Resource
        private Ignite ignite;
    
        @GetMapping(value = "/igniteWrite")
        public String testIgniteWrite() {
            IgniteCache<String, String> cache = ignite.getOrCreateCache("myCache");
            cache.put("name", "this is name");
            cache.put("age", "24");
            return "success";
        }
    
        @GetMapping(value = "/igniteRead")
        public String igniteRead() {
            IgniteCache<String, String> cache = ignite.cache("myCache");
            return cache.get("name");
        }
    
        @GetMapping(value = "/write")
        public String igniteWriteByInput(String key, String value) {
            IgniteCache<String, String> cache = ignite.getOrCreateCache("myCache");
            cache.put(key, value);
            return "success";
        }
    
        @GetMapping(value = "/read")
        public String igniteWriteByRead(String key) {
            IgniteCache<String, String> cache = ignite.cache("myCache");
            return cache.get(key);
        }
    
    }
    
    

    执行结果 先赋值,后获取值


  • 相关阅读:
    数组的操作方法
    数组遍历的方法以及区别
    组件内的守卫
    路由守卫
    软件工程
    java web (j2ee)学习路线 —— 将青春交给命运
    团队作业(一)- 第五组
    软件工程
    软件工程-第二次作业
    java局部/成员/静态/实例变量
  • 原文地址:https://www.cnblogs.com/lick468/p/15458894.html
Copyright © 2020-2023  润新知