简体   繁体   English

使用Spring Data Gemfire时的@Region注释

[英]@Region annotation when using Spring Data Gemfire

I am developing a data service using Spring Data and Gemfire. 我正在使用Spring Data和Gemfire开发数据服务。 There is an annotation 有一个注释

@Region("<region name>")

to specify which Gemfire region the POJO is going to be stored in. 指定POJO将存储在哪个Gemfire区域。

It requires the name of the configured Gemfire region. 它需要配置的Gemfire区域的名称。 I feel like hard-coding the name of the region is a bad practice, since the Gemfire cluster is going to be managed by a separate team and I believe the region name should be totally configurable. 我觉得硬编码区域的名称是一种不好的做法,因为Gemfire集群将由一个单独的团队管理,我相信区域名称应该是完全可配置的。

Is there any better practice to avoid hard coding the region name? 有没有更好的做法来避免对区域名称进行硬编码?

The region name must be shared by all processes that access the region. 区域名称必须由访问该区域的所有进程共享。 This is analogous to a table name in a relational database. 这类似于关系数据库中的表名。 In this sense, it is no different than JPA or Hibernate annotations that declare the table name in which the POJO will be stored. 从这个意义上说,它与JPA或Hibernate注释没有区别,它们声明了将存储POJO的表名。 IIRC, using Spring Data Repositories, if @Region is not present it will get it from the class name. IIRC,使用Spring Data Repositories,如果@Region不存在,它将从类名中获取它。 But either way, the corresponding region must exist. 但不管怎样,相应的区域必须存在。 If your application is a client to the GemFire grid, you must also configure a client region with the same name as the corresponding region on the server. 如果您的应用程序是GemFire网格的客户端,则还必须配置与服务器上相应区域同名的客户端区域。 If it's a peer than you must create the region (either a partition or a replica). 如果它是对等体,则必须创建区域(分区或副本)。 These things may be done with Spring configuration or native GemFire configuration, but in any event, the shared region name must be known in advance and if it changes, it must change everywhere. 这些事情可以通过Spring配置或本机GemFire配置来完成,但无论如何,共享区域名称必须事先知道,如果它发生变化,它必须在任何地方都改变。

Could you use Spring Expression Language to inject the name of the Region? 你能用Spring Expression Language来注入Region的名字吗?

We inject a value from a config bean, which itself is based on an XML file, into a @Value annotation eg: 我们从配置bean(它本身基于XML文件)注入一个值到@Value注释中,例如:

@Value("#{config.dataSourceConfig.dbMainUsername}")

Where "config" is the name of the config bean. 其中“config”是配置bean的名称。

Not sure is this works with all annotations tho... 不确定这适用于所有注释......

In general, I do not think it is necessarily bad practice to specify the Region's name/path in the @Region annotation on the application domain object; 一般来说,我认为在应用程序域对象的@Region注释中指定Region的名称/路径并不一定是不好的做法。 it is certainly a lot more explicit. 它肯定更明确。

However, I can understand the need to make such things configurable, perhaps as you promote from 1 env (eg DEV) to another (eg PROD). 但是,我可以理解需要使这些事情可配置,也许当你从1 env(例如DEV)升级到另一个(例如PROD)时。 As such, see the recent change... 因此,请参阅最近的变化......

SGF-261 - allowing an application domain object/entity to be persisted to multiple Regions in a GemFire Cache SGF-261 - 允许应用程序域对象/实体持久保存到GemFire Cache中的多个区域

As well as this proposed, future change... 以及这个提议,未来的变化......

SGF-262 . SGF-262

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM