Start-Locator/定位器,哪个用于客户端,哪个用于服务器? [英] Start-Locator / Locators, which is for client and which is for server?

查看:124
本文介绍了Start-Locator/定位器,哪个用于客户端,哪个用于服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在像下面的示例那样配置Pivotal GemFire:

I have been configuring Pivotal GemFire like this example:

@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]",但是当我放置一个时:

I need to put a Locator "localhost[1099]", but when a I put:

gemfireProperties.setProperty("locators", "localhost[1099]");

我从Spring收到一条错误消息,说找不到定位器(更具体的是NULL),但是我用以下方法更改了设置器:

I get an error from Spring saying that the Locator could not be found (more specific is NULL), but I change the setter with:

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

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

The app runs but I don't know if Spring creates the Locator or what happens. I want to point to localhost[1099] and with this way I am not sure if it is correct.

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

I saw many examples but it is still not clear to me which property is for client or server app.

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

I am working on a REST API with spring-data-gemfire, gemstone, etc...

有人可以帮我吗?

推荐答案

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

The Pivotal GemFire locators and start-locator properties are used by servers only. Neither property applies to clients.

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

locators identifies the Locator(s) of the cluster that the new member will use to join as a peer. It has the following format: host1[port1],host2[port2],...,hostN[portN].

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

start-locator is used to start an embedded Locator in a peer Cache [application] node or server. This property is highly convenient when starting a small cluster of GemFire servers (peer member nodes) inside your IDE.

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

TIP: Typically, in standalone, production environment, you want to startup multiple, separate and dedicated Locator nodes (JVM processes, and usually on different hosts) for resiliency. But during development, using the start-locator property is convenient, especially when testing.

您可以阅读有关locatorsstart-locator属性的更多信息此处此处.

You can read more about the locators and start-locator properties here. You can read more about Locators, and specifically member discovery, here and here.

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

So, first question, why do you need a Locator or Locators in this instance?

关于...

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

I need to put a Locator "localhost[1099]", but when a I put: gemfireProperties.setProperty("locators", "localhost[1099]"); I get an error from Spring saying that the Locator could not be found (more specific is NULL), ...

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

This will be the case when you have not started a Locator. If you specify start-locator then your Spring (Data for Pivotal GemFire), peer Cache application will embed a Locator (service) on startup, in which case, you do not need to specify the locators property since it would be redundant.

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

With an embedded Locator, you can then start, or have other members join this member in a cluster.

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

For example, I often use classes like this to start a small Pivotal GemFire cluster for development, testing and demonstration purposes...

@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 Boot Pivotal GemFire对等Cache应用程序节点(服务器).唯一的区别是,@CacheServerApplication另外添加了ServerSocket,以允许基于GemFire ClientCache的应用程序(即带有SDG @ClientClientApplication注释的Spring Boot应用程序)连接到服务器.

First, the @CacheServerApplication and @PeerCacheApplication annotations are nearly synonymous. They both create a Spring Boot, Pivotal GemFire peer Cache application node (server). The only difference is, the @CacheServerApplication additionally adds a ServerSocket allowing GemFire ClientCache based applications (i.e. a Spring Boot application annotated with SDG's @ClientClientApplication) to connect to the server.

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

As you can see, I have created an inner, static LocatorManagerConfiguration class. This class is annotated with @EnableLocator and @EnableManager. @EnableLocator is equivalent to the start-locator property and allows you to control the NIC and port to which the embedded Locator service will bind to on startup. By default, the embedded Locator service startups up on "localhost" bound to the default Locator port 10334.

我添加了@EnableManager批注以启动基于GemFire JMX的管理服务,该服务允许 Gfsh 连接到我们的Spring Boot配置/引导的GemFire服务器.

I added the @EnableManager annotation to also start the GemFire JMX-based Management service, which allows Gfsh to connect to our Spring Boot configured/bootstrapped GemFire server.

我使用Spring概要文件("locator-manager")启用此Spring @Configuration类,以便只有一台服务器以嵌入式定位器/管理器启动.当然,我可以让多个服务器启动一个Locator和/或Manager,但是随后在侦听客户端连接时(例如Manager侦听来自JMX客户端的连接)时,我需要小心更改Locator和Manager服务使用的端口号.例如 Gfsh JConsole JVisualVM 等).

I enable this Spring @Configuration class with a Spring Profile ("locator-manager") so that only 1 of the servers starts with the embedded Locator/Manager. Of course, I could have multiple servers start a Locator and/or Manager, but I then need to be careful to vary the port numbers used by the Locator and Manager services when listening for client connections (e.g. the Manager listens for connections from JMX clients like Gfsh, or JConsole, or JVisualVM, etc).

那么,我们如何运行它?

So, how do we run this?

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

Well, let's say we want to create a small GemFire cluster with 3 servers. In my IDE, I create 3 different run profiles using the same GeodeServerApplication class. The first run profile will start with the "locator-manager" Spring profile enabled, like so...

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

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

The next 2 run profiles in my IDE are setup like so...

-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希望集群中对等成员的名称是唯一的.

The only difference is, for my last run profile, run profile 3, I need to name the server something different, like "GeodeServerThree". Pivotal GemFire expects the names of the peer members in the cluster to be unique.

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

Now, from my IDE, I can start the server with the Locator/Manager enabled first, and then run the last 2 servers without the embedded Locator/Manager enabled, next. Then, I can inspect my cluster using Gfsh, as follows:

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

If you had enabled these Spring Boot, Pivotal GemFire peer Cache applications to be CacheServers as well (by replacing the @PeerCacheApplication annotation with @CacheServerApplication), then you would be able to connect a cache client app, similar to the following...

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

提示:BootExampleApplication正在使用新的 Spring Boot适用于Apache Geode/Pivotal GemFire (SBDG)项目,默认情况下spring-geode-starterspring-gemfire-starter 自动配置 ClientCache实例,位于应用程序的类路径.参见 docs 了解更多详细信息.如果该项目未使用SBDG,则必须显式地使用SDG的@ClientCacheApplication注释Spring Boot应用程序类.

TIP: The BootExampleApplication is using the new Spring Boot for Apache Geode/Pivotal GemFire (SBDG) project which auto-configures a ClientCache instance, by default, when either spring-geode-starter or, alternatively, spring-gemfire-starter, is on your application's classpath. See the docs for additional details. If this project were not using SBDG, then you would explicitly have to annotate your Spring Boot application class with SDG's @ClientCacheApplication.

阅读此 部分.

无论如何,我希望这能为您提供这些属性的用途以及SDG注释功能的指导.还可以查看用于Apache Geode/Pivotal GemFire 的新 Spring Boot(请参阅

Anyway, I hope this gives you some guidance into what these properties are for and the power of SDG's annotations. Also have a look at the new Spring Boot for Apache Geode/Pivotal GemFire project (see blog post), which uses convention over configuration with Spring Boot's auto-configuration support to simplify configuring and bootstrapping either client or server Apache Geode/Pivotal GemFire applications further.

干杯, -约翰

这篇关于Start-Locator/定位器,哪个用于客户端,哪个用于服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