zoukankan      html  css  js  c++  java
  • 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);
        }
    
    }
    
    

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


  • 相关阅读:
    使用PHP绘制统计图
    微信公众平台商户模块
    jQuery Mobile入门教程
    2013中国微信公众平台用户研究报告
    WordPress的SEO技术
    微信公众平台消息接口星标功能
    微信5.0打飞机怎么取得高分?
    微信公众平台的服务号和订阅号
    微信公众平台开发(58)自定义菜单
    微信公众平台开发(57)Emoji表情符号
  • 原文地址:https://www.cnblogs.com/lick468/p/15458894.html
Copyright © 2011-2022 走看看