hazelcast / hazelcast-eureka

Hazelcast Discovery SPI Plugin for Netflix' Eureka Service Discovery V1
Other
30 stars 27 forks source link

Hazelcast Client registers itself on Eureka with Dynamic Conf #39

Open gokhansari opened 5 years ago

gokhansari commented 5 years ago

According to documentation:

Note: Hazelcast clients do not register themselves to Eureka server, therefore self-registration property has no effect.

If I set use-classpath-eureka-client-props false and configure my HZ Client eureka config programmatically like below, Client tries to register itself as a new second app on Eureka server (with name member-app) even I set self-registration to false.

There is no problem If I go with eureka-client.properties file, but I don't want to prefer that way.

Hazelcast client version: 3.12.3 Hazelcast eureka one version: 1.1.2

final ClientConfig config = new ClientConfig();

config
    .getGroupConfig()
    .setName(cacheProperties.getGroup().getName());

final ClientNetworkConfig netConfig = config.getNetworkConfig();

netConfig.getEurekaConfig()
    .setEnabled(true)
    .setProperty("serviceUrl.default", "localhost:8761/eureka/")
    .setProperty("name", "member-app")
    .setProperty("use-classpath-eureka-client-props", "false")
    .setProperty("shouldUseDns", "false");

return HazelcastClient.newHazelcastClient(config);
gokhansari commented 5 years ago

I dived into source code a little bit and find a workaround for this issue. Setting use-classpath-eureka-client-props to false, causes creating EurekaClientConfig based on PropertyBasedEurekaClientConfig impl instead of EurekaOneAwareConfig.

if (useClasspathEurekaClientProps) {
    eurekaClientConfig = new EurekaOneAwareConfig(this.namespace);
} else {
    eurekaClientConfig = new PropertyBasedEurekaClientConfig(
            this.namespace,
            getEurekaClientProperties(this.namespace, this.getProperties()));
}

shouldRegisterWithEureka implementation of PropertyBasedEurekaClientConfig returns true for default value.

@Override
public boolean shouldRegisterWithEureka() {
    return configInstance.getBooleanProperty(
            namespace + REGISTRATION_ENABLED_KEY, true).get();
}

As a workaround: depending of these findings I set network eureka configuration for hazelcast client like below and problem is solved.

netConfig.getEurekaConfig()
    .setProperty("registration.enabled", "false")