Spring认证中国教育管理中心-Apache Geode 的 Spring 数据教程一

简介: Spring认证中国教育管理中心-Apache Geode 的 Spring 数据教程一
  1. 文档结构

以下章节解释了 Spring Data 为 Apache Geode 提供的核心功能:

Bootstrapping Apache Geode with the Spring Container描述了为配置、初始化和访问 Apache Geode 缓存、区域和相关分布式系统组件提供的配置支持。
使用 Apache Geode API解释了 Apache Geode API 与 Spring 中可用的各种数据访问功能之间的集成,例如基于模板的数据访问、异常转换、事务管理和缓存。
使用 Apache Geode 序列化描述了对 Apache Geode 的托管对象序列化和反序列化的增强。
POJO 映射描述了使用 Spring Data 存储在 Apache Geode 中的 POJO 的持久性映射。
Spring Data for Apache Geode Repositories描述了如何通过使用基本的 CRUD 和简单的查询操作来创建和使用 Spring Data Repositories 来访问存储在 Apache Geode 中的数据。
函数执行的注释支持描述了如何通过使用注释来执行数据所在的分布式计算来创建和使用 Apache Geode 函数。
连续查询 (CQ)描述了如何使用 Apache Geode 的连续查询 (CQ) 功能来处理基于兴趣的事件流,该兴趣使用 Apache Geode 的 OQL(对象查询语言)定义和注册。
在 Apache Geode中引导 Spring ApplicationContext描述了如何ApplicationContext 使用Gfsh.
示例应用程序描述了随发行版提供的示例,以说明 Spring Data for Apache Geode 中可用的各种功能。

  1. 使用 Spring 容器引导 Apache Geode

Spring Data for Apache Geode 使用 Spring IoC 容器提供了 Apache Geode In-Memory Data Grid (IMDG) 的完整配置和初始化。该框架包括几个类来帮助简化 Apache Geode 组件的配置,包括:缓存、区域、索引、磁盘存储、函数、WAN 网关、持久性备份和其他几个分布式系统组件,以最少的工作支持各种应用程序用例.

本节假设您基本熟悉 Apache Geode。有关更多信息,请参阅 Apache Geode 产品文档。

5.1.使用 Spring 而不是 Apache Geode 的优势cache.xml
Spring Data for Apache Geode 的 XML 命名空间支持 Apache Geode In-Memory Data Grid (IMDG) 的完整配置。XML 命名空间是在 Spring 上下文中配置 Apache Geode 以在 Spring 容器内正确管理 Apache Geode 生命周期的两种方法之一。在 Spring 上下文中配置 Apache Geode 的另一种方法是使用基于注解的配置。

虽然cache.xml由于遗留原因仍然支持 Apache Geode 的本机,但鼓励使用 XML 配置的 Apache Geode 应用程序开发人员在 Spring XML 中做所有事情,以利用 Spring 提供的许多美妙的东西,例如模块化 XML 配置、属性占位符和覆盖、SpEL(Spring 表达式语言)和环境配置文件。在 XML 命名空间的背后,Spring Data for Apache Geode 广泛使用 Spring 的FactoryBean模式来简化 Apache Geode 组件的创建、配置和初始化。

阿帕奇的Geode提供了几个回调接口,如CacheListener,CacheLoader和CacheWriter,这让开发人员添加自定义事件处理程序。使用 Spring 的 IoC 容器,您可以将这些回调配置为普通的 Spring bean,并将它们注入到 Apache Geode 组件中。这是对 native 的重大改进cache.xml,它提供了相对有限的配置选项,并且需要回调来实现 Apache Geode 的Declarable接口(请参阅Wiring DeclarableComponents以了解如何仍然可以Declarables 在 Spring 的容器中使用)。

此外,诸如 Spring Tool Suite (STS) 之类的 IDE 为 Spring XML 命名空间提供了出色的支持,包括代码完成、弹出注释和实时验证。

5.2.使用核心命名空间
为了简化配置,Spring Data for Apache Geode 提供了一个专用的 XML 命名空间来配置核心 Apache Geode 组件。可以使用 Spring 的标准定义直接配置 bean 。但是,所有 bean 属性都通过 XML 名称空间公开,因此使用原始 bean 定义几乎没有好处。

有关 Spring 中基于 XML Schema 的配置的更多信息,请参阅Spring Framework 参考文档中的 附录。

Spring Data Repository 支持使用单独的 XML 命名空间。有关如何为 Apache Geode Repositories 配置 Spring Data 的更多信息,请参阅Spring Data for Apache Geode Repositories。

要使用 Spring Data for Apache Geode XML 命名空间,请在 Spring XML 配置元数据中声明它,如以下示例所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

   xmlns:gfe="https://www.springframework.org/schema/geode" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
https://www.springframework.org/schema/geode https://www.springframework.org/schema/geode/spring-geode.xsd 

">

<gfe:cache ...>


pring Data for Apache Geode XML 命名空间前缀。任何名称都可以使用,但在本参考文档gfe中使用了所有名称。

XML 命名空间前缀映射到 URI。

