开始定位器/定位器,哪个用于客户端,哪个用于服务器?

时间:2018-08-02 18:05:11

标签: gemfire spring-data-gemfire

我一直在像下面的示例那样配置Pivotal 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),但是我用以下方法更改了设置器:

gemfireProperties.setProperty("start-locator", "localhost[1099]");

该应用程序正在运行,但是我不知道Spring是否创建了Locator或发生了什么。我想指向localhost[1099],用这种方式我不确定它是否正确。

我看到了很多示例,但是对于我来说还是不清楚哪个属性适用于客户端或服务器应用。

我正在使用spring-data-gemfire,宝石等来制作REST API ...

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:2)

Pivotal GemFire locatorsstart-locator属性仅由服务器使用。这两种属性均不适用于客户。

locators标识新成员将用来作为对等方加入的集群的定位器。它具有以下格式:host1[port1],host2[port2],...,hostN[portN]

start-locator用于在对等Cache [应用程序]节点或服务器中启动嵌入式定位器。在您的IDE中启动小型GemFire服务器群集(对等成员节点)时,此属性非常方便。

  

提示:通常,在独立的生产环境中,您要启动多个单独的专用Locator节点(JVM进程,通常在不同的主机上)以实现弹性。但是在开发过程中,使用start-locator属性很方便,尤其是在测试时。

您可以详细了解locatorsstart-locator属性here。您可以了解有关定位器的更多信息,尤其是成员发现herehere

所以,第一个问题是,为什么在这种情况下需要一个或多个定位器?

关于...

  

我需要放置一个定位器“ localhost [1099]”,但是当我放置一个:gemfireProperties.setProperty("locators", "localhost[1099]");时,我从Spring收到一条错误消息,提示找不到定位器(更具体的说是NULL)。

当您尚未启动定位器时就是这种情况。如果指定start-locator,则您的Spring(数据透视GemFire数据)对等Cache应用程序将在启动时嵌入定位器(服务),在这种情况下,您无需指定{{1} }属性,因为它将是多余的。

使用嵌入式定位器,您可以然后开始或让其他成员加入集群中的该成员。

例如,我经常使用这样的类来启动一个小的Pivotal GemFire集群,以进行开发,测试和演示……

locators

完整的源代码可用here

一些注意事项。

首先,@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注释几乎是同义词。它们都创建一个Spring Boot Pivotal GemFire对等@PeerCacheApplication应用程序节点(服务器)。唯一的区别是,Cache还添加了一个@CacheServerApplication,以允许基于GemFire ServerSocket的应用程序(即标有SDG ClientCache的Spring Boot应用程序)连接到服务器。 / p>

如您所见,我创建了一个内部静态@ClientClientApplication类。此类由LocatorManagerConfiguration@EnableLocator注释。 @EnableManager等效于@EnableLocator属性,并允许您控制嵌入式Locator服务在启动时将绑定到的NIC和端口。默认情况下,嵌入式定位器服务在绑定到默认定位器端口start-locator的“ localhost”上启动。

我添加了10334注释,还启动了基于GemFire JMX的管理服务,该服务允许 Gfsh 连接到我们的Spring Boot配置/引导的GemFire服务器。

我使用Spring概要文件(“ @EnableManager”)启用此Spring @Configuration类,以便只有一台服务器以嵌入式Locator / Manager开头。当然,我可能有多个服务器启动一个Locator和/或Manager,但是当侦听客户端连接时(例如,Manager侦听来自JMX客户端的连接),然后需要小心更改Locator和Manager服务使用的端口号。例如 Gfsh JConsole JVisualVM 等)。

那么,我们如何运行它?

好吧,假设我们要创建一个包含3个服务器的小型GemFire集群。在我的IDE中,我使用相同的locator-manager类创建3个不同的运行配置文件。第一次运行配置文件将从启用“ GeodeServerApplication” Spring配置文件开始,就像这样...

locator-manager

IDE中接下来的2个运行配置文件的设置如下...

-server -ea -Dspring.profiles.active=locator-manager -Dspring.data.gemfire.name=GeodeServerOne

唯一的区别是,对于我的上次运行配置文件,运行配置文件3,我需要为服务器命名不同的名称,例如“ -server -ea -Dspring.profiles.active=none -Dspring.data.gemfire.name=GeodeServerTwo -server -ea -Dspring.profiles.active=none -Dspring.data.gemfire.name=GeodeServerThree ”。 Pivotal GemFire希望集群中对等成员的名称是唯一的。

现在,从IDE中,我可以先启动启用了Locator / Manager的服务器,然后再运行最后2台未启用嵌入式Locator / Manager的服务器。然后,我可以使用 Gfsh 检查集群,如下所示:

GeodeServerThree

如果您还启用了这些Spring Boot,Pivotal GemFire对等$ 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 应用程序(通过将Cache注释替换为CacheServers)也成为@PeerCacheApplication,那么您将能够连接缓存客户端应用,类似于以下内容...

https://github.com/jxblum/contacts-application/blob/master/boot-example/src/main/java/example/app/geode/cache/client/BootExampleApplication.java

  

提示:@CacheServerApplication使用新的Spring Boot for Apache Geode/Pivotal GemFire(SBDG)项目,默认情况下,当{{ 1}}或BootExampleApplication位于应用程序的classpath上。有关更多详细信息,请参见docs。如果该项目未使用SBDG,则必须显式地使用SDG的ClientCache注释Spring Boot应用程序类。

有关更多详细信息,请阅读《 SDG参考指南》的chaptersection

无论如何,我希望这能为您提供这些属性的用途以及SDG注释功能的指导。还可以查看新的 Apache Geode / Pivotal GemFire 项目的Spring Boot(请参阅blog post),该项目在Spring Boot的自动配置中使用约定优于配置支持进一步简化客户端或服务器Apache Geode / Pivotal GemFire应用程序的配置和引导。

干杯, -约翰