Hazelcast member discovery with PCF Registry Service and hazelcast-eureka-plugin

前提是你 提交于 2021-01-07 04:09:19

问题


Running several instances of application with embedded hazelcast on PCF. My goal is to chain hazelcast members into cluster. For purpose of member discovery I am using hazelcast-eureka plugin. I am able to achieve member discovery using simple Eureka Server app, passing eureka URL to hazelcast-eureka plugin, using this example. Now I want to use PCF Registry Service instead of Eureka Server app. For that purpose I am using EurekaOneDiscoveryStrategyFactory with EurekaClient autowired which is configured with PCF Registry Service properies.

Issue is - my hazelcast members do net get registered by PCF Registry Service, hence can not discover each other. Though I can see my application instances get registered by PCF Registry Service.

Instance config:

@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>

来源:https://stackoverflow.com/questions/54460282/hazelcast-member-discovery-with-pcf-registry-service-and-hazelcast-eureka-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!