XML 命名空间 URI 位置。请注意,即使该位置指向外部地址(确实存在且有效),Spring 也会在本地解析模式,因为它包含在 Spring Data for Apache Geode 库中。

使用带有gfe前缀的 XML 命名空间的示例声明。

您可以将默认命名空间从 更改beans为gfe。这对于主要由 Apache Geode 组件组成的 XML 配置很有用,因为它避免了声明前缀。为此,请交换前面显示的命名空间前缀声明,如以下示例所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://www.springframework.org/schema/geode"

   xmlns:beans="http://www.springframework.org/schema/beans" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
https://www.springframework.org/schema/geode https://www.springframework.org/schema/geode/spring-geode.xsd

">

<beans:bean id ... >


此 XML 文档的默认命名空间声明指向 Spring Data for Apache Geode XML 命名空间。

beansSpring 原始 bean 定义的命名空间前缀声明。

使用beans命名空间的Bean 声明。注意前缀。

使用gfe命名空间的Bean 声明。请注意缺少前缀,因为gfe它是默认命名空间。

Spring认证中国教育管理中心-Apache Geode 的 Spring 数据教程一
5.3.使用数据访问命名空间
除了核心 XML 命名空间 ( gfe) 之外,Spring Data for Apache Geode 还提供了数据访问 XML 命名空间 ( gfe-data),主要用于简化 Apache Geode 客户端应用程序的开发。此命名空间当前包含对 Apache Geode Repositories和 Function execution 的支持,以及提供连接到 Apache Geode 集群的便捷方式的标签。

5.3.1.连接到 Apache Geode 的简单方法
对于许多应用程序,使用默认值与 Apache Geode 数据网格的基本连接就足够了。Spring Data for Apache Geode 的标签提供了一种访问数据的简单方法。数据源创建一个ClientCache 和连接Pool。此外,它会查询所有现有根区域的集群服务器,并为每个区域创建一个(空)客户端区域代理。

<gfe-data:datasource>

</gfe-data:datasource>
该标签在语法上类似于<gfe:pool>。它可以配置一个或多个嵌套locator 或server元素以连接到现有数据网格。此外,支持可用于配置池的所有属性。此配置为连接到 Locator 的集群成员上定义的每个 Region 自动创建客户端 Region bean,因此它们可以被 Spring Data 映射注释 ( GemfireTemplate)无缝引用并自动装配到应用程序类中。

当然,您可以显式配置客户端区域。例如,如果要将数据缓存在本地内存中,如下例所示:

<gfe-data:datasource>

</gfe-data:datasource>

<gfe:client-region id="Example" shortcut="CACHING_PROXY"/>

相关文章
|
1月前
|
存储 缓存 分布式计算
Apache Hudi数据跳过技术加速查询高达50倍
Apache Hudi数据跳过技术加速查询高达50倍
38 2
|
1月前
|
分布式计算 测试技术 Apache
如何不加锁地将数据并发写入Apache Hudi?
如何不加锁地将数据并发写入Apache Hudi?
32 0
|
11天前
|
安全 数据安全/隐私保护
Springboot+Spring security +jwt认证+动态授权
Springboot+Spring security +jwt认证+动态授权
|
1月前
|
监控 NoSQL Java
Spring Boot集成Redis启动失败【Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.impl.G】
Spring Boot集成Redis启动失败【Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.impl.G】
|
1月前
|
Apache 开发者
揭秘!Apache Hudi社区发展数据盘点
揭秘!Apache Hudi社区发展数据盘点
30 0
|
1月前
|
分布式计算 Java 数据管理
使用Apache Hudi + Amazon EMR进行变化数据捕获(CDC)
使用Apache Hudi + Amazon EMR进行变化数据捕获(CDC)
87 0
|
1月前
|
分布式计算 大数据 测试技术
查询时间降低60%!Apache Hudi数据布局黑科技了解下
查询时间降低60%!Apache Hudi数据布局黑科技了解下
22 0
|
1月前
|
分布式计算 测试技术 Apache
如何将数据更快导入Apache Hudi?
如何将数据更快导入Apache Hudi?
28 0
|
1月前
|
消息中间件 分布式计算 Kafka
硬核!Apache Hudi中自定义序列化和数据写入逻辑
硬核!Apache Hudi中自定义序列化和数据写入逻辑
30 1
|
1月前
|
存储 数据采集 Apache
众安保险 CDP 平台:借助阿里云数据库 SelectDB 版内核 Apache Doris 打破数据孤岛,人群圈选提速4倍
随着业务在金融、保险和商城领域的不断扩展,众安保险建设 CDP 平台以提供自动化营销数据支持。早期 CDP 平台依赖于 Spark + Impala + Hbase + Nebula 复杂的技术组合,这不仅导致数据分析形成数据孤岛,还带来高昂的管理及维护成本。为解决该问题,众安保险引入 Apache Doris,替换了早期复杂的技术组合,不仅降低了系统的复杂性,打破了数据孤岛,更提升了数据处理的效率。
众安保险 CDP 平台:借助阿里云数据库 SelectDB 版内核 Apache Doris 打破数据孤岛,人群圈选提速4倍

热门文章

最新文章

推荐镜像

更多