关于spring:Spring认证中国教育管理中心Apache-Geode-的-Spring-数据教程十七

2次阅读

共计 7544 个字符,预计需要花费 19 分钟才能阅读完成。

原题目: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 应用程序中的每个配置。

正文完
 0