使用PCF Registry Service和hazelcast-eureka-plugin进行Hazelcast成员发现

时间:2019-01-31 12:09:01

标签: spring-cloud hazelcast pivotal-cloud-foundry service-discovery

在PCF上运行具有嵌入式hazelcast的多个应用程序实例。我的目标是将hazelcast成员链接到集群。出于成员发现的目的,我使用了 hazelcast-eureka插件。我可以使用简单的Eureka Server应用程序实现成员发现,并使用this示例将eureka URL传递给 hazelcast-eureka插件。 现在,我想使用PCF Registry Service代替Eureka Server应用程序。为此,我将EurekaOneDiscoveryStrategyFactoryEurekaClient自动连线一起使用,该连线已配置PCF注册表服务属性。

问题是-我的hazelcast成员通过PCF Registry Service进行了网络注册,因此无法互相发现。虽然我可以看到我的应用程序实例已通过PCF Registry Service注册。

实例配置:

@Autowired
private EurekaClient eurekaClient;

@Bean
public HazelcastInstance hazelcastInstance() {
    return Hazelcast.newHazelcastInstance(cloudConfig());

}

@Bean
public Config cloudConfig(){
    Config config = new Config();
    config.getGroupConfig().setName( "hazelcast-test" );
    config.setProperty("hazelcast.discovery.enabled", Boolean.TRUE.toString());

    JoinConfig join = config.getNetworkConfig().getJoin();
    join.getMulticastConfig().setEnabled(false);

    EurekaOneDiscoveryStrategyFactory.setEurekaClient(eurekaClient);
    final EurekaOneDiscoveryStrategyFactory eurekaOneDiscoveryStrategyFactory = new EurekaOneDiscoveryStrategyFactory();

    DiscoveryStrategyConfig discoveryStrategyConfig =new DiscoveryStrategyConfig(eurekaOneDiscoveryStrategyFactory);
    discoveryStrategyConfig.addProperty("self-registration", true);
    discoveryStrategyConfig.addProperty("namespace", "hazelcast-test");
    discoveryStrategyConfig.addProperty("use-classpath-eureka-client-props", false);
    discoveryStrategyConfig.addProperty("shouldUseDns", false);
    discoveryStrategyConfig.addProperty("datacenter", "cloud");
    discoveryStrategyConfig.addProperty("name", "hazelcast-test");
    discoveryStrategyConfig.addProperty("use-metadata-for-host-and-port", false);
    discoveryStrategyConfig.addProperty("skip-eureka-registration-verification", false);


    DiscoveryConfig discoveryConfig = new DiscoveryConfig();
    discoveryConfig.addDiscoveryStrategyConfig( discoveryStrategyConfig );
    join.setDiscoveryConfig( discoveryConfig );
    return config;
}

pom.xml:

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.19.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>eureka-client-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>eureka-client-demo</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
    <spring-cloud-services.version>1.6.6.RELEASE</spring-cloud-services.version>
    <spring-cloud.version>Edgware.SR5</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>io.pivotal.spring.cloud</groupId>
        <artifactId>spring-cloud-services-starter-service-registry</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.hazelcast</groupId>
        <artifactId>hazelcast-eureka-one</artifactId>
        <version>1.0.2</version>
    </dependency>

</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>io.pivotal.spring.cloud</groupId>
            <artifactId>spring-cloud-services-dependencies</artifactId>
            <version>${spring-cloud-services.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
    </repository>
</repositories>

0 个答案:

没有答案