我一直在配置关键的GemFire,如下例所示:
@Configuration
public class GemfireConfiguration {
@Bean
Properties gemfireProperties() {
Properties gemfireProperties = new Properties();
gemfireProperties.setProperty("name","SpringDataGemFireApplication");
gemfireProperties.setProperty("mcast-port", "0");
gemfireProperties.setProperty("log-level", "config");
return gemfireProperties;
}
@Bean
CacheFactoryBean gemfireCache() {
CacheFactoryBean gemfireCache = new CacheFactoryBean();
gemfireCache.setClose(true);
gemfireCache.setProperties(gemfireProperties());
return gemfireCache;
}
@Bean(name="employee")
LocalRegionFactoryBean<String, Employee> getEmployee(final GemFireCache cache) {
LocalRegionFactoryBean<String, Employee> employeeRegion = new LocalRegionFactoryBean();
employeeRegion.setCache(cache);
employeeRegion.setName("employee");
// ...
return employeeRegion;
}
}我需要放置一个定位器"localhost[1099]",但是当我放置一个:
gemfireProperties.setProperty("locators", "localhost[1099]");我从Spring中得到一个错误,说找不到定位器(更具体的是NULL),但我用以下方法更改了setter:
gemfireProperties.setProperty("start-locator", "localhost[1099]");该应用程序运行,但我不知道Spring是否创建了定位器或发生了什么。我想指出localhost[1099],用这种方式我不确定它是否正确。
我看到了许多例子,但我仍然不清楚哪个属性是用于客户端或服务器应用程序。
我正在用spring-data-gemfire、宝石等开发REST .
有人能帮我吗?
发布于 2018-08-02 23:35:31
关键的GemFire、locators和start-locator属性仅供服务器使用。这两种财产都不适用于客户。
locators标识集群的定位器,新成员将使用该定位器作为对等点进行连接。它有以下格式:host1[port1],host2[port2],...,hostN[portN]。
start-locator用于在对等Cache应用程序节点或服务器中启动嵌入式定位器。当您在IDE中启动一个小型GemFire服务器集群(对等成员节点)时,此属性非常方便。
提示:通常,在独立的生产环境中,您希望启动多个、独立的和专用的Locator节点(JVM进程,通常是在不同的主机上)以实现弹性。但是在开发过程中,使用
start-locator属性非常方便,特别是在测试时。
您可以阅读有关locators和start-locator属性这里的更多信息。您可以阅读更多关于定位器,特别是成员发现、这里和这里的信息。
那么,第一个问题,为什么在这种情况下需要一个或多个定位器?
关于..。
我需要放置一个定位器"localhost1099",但是当一个i put:
gemfireProperties.setProperty("locators", "localhost[1099]");从Spring中得到一个错误,说找不到这个定位器(更具体的是NULL),
如果您还没有启动定位器,就会出现这种情况。如果您指定了start-locator,那么您的Spring (关键GemFire的数据),对等Cache应用程序将在启动时嵌入一个Locator (服务),在这种情况下,您不需要指定locators属性,因为它将是冗余的。
使用嵌入式定位器,您可以启动或让其他成员在集群中加入该成员。
例如,我经常使用这样的类来启动一个小型的关键GemFire集群,用于开发、测试和演示.
@SpringBootApplication
//@CacheServerApplication(name = "ExampleServerApplication", locators = "localhost[10334]")
@PeerCacheApplication(name = "BookExampleServerApplication", locators = "localhost[10334]")
@EnablePdx(readSerialized = true)
@SuppressWarnings("unused")
public class GeodeServerApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(GeodeServerApplication.class)
.web(WebApplicationType.NONE)
.build()
.run(args);
}
@Profile("locator-manager")
@Configuration
@EnableLocator
@EnableManager(start = true)
static class LocatorManagerConfiguration { }
}完整的源代码是可用的这里。
有几件事要注意。
首先,@CacheServerApplication和@PeerCacheApplication注释几乎是同义词。它们都创建了一个Spring,关键的GemFire对等Cache应用程序节点(服务器)。唯一的区别是,@CacheServerApplication还添加了一个ServerSocket,允许基于GemFire ClientCache的应用程序(即用SDG的@ClientClientApplication注释的Spring应用程序)连接到服务器。
如您所见,我创建了一个内部的静态LocatorManagerConfiguration类。这个类使用@EnableLocator和@EnableManager进行注释。@EnableLocator等同于start-locator属性,允许您控制嵌入式Locator服务在启动时绑定到的NIC和端口。默认情况下,嵌入式Locator服务在绑定到默认Locator端口10334的“10334”上启动。
我添加了@EnableManager注释,以启动基于GemFire JMX的管理服务,该服务允许Gfsh连接到配置/引导的GemFire服务器。
我使用Spring ("locator-manager")启用这个Spring类,这样只有一个服务器以嵌入式Locator/Manager开始。当然,我可以让多台服务器启动一个Locator和/或Manager,但是在侦听客户端连接时,我需要小心地更改Locator和Manager服务使用的端口号(例如Manager侦听来自诸如Gfsh、JConsole或JVisualVM等JMX客户端的连接)。
那我们怎么处理这个?
那么,假设我们想要创建一个带有3台服务器的小型GemFire集群。在我的IDE中,我使用同一个GeodeServerApplication类创建了3个不同的运行配置文件。第一个运行配置文件将以启用"locator-manager“Spring配置文件开始,如下所示..。
-server -ea -Dspring.profiles.active=locator-manager -Dspring.data.gemfire.name=GeodeServerOne我的IDE中接下来的2个运行配置文件是这样设置的.
-server -ea -Dspring.profiles.active=none -Dspring.data.gemfire.name=GeodeServerTwo
-server -ea -Dspring.profiles.active=none -Dspring.data.gemfire.name=GeodeServerThree唯一的区别是,对于我上次运行的概要文件,运行概要文件3,我需要给服务器命名不同的名称,比如"GeodeServerThree“。Pivotal GemFire期望集群中的对等成员的名称是唯一的。
现在,在我的IDE中,我可以先启用Locator/Manager启动服务器,然后在不启用嵌入式Locator/Manager的情况下运行最后2个服务器。然后,我可以使用Gfsh检查集群,如下所示:
$ echo $GEODE_HOME
/Users/jblum/pivdev/apache-geode-1.2.1
$ gfsh
_________________________ __
/ _____/ ______/ ______/ /____/ /
/ / __/ /___ /_____ / _____ /
/ /__/ / ____/ _____/ / / / /
/______/_/ /______/_/ /_/ 1.2.1
Monitor and Manage Apache Geode
gfsh>connect
Connecting to Locator at [host=localhost, port=10334] ..
Connecting to Manager at [host=10.0.0.121, port=1099] ..
Successfully connected to: [host=10.0.0.121, port=1099]
gfsh>list members
Name | Id
---------------- | ---------------------------------------------
GeodeServerOne | 10.0.0.121(GeodeServerOne:42883)<ec><v0>:1024
GeodeServerTwo | 10.0.0.121(GeodeServerTwo:42911)<v1>:1025
GeodeServerThree | 10.0.0.121(GeodeServerThree:42913)<v2>:1026如果您已经启用了这些Spring (关键的GemFire对等Cache应用程序也是CacheServers )(通过用@CacheServerApplication替换@PeerCacheApplication注释),那么您将能够连接缓存客户端应用程序,类似于以下.
提示:
BootExampleApplication正在使用新的https://github.com/spring-projects/spring-boot-data-geode (SBDG)项目,默认情况下,当spring-geode-starter或spring-gemfire-starter在应用程序的类路径上时,该项目会自动配置ClientCache实例。有关其他详细信息,请参阅文档。如果这个项目没有使用SBDG,那么您必须显式地用SDG的@ClientCacheApplication注释Spring应用程序类。
无论如何,我希望这能为您提供一些指导,说明这些属性的用途以及SDG注释的功能。还请看一下新的Apache /Pivotal项目(参见博客帖子),该项目使用了对Spring的自动配置支持的约定而不是配置,以进一步简化客户端或服务器Apache /枢轴GemFire应用程序的配置和引导。
干杯,-John
https://stackoverflow.com/questions/51659771
复制相似问题