Spring认证中国教育管理中心-Apache Geode的Spring数据教程十七
发布于 2 年前 作者 lei00 4841 次浏览 来自 分享

原标题:Spring认证中国教育管理中心-Apache Geode 的 Spring 数据教程十七(Spring中国教育管理中心)

Spring认证中国教育管理中心-Apache Geode 的 Spring 数据教程十七
6.20.16。从集群定义的区域配置客户端区域
或者,您可以使用 定义从集群中已定义的区域中定义客户端 [*PROXY] 区域@
EnableClusterDefinedRegions,如下所示:

@SpringBootApplication
@ClientCacheApplication
@EnableClusterDefinedRegions
@EnableGemfireRepositories
public class ClientApplication {

public static void main(String[] args) {
SpringApplication.run(ClientApplication.class, args);
}


}
6.20.17。配置功能
Apache Geode Functions 在分布式计算场景中很有用,在这种场景中,需要数据的潜在昂贵计算可以跨集群中的节点并行执行。在这种情况下,将逻辑带到数据所在(存储)的位置比请求和获取要由计算处理的数据更有效。

使用@EnableGemfireFunctions@GemfireFunction注释来启用作为 POJO 方法实现的 Apache Geode Functions 定义,如下所示:

@PeerCacheApplication
@EnableGemfireFunctions
class ServerApplication {

public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}

@GemfireFunction
Integer computeLoyaltyPoints(Customer customer) {

}
}
使用@
EnableGemfireFunctionExecutions与函数调用注解1一起:@OnMember@OnMembers@OnRegion@OnServer@OnServers

@ClientCacheApplication
@EnableGemfireFunctionExecutions(basePackageClasses = CustomerRewardsFunction.class)
class ClientApplication {

public static void main(String[] args) {
SpringApplication.run(ClientApplication.class, args);
}
}

@OnRegion(“Customers”)
interface CustomerRewardsFunctions {

Integer computeLoyaltyPoints(Customer customer);

}
请参阅@
EnableGemfireFunctionsJavadoc。

@target(值= TYPE)
@Retention(值= RUNTIME)
@Inherited
@Documented
@Import(值= GemfireFunctionBeanPostProcessorRegistrar.class)
公共@interface EnableGemfireFunctions
启用 GemFire 注释函数实现。使容器发现任何用 {code}@GemfireFunction{code} 注释的 bean,将它们包装在 中PojoFunctionWrapper,并将它们注册到缓存中。

请参阅@GemfireFunctionJavadoc

@Retention ( value = RUNTIME )
@Target ( value = METHOD )
公共@interface GemfireFunction
用于将具体方法声明为 GemFire 函数实现

请参阅@
EnableGemfireFunctionExecutionsJavadoc。

@Target ( value = TYPE )
@Retention ( value = RUNTIME )
@Documented
@Inherited
@Import ( value = FunctionExecutionBeanDefinitionRegistrar.class )
公共@interface EnableGemfireFunctionExecutions
为注释为 GemFire 函数执行(函数调用)的接口启用类路径扫描。这些包括用 {code} @OnRegion@OnServer@OnServers@OnMember@OnMembers{code} 之一注释的接口

请参阅@OnMemberJavadoc@OnMembersJavadoc@OnRegionJavadoc@OnServerJavadoc@OnServersJavadoc

@Retention ( value = RUNTIME )
@Target ( value = TYPE )
公共@interface OnMember
将接口声明为 GemFire OnMember 函数执行的注释

@Retention ( value = RUNTIME )
@Target ( value = TYPE )
公共@interface OnMembers
将接口声明为 GemFire OnMembers 函数执行的注释

@Retention ( value = RUNTIME )
@Target ( value = TYPE )
公共@interface OnRegion
将接口声明为 GemFire OnRegion 函数执行的注释

@Retention ( value = RUNTIME )
@Target ( value = TYPE )
公共@interface OnServer
将接口声明为 GemFire OnServer 函数执行的注释

@Retention ( value = RUNTIME )
@Target ( value = TYPE )
公共@interface OnServers
将接口声明为 GemFire OnServers 函数执行的注释

6.20.18。配置连续查询
实时事件流处理正成为数据密集型应用程序越来越重要的任务,主要是为了及时响应用户请求。Apache Geode Continuous Query (CQ) 将帮助您轻松完成这项相当复杂的任务。

通过@EnableContinuousQueries使用相关联的事件处理程序注释您的应用程序类并定义您的CQ 来启用 CQ ,如下所示:

@ClientCacheApplication
@EnableContinuousQueries
class ClientApplication {

public static void main(String[] args) {
SpringApplication.run(ClientApplication.class, args);
}
}
然后,通过使用 注释关联的处理程序方法来定义您的 CQ @ContinousQuery,如下所示:

@Service
class CustomerService {

@ContinuousQuery(name = “CustomerQuery”, query = “SELECT * FROM /Customers c WHERE …”)
public void process(CqEvent event) {

}
}
每当发生更改Customer数据以匹配连续 OQL 查询 (CQ) 中的谓词的事件时,process都会调用该方法。

Apache Geode CQ 只是一个客户端特性。

请参阅@
EnableContinuousQueriesJavadoc。

@Target ( value = TYPE )
@Retention ( value = RUNTIME )
@Inherited
@Documented
@Import ( value = ContinuousQueryConfiguration.class )
公共@interface EnableContinuousQueries
该EnableContinuousQueries注释标记了一个带有 Spring@Configuration注释的应用程序配置类,以启用 Pivotal GemFire / Apache Geode 连续查询 (CQ) 功能。

请参阅@ContinuousQueryJavadoc

@Target ( value = METHOD )
@Retention ( value = RUNTIME )
@Inherited
@Documented
public @interface ContinuousQuery
在ContinuousQuery处理所有 CQ 事件和错误的 POJO 方法上定义 GemFire/Geode 连续查询 (CQ)的注释。

6.20.19。配置集群配置
当使用 Apache Geode 作为 Apache GeodeClientCache应用程序开发 Spring Data 应用程序时,在开发期间配置服务器以匹配客户端/服务器拓扑中的客户端很有用。事实上,Apache Geode 期望当您Region在客户端上有一个“/Example”代理时,服务器中存在一个匹配Region的名称(即“Example”)。

您可以使用Gfsh创建您的应用程序需要的每个区域和索引,或者,您可以在运行时简单地推送在使用 Apache Geode 开发 Spring Data 应用程序时已经表达的配置元数据。

这就像注释您的主应用程序类一样简单@
EnableClusterConfiguration(…):

使用 @
EnableClusterConfiguration

@ClientCacheApplication
@EnableClusterConfiguration(useHttp = true)
class ClientApplication {

}
大多数时候,当使用客户端/服务器拓扑时,特别是在生产环境中,集群的服务器将使用Gfsh启动。在这种情况下,习惯上使用 HTTP(S) 将配置元数据(例如区域和索引定义)发送到集群。当使用 HTTP 时,配置元数据被发送到集群中的 Manager 并一致地分布在集群中的服务器节点上。

为了使用,@
EnableClusterConfiguration您必须org.springframework:spring-web在 Spring 应用程序类路径中声明依赖项。

请参阅@
EnableClusterConfigurationJavadoc。

@Target ( value = TYPE )
@Retention ( value = RUNTIME )
@Inherited
@Documented
@Import ( value = ClusterConfigurationConfiguration.class )
公共@interface EnableClusterConfiguration

EnableClusterConfiguration注释使 Spring [Boot] 中定义的 Apache Geode / Pivotal GemFire 模式对象定义、ClientCache使用 Spring 配置的Apache Geode / Pivotal GemFire应用程序能够推送到 Apache Geode / Pivotal GemFire 集群,类似于模式命令(例如create region) 在 Gfsh 中由 Apache Geode / Pivotal GemFire 管理器处理。

6.20.20。配置GatewayReceivers
不同 Apache Geode 集群之间的数据复制是一种越来越重要的容错和高可用性 (HA) 机制。Apache Geode WAN 复制是一种机制,允许一个 Apache Geode 集群以可靠且容错的方式将其数据复制到另一个 Apache Geode 集群。

