apache ignite_Kubernetes集群上的Apache Ignite和Spring第1部分:Spring Boot应用程序

apache ignite

在之前的一系列博客中,我们在Kubernetes集群上启动了一个Ignite集群。
在本教程中,我们将使用先前在Spring Boot Application上创建的Ignite集群。


让我们使用Spring Boot创建我们的项目。 Spring Boot应用程序将连接到Ignite集群。

让我们添加依赖项。

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.5.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.gkatzioura</groupId><artifactId>job-api-ignite</artifactId><version>0.0.1-SNAPSHOT</version><name>job-api-ignite</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-cache</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.apache.ignite</groupId><artifactId>ignite-kubernetes</artifactId><version>2.7.6</version></dependency><dependency><groupId>org.apache.ignite</groupId><artifactId>ignite-spring</artifactId><version>2.7.6</version><exclusions><exclusion><groupId>org.apache.ignite</groupId><artifactId>ignite-indexing</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.12</version><scope>provided</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

与之前的教程一样,我们将使用GitHub的Job api。

第一步是添加反序列化的作业模型。

 package com.gkatzioura.jobapi.model;  import java.io.Serializable;  import lombok.Data;  @Data  public class Job implements Serializable { private String id; private String type; private String url; private String createdAt; private String company; private String companyUrl; private String location; private String title; private String description;  } 

我们需要一个乔布斯仓库。 注意该类需要可序列化。 Ignite将数据缓存在堆外。

 package com.gkatzioura.jobapi.repository;  import java.util.ArrayList;  import java.util.List;  import com.gkatzioura.jobapi.model.Job;  import lombok.Data;  import org.apache.ignite.Ignite;  import org.springframework.cache.annotation.Cacheable;  import org.springframework.stereotype.Repository;  import org.springframework.web.client.RestTemplate;  @Repository  public class GitHubJobRepository { private static final String JOB_API_CONSTANST = " https://jobs.github.com/positions.json?page= {page}" ; public static final String GITHUBJOB_CACHE = "githubjob" ; private final RestTemplate restTemplate; private final Ignite ignite; GitHubJobRepository(Ignite ignite) { this .restTemplate = new RestTemplate(); this .ignite = ignite; } @Cacheable (value = GITHUBJOB_CACHE) public List<Job> getJob( int page) { return restTemplate.getForObject(JOB_API_CONSTANST,JobList. class ,page); } public List<Job> fetchFromIgnite( int page) { for (String cache: ignite.cacheNames()) { if (cache.equals(GITHUBJOB_CACHE)) { return (List<Job>) ignite.getOrCreateCache(cache).get( 1 ); } } return new ArrayList<>(); } @Data private static class JobList extends ArrayList<Job> { }  } 

JobList类存在的主要原因是为了方便解组。
如您所见,存储库的注释为@Cacheable。 这意味着我们的请求将被缓存。 就本示例而言,fetchFromIgnite方法是一种测试方法。 我们将使用它直接访问ignite缓存的数据。

我们还将添加控制器。

 package com.gkatzioura.jobapi.controller;  import java.util.List;  import com.gkatzioura.jobapi.model.Job;  import com.gkatzioura.jobapi.repository.GitHubJobRepository;  import org.springframework.web.bind.annotation.GetMapping;  import org.springframework.web.bind.annotation.PathVariable;  import org.springframework.web.bind.annotation.RequestMapping;  import org.springframework.web.bind.annotation.RestController;  @RestController  @RequestMapping ( "/jobs" )  public class JobsController { private final GitHubJobRepository gitHubJobRepository; JobsController(GitHubJobRepository gitHubJobRepository) { this .gitHubJobRepository = gitHubJobRepository; } @GetMapping ( "/github/{page}" ) public List<Job> gitHub( @PathVariable ( "page" ) int page) { return this .gitHubJobRepository.getJob(page); } @GetMapping ( "/github/ignite/{page}" ) public List<Job> gitHubIgnite( @PathVariable ( "page" ) int page) { return this .gitHubJobRepository.fetchFromIgnite(page); }  } 

控制器上有两种方法,一种是照常获取数据并将其缓存在后台,另一种是我们将用于测试的方法。

