简体   繁体   English

在没有定位器运行的情况下启动spring-data-gemfire

[英]Startup of spring-data-gemfire without locator running yet

We have a big web application in Java which uses Gemfire and spring-data-gemfire. 我们在Java中有一个使用Gemfire和spring-data-gemfire的大型Web应用程序。 We run gemfire in a client server configuration. 我们在客户端服务器配置中运行gemfire。

We have the following problem: During startup, in the bean wiring phase, spring-data-gemfire wants to connect to the locator of gemfire. 我们遇到以下问题:在启动期间,在bean连接阶段,spring-data-gemfire想要连接到gemfire的定位器。 However, the locator may not be up yet. 但是,定位器可能尚未启动。 The application will then throw a com.gemstone.gemfire.cache.NoSubscriptionServersAvailableException: Primary discovery failed exception. 然后,应用程序将抛出com.gemstone.gemfire.cache.NoSubscriptionServersAvailableException: Primary discovery failed异常。

This causes a slow and fragile startup procedure of our services, which is inconvenient, especially during our automated tests. 这导致我们的服务启动过程缓慢且脆弱,这是不方便的,尤其是在我们的自动化测试期间。

Is there any good solution to have the client wait and periodically poll until the locator is running? 是否有任何好的解决方案让客户端等待并定期轮询直到定位器运行?

As Jens D comments, you can try the locator-wait-time GemFire (System) property. 正如Jens D评论的那样,您可以尝试locator-wait-time GemFire(系统)属性。 However, as the documentation points out... 但是,正如文件指出的......

The number of seconds that a member should wait for a locator to start if a locator is not available when attempting to join the distributed system. 尝试加入分布式系统时,如果定位器不可用,成员应等待定位器启动的秒数。 Use this setting when you are starting locators and peers all at once. 当您一次启动定位器和对等时,请使用此设置。 This timeout allows peers to wait for the locators to finish starting up before attempting to join the distributed system. 此超时允许对等方在尝试加入分布式系统之前等待定位器完成启动。

This specifically refers to a "peer member" joining the distributed system/cluster, and thus, may have not any effect from the client (cache). 这具体是指加入分布式系统/集群的“对等成员”,因此可能对客户端(缓存)没有任何影响。

In which case, I have employed other techniques using Spring (specifically in integration tests involving a client/server topology) to cause the client to block waiting for the Server (or Locator) to become available. 在这种情况下,我使用了其他使用Spring的技术(特别是在涉及客户端/服务器拓扑的集成测试中),导致客户端阻塞等待服务器(或定位器)变得可用。 In my tests, the test forks a separate GemFire JVM process to run the Server while the test VM serves as the cache client. 在我的测试中,测试分支一个单独的GemFire JVM进程来运行服务器,而测试VM用作缓存客户端。

You can see examples of this in my most recent development effort by integrating GemFire with Spring Session , specifically, in the httpsession-gemfire-clientserver sample. 您可以通过将GemFire与Spring Session集成,特别是在httpsession-gemfire-clientserver示例中,在我最近的开发工作中看到这方面的示例。

Here, I used a BeanPostProcessor that causes the client cache, and specifically the PoolFactoryBean/Pool, to block (in postProcessBeforeInitialization(..) ) preventing the Pool from being fully initialized until the Server is available (could also apply to a Locator). 在这里,我使用BeanPostProcessor导致客户端缓存,特别是PoolFactoryBean / Pool,阻止(在postProcessBeforeInitialization(..) )阻止池完全初始化,直到服务器可用(也可以应用于Locator)。

The wait just attempts to open a Socket connection to the Server (or Locator) to verify connectivity. 等待只是尝试打开与服务器 (或定位器) 的Socket连接以验证连接。

Another approach is to create a CountDownLatch , use it in a registered GemFire ClientMembershipListener and combine it with, again, the BeanPostProcessor , only in the postProcessAfterInitialization(..) method this time. 另一种方法是创建一个CountDownLatch ,在注册的GemFire ClientMembershipListener使用它,并再次将它与BeanPostProcessor相结合,这次只在postProcessAfterInitialization(..)方法中。

Technically, only 1 of the 2 approaches are necessary. 从技术上讲,这两种方法中只有一种是必要的。 While, I used this for testing purposes, this can be used for, and is not uncommon in, an actual application as well. 虽然我将其用于测试目的,但它也可用于实际应用程序,并且在实际应用程序中也不常见。

Ideally, however, you are starting your Locators before anything else, since forming a cluster depends on it. 但是,理想情况下,您首先要启动Locator,因为形成一个集群取决于它。

Hope this helps. 希望这可以帮助。

Cheers! 干杯! John 约翰

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

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