Apache Geode WAN 复制需要配置两个组件:

GatewayReceiver- 从远程 Apache Geode 集群的GatewaySender.
GatewaySender- 将数据发送到远程 Apache Geode 集群的GatewayReceiver.
要启用 a GatewayReceiver,需要对应用程序类进行@EnableGatewayReceiver如下注释:

@CacheServerApplication
@EnableGatewayReceiver(manualStart = false, startPort = 10000, endPort = 11000, maximumTimeBetweenPings = 1000,
socketBufferSize = 16384, bindAddress = “localhost”,transportFilters = {“transportBean1”, “transportBean2”},
hostnameForSenders = “hostnameLocalhost”){


}
}
class MySpringApplication { … }
Apache GeodeGatewayReceiver只是一个服务器端特性,只能在一个CacheServer 或对等Cache节点上配置。

6.20.21。配置GatewaySenders
要启用GatewaySender,应用程序类需要使用@EnableGatewaySenders 和进行注释,@EnableGatewaySender如下所示:

@CacheServerApplication
@EnableGatewaySenders(gatewaySenders = {
@EnableGatewaySender(name = “GatewaySender”, manualStart = true,
remoteDistributedSystemId = 2, diskSynchronous = true, batchConflationEnabled = true,
parallel = true, persistent = false,diskStoreReference = “someDiskStore”,
orderPolicy = OrderPolicyType.PARTITION, alertThreshold = 1234, batchSize = 100,
eventFilters = “SomeEventFilter”, batchTimeInterval = 2000, dispatcherThreads = 22,
maximumQueueMemory = 400,socketBufferSize = 16384,
socketReadTimeout = 4000, regions = { “Region1”}),
@EnableGatewaySender(name = “GatewaySender2”, manualStart = true,
remoteDistributedSystemId = 2, diskSynchronous = true, batchConflationEnabled = true,
parallel = true, persistent = false, diskStoreReference = “someDiskStore”,
orderPolicy = OrderPolicyType.PARTITION, alertThreshold = 1234, batchSize = 100,
eventFilters = “SomeEventFilter”, batchTimeInterval = 2000, dispatcherThreads = 22,
maximumQueueMemory = 400, socketBufferSize = 16384,socketReadTimeout = 4000,
regions = { “Region2” })
}){
class MySpringApplication { … }
}
Apache GeodeGatewaySender只是一个服务器端特性,只能在一个CacheServer 或一个对等Cache节点上配置。

在上面的例子中,应用程序配置了 2 个区域,Region1和Region2. 此外,GatewaySenders将配置两个为两个区域提供服务。GatewaySender1将被配置为复制 Region1’s data and GatewaySender2将被配置为复制Region2 的数据。

正如演示的那样,GatewaySender可以在每个EnableGatewaySender注释上配置每个属性。

还可以使用更通用的“默认”属性方法,其中所有属性都在EnableGatewaySenders注释上配置。这样,可以在父注释上设置一组通用的默认值,然后根据需要在子注释上覆盖,如下所示:

@CacheServerApplication
@EnableGatewaySenders(gatewaySenders = {
@EnableGatewaySender(name = “GatewaySender”, transportFilters = “transportBean1”, regions = “Region2”),
@EnableGatewaySender(name = “GatewaySender2”)},
manualStart = true, remoteDistributedSystemId = 2,
diskSynchronous = false, batchConflationEnabled = true, parallel = true, persistent = true,
diskStoreReference = “someDiskStore”, orderPolicy = OrderPolicyType.PARTITION, alertThreshold = 1234, batchSize = 1002,
eventFilters = “SomeEventFilter”, batchTimeInterval = 2000, dispatcherThreads = 22, maximumQueueMemory = 400,
socketBufferSize = 16384, socketReadTimeout = 4000, regions = { “Region1”, “Region2” },
transportFilters = { “transportBean2”, “transportBean1” })
class MySpringApplication { … }
当regions属性为空或未填充时,GatewaySender(s) 将自动附加到Region应用程序中的每个配置。

回到顶部