现在是时候配置使用Kubernetes集群上的节点的Ignite客户端了。

 package com.gkatzioura.jobapi.config;  import lombok.extern.slf4j.Slf4j;  import org.apache.ignite.Ignite;  import org.apache.ignite.Ignition;  import org.apache.ignite.cache.spring.SpringCacheManager;  import org.apache.ignite.configuration.IgniteConfiguration;  import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;  import org.apache.ignite.spi.discovery.tcp.ipfinder.kubernetes.TcpDiscoveryKubernetesIpFinder;  import org.springframework.cache.annotation.EnableCaching;  import org.springframework.context.annotation.Bean;  import org.springframework.context.annotation.Configuration;  @Configuration  @EnableCaching  @Slf4j  public class SpringCacheConfiguration { @Bean public Ignite igniteInstance() { log.info( "Creating ignite instance" ); TcpDiscoveryKubernetesIpFinder tcpDiscoveryKubernetesIpFinder = new TcpDiscoveryKubernetesIpFinder(); tcpDiscoveryKubernetesIpFinder.setNamespace( "default" ); tcpDiscoveryKubernetesIpFinder.setServiceName( "job-cache" ); TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi(); tcpDiscoverySpi.setIpFinder(tcpDiscoveryKubernetesIpFinder); IgniteConfiguration igniteConfiguration = new IgniteConfiguration(); igniteConfiguration.setDiscoverySpi(tcpDiscoverySpi); igniteConfiguration.setClientMode( false ); return Ignition.start(igniteConfiguration); } @Bean public SpringCacheManager cacheManager(Ignite ignite) { SpringCacheManager springCacheManager = new SpringCacheManager(); springCacheManager.setIgniteInstanceName(ignite.name()); return springCacheManager; }  } 

我们创建了缓存。 它应使用Kubernetes TCP发现模式。

下一步是添加我们的Main类。

 package com.gkatzioura.jobapi;  import org.springframework.boot.SpringApplication;  import org.springframework.boot.autoconfigure.SpringBootApplication;  import org.springframework.cache.annotation.EnableCaching;  @SpringBootApplication  @EnableCaching  public class IgniteKubeClusterApplication { public static void main(String[] args) { SpringApplication.run(IgniteKubeClusterApplication. class , args); }  } 

下一个博客将专注于将解决方案交付给kubernetes。

翻译自: https://www.javacodegeeks.com/2020/04/apache-ignite-and-spring-on-your-kubernetes-cluster-part-1-spring-boot-application.html

apache ignite

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/331270.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

tomcat(1)一个简单的web server

【0】README 0.1&#xff09;本文部分描述转自“深入剖析tomcat”&#xff0c; 旨在学习 一个简单的web server 的基础知识&#xff1b; 0.2&#xff09;for complete source code, please visit https://github.com/pacosonTang/HowTomcatWorks/tree/master/chapter1 【1】…

漫画:什么是MD5算法

转载自 玻璃猫 程序员小灰 摘要哈希生成的正确姿势是什么样呢&#xff1f;分三步&#xff1a; 1.收集相关业务参数&#xff0c;在这里是金额和目标账户。当然&#xff0c;实际应用中的参数肯定比这多得多&#xff0c;这里只是做了简化。 2.按照规则&#xff0c;把参数名和参数…

idea快速生成crud_Java / Spring:如何快速生成完整的Swagger文档CRUD REST API

idea快速生成crud作为开发人员&#xff0c;我们在日常生活中经常面临的最繁琐的任务之一就是编写良好且易于理解的文档。 无论我们的文档只有几行来解释功能的核心功能&#xff0c;还是表明系统的来龙去脉的成熟文章都没关系。 重要的是&#xff0c;我们试图通过文档传达的信息…

漫画:如何破解MD5算法

转载自 玻璃猫 程序员小灰 在之前的漫画中&#xff0c;我们介绍了MD5算法的基本概念和底层原理&#xff0c;没看过的小伙伴们可以点击下面的链接&#xff1a;《漫画&#xff1a;什么是MD5算法&#xff1f;》 这一次&#xff0c;我们来讲解如何破解MD5算法。 设MD5的哈希函数是…

自定义类加载器(ClassLoader + URLClassLoader)

【0】README 0.1&#xff09;本文主要对类加载器进行分析&#xff0c;且 URLClassLoader是 ClassLoader的子类&#xff1b; 0.2&#xff09;关于如何设置类加载器的加载路径&#xff0c;参见 对servlet容器的补充 【1】URLClassLoader类加载器 1.1&#xff09;URLClassLoad…

fork/join和线程池_从fork-join /线程池调用的Singelton bean中的访问spring请求范围缓存...

fork/join和线程池问题&#xff1a; 启用了Spring且其范围设置为Request的缓存需要由不在请求范围内的singleton bean访问。 解&#xff1a; Spring使您能够创建缓存&#xff0c;该缓存为请求范围保留数据。 例如 import org.springframework.cache.concurrent.ConcurrentMapC…

tomcat(2)一个简单的servlet容器

【0】README 0.1&#xff09;本文部分文字转自 “深入剖析Tomcat”&#xff0c;旨在学习 一个简单的servlet容器 的基础知识&#xff1b; 0.2&#xff09;for complete source code, please visit https://github.com/pacosonTang/HowTomcatWorks/tree/master/chapter2 0…

漫画:什么是Base64算法

转载自 玻璃猫 程序员小灰 ValueChar ValueChar ValueChar ValueChar0A16Q32g48w1B17R33h49x2C18S34i50y3D19T35j51z4E20U36k5205F21V37l5316G22W38m5427H23X39n5538I24Y40o5649J25Z41p57510K26a42q58611L27b43r59712M28c44s60813N29d45t61914O30e46u6215P31f47v63/控制字符&am…

soapui 测试soap_使用SoapUI调用不同的安全WCF SOAP服务-基本身份验证,第一部分

soapui 测试soap在这个分为三部分的系列中&#xff0c;我将演示如何使用SoapUI API工具来调用安全的WCF SOAP服务。 第一篇文章将着重于创建将要测试的系统的服务。 第二篇文章将介绍在基本身份验证机制保护的情况下调用它所需的步骤。 在最后一部分中&#xff0c;我将对初始服…

dmn是大脑中哪个区域_DMN中的函数式编程:感觉就像再次重读我的大学课程一样...

dmn是大脑中哪个区域在本文中&#xff0c;我想分享有关DMN中递归支持的有趣见解&#xff0c;并重点介绍FEEL语言的特定属性如何使功能性编程结构能够在DMN中建模。 我们将从一个基本示例开始&#xff0c;以演示FEEL语言和DMN构造的“商业友好”性质如何使我们能够解决一个通常…

对Servlet容器的补充

【0】README 0.1&#xff09;本文是对 一个简单的servlet容器 的补充&#xff1b; 【1】Servlet容器 1.1&#xff09;通过一个简单的servlet容器这篇博文&#xff0c;我们看到&#xff1a;其中的核心代码是 类加载器&#xff0c; 然而&#xff0c;在我follow 其代码&#xf…

漫画:什么是A*寻路算法

转载自 玻璃猫 程序员小灰比如像这样子&#xff1a;第一步&#xff1a;把起点放入OpenList第二步&#xff1a;找出OpenList中F值最小的方格&#xff0c;即唯一的方格Node(1,2)作为当前方格&#xff0c;并把当前格移出OpenList&#xff0c;放入CloseList。代表这个格子已到达并…

apache ignite_Kubernetes集群上的Apache Ignite和Spring第2部分:Kubernetes部署

apache ignite以前&#xff0c;我们已经成功创建了第一个由Apache Ignite支持的Spring boot Application。 在此博客上&#xff0c;我们将重点介绍Kubernetes方面需要做的事情&#xff0c;以便能够启动我们的应用程序。 如先前博客所述&#xff0c;我们需要制定我们的Kuberne…

漫画:什么是布隆算法

转载自 玻璃猫 程序员小灰两周之前——爬虫的原理就不细说了&#xff0c;无非是通过种子URL来顺藤摸瓜&#xff0c;爬取出网站关联的所有的子网页&#xff0c;存入自己的网页库当中。但是&#xff0c;这其中涉及到一个小小的问题......URL去重方案第一版&#xff1a;HashSet 创…

2016第11届四川省高校计算机(软件)院长论坛纪要(旁听)

​【0】README 0.1&#xff09;该论坛与16年4月8日在西南交大召开&#xff0c;为贺西南交大120周年华诞&#xff1b; 0.2&#xff09;以下内容是小生在该论坛上的部分旁听内容&#xff08;仅仅是部分&#xff09;&#xff0c; 感觉很新鲜&#xff0c;故分享之&#xff1b; 0…

selenium自动化测试_为什么在生产中进行Selenium自动化测试对于您的下一个版本至关重要?...

selenium自动化测试您是否认为仅仅是因为您的Web应用程序在过渡环境中以飞快的速度通过&#xff0c;它对于生产环境也将是相同的&#xff1f; 您可能需要重新考虑&#xff01; 特别是&#xff0c;如果我们指的是跨浏览器测试 &#xff0c;则需要确保跨各种操作系统&#xff0c…

java.lang.ExceptionInInitializerError的原因

【0】README 0.1&#xff09;本文转自 http://blog.csdn.net/fykhlp/article/details/6236316&#xff1b; 【1】正文如下 这个错误是说变量初始化出现问题&#xff0c;通常出现在静态变量尤其是单例模式。这种问题往往是初始化顺序不对造成的&#xff0c;下面举个简单的例子。…

漫画:Bitmap算法 整合版

转载自 玻璃猫 程序员小灰两个月之前——为满足用户标签的统计需求&#xff0c;小灰利用Mysql设计了如下的表结构&#xff0c;每一个维度的标签都对应着Mysql表的一列&#xff1a;要想统计所有90后的程序员该怎么做呢&#xff1f;用一条求交集的SQL语句即可&#xff1a;Select…

tomcat(3)连接器

【0】README0.1&#xff09;本文部分内容转自“深入剖析tomcat”&#xff0c;旨在学习 tomcat(3)连接器 的基础知识&#xff1b;0.2&#xff09;Catalina 中有两个主要的模块&#xff1a;连接器&#xff08;ServerSocket&#xff09; 和 容器&#xff08;Servlet容器&#xff0…

java正则表达式验证_如何在Java中验证电话号码(正则表达式+ Google libphonenumber)...

java正则表达式验证关于如何在不同国家&#xff08;例如美国&#xff0c;美国&#xff09;使用Java验证电话号码的快速指南。 带有正则表达式和Google libphonenumber API的示例程序。 1.简介 在本教程中&#xff0c;我们将学习如何在java中验证电话号码 。 这主要是为了验证美…