Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
[#123]heartbeat interval support configuration (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
liubao68 authored Aug 9, 2021
1 parent 394c884 commit 5baa3d6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public class CommonConfiguration {
// ###### service instance configuration ############### //
public static final String KEY_INSTANCE_ENVIRONMENT = "dubbo.servicecomb.instance.initialStatus";

public static final String KEY_INSTANCE_PULL_INTERVAL = "dubbo.servicecomb.instance.pull.interval";

public static final String KEY_INSTANCE_HEALTH_CHECK_INTERVAL = "dubbo.servicecomb.instance.healthCheck.interval";

public static final String KEY_INSTANCE_HEALTH_CHECK_TIMES = "dubbo.servicecomb.instance.healthCheck.times";

// ###### service center configuration ############### //
public static final String KEY_REGISTRY_ADDRESS = "dubbo.servicecomb.registry.address";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.servicecomb.config.center.client.AddressManager;
import org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;


public class ConfigCenterConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigCenterConfiguration.class);

private Environment environment;

public ConfigCenterConfiguration(Environment environment) {
Expand All @@ -45,6 +49,7 @@ public AddressManager createAddressManager() {
return null;
}
String project = environment.getProperty(KEY_SERVICE_PROJECT, "default");
LOGGER.info("Using config center, address={}", address);
return new AddressManager(project, Arrays.asList(address.split(",")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.servicecomb.config.kie.client.model.KieAddressManager;
import org.apache.servicecomb.config.kie.client.model.KieConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;


public class KieConfigConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(KieConfigConfiguration.class);

private Environment environment;

public KieConfigConfiguration(Environment environment) {
Expand All @@ -53,6 +57,7 @@ public KieAddressManager createKieAddressManager() {
return null;
}
KieAddressManager kieAddressManager = new KieAddressManager(Arrays.asList(address.split(",")));
LOGGER.info("Using kie, address={}", address);
return kieAddressManager;
}

Expand All @@ -66,9 +71,11 @@ public KieConfiguration createKieConfiguration() {
kieConfiguration.setCustomLabel(environment.getProperty(KEY_SERVICE_KIE_CUSTOMLABEL, "public"));
kieConfiguration.setCustomLabelValue(environment.getProperty(KEY_SERVICE_KIE_CUSTOMLABELVALUE, ""));
kieConfiguration
.setEnableCustomConfig(Boolean.parseBoolean(environment.getProperty(KEY_SERVICE_KIE_ENABLECUSTOMCONFIG, "true")));
.setEnableCustomConfig(
Boolean.parseBoolean(environment.getProperty(KEY_SERVICE_KIE_ENABLECUSTOMCONFIG, "true")));
kieConfiguration
.setEnableServiceConfig(Boolean.parseBoolean(environment.getProperty(KEY_SERVICE_KIE_ENABLESERVICECONFIG, "true")));
.setEnableServiceConfig(
Boolean.parseBoolean(environment.getProperty(KEY_SERVICE_KIE_ENABLESERVICECONFIG, "true")));
kieConfiguration
.setEnableAppConfig(Boolean.parseBoolean(environment.getProperty(KEY_SERVICE_KIE_ENABLEAPPCONFIG, "true")));
kieConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.huaweicloud.dubbo.discovery;

import static com.huaweicloud.dubbo.common.CommonConfiguration.DEFAULT_PROJECT;
import static com.huaweicloud.dubbo.common.CommonConfiguration.KEY_INSTANCE_PULL_INTERVAL;
import static com.huaweicloud.dubbo.common.CommonConfiguration.KEY_REGISTRY_WATCH;

import java.io.IOException;
Expand Down Expand Up @@ -220,6 +221,7 @@ public void onApplicationEvent(ApplicationEvent applicationEvent) {
EventManager.getEventBus());
serviceCenterRegistration.setMicroservice(microservice);
serviceCenterRegistration.setMicroserviceInstance(instance);
serviceCenterRegistration.setHeartBeatInterval(instance.getHealthCheck().getInterval());
addSchemaInfo(serviceCenterRegistration);
serviceCenterRegistration.startRegistration();

Expand Down Expand Up @@ -358,6 +360,8 @@ public void onMicroserviceRegistrationEvent(MicroserviceRegistrationEvent event)
if (serviceCenterDiscovery == null) {
serviceCenterDiscovery = new ServiceCenterDiscovery(client, EventManager.getEventBus());
serviceCenterDiscovery.updateMyselfServiceId(microservice.getServiceId());
serviceCenterDiscovery
.setPollInterval(Integer.parseInt(environment.getProperty(KEY_INSTANCE_PULL_INTERVAL, "15")));
serviceCenterDiscovery.startDiscovery();
} else {
serviceCenterDiscovery.updateMyselfServiceId(microservice.getServiceId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

package com.huaweicloud.dubbo.discovery;

import static com.huaweicloud.dubbo.common.CommonConfiguration.KEY_CONFIG_ADDRESSTYPE;
import static com.huaweicloud.dubbo.common.CommonConfiguration.KEY_INSTANCE_ENVIRONMENT;
import static com.huaweicloud.dubbo.common.CommonConfiguration.KEY_INSTANCE_HEALTH_CHECK_INTERVAL;
import static com.huaweicloud.dubbo.common.CommonConfiguration.KEY_INSTANCE_HEALTH_CHECK_TIMES;
import static com.huaweicloud.dubbo.common.CommonConfiguration.KEY_REGISTRY_ADDRESS;
import static com.huaweicloud.dubbo.common.CommonConfiguration.KEY_SERVICE_APPLICATION;
import static com.huaweicloud.dubbo.common.CommonConfiguration.KEY_SERVICE_ENVIRONMENT;
Expand All @@ -31,6 +32,8 @@
import org.apache.dubbo.registry.support.AbstractRegistryFactory;
import org.apache.servicecomb.service.center.client.AddressManager;
import org.apache.servicecomb.service.center.client.model.Framework;
import org.apache.servicecomb.service.center.client.model.HealthCheck;
import org.apache.servicecomb.service.center.client.model.HealthCheckMode;
import org.apache.servicecomb.service.center.client.model.Microservice;
import org.apache.servicecomb.service.center.client.model.MicroserviceInstance;
import org.apache.servicecomb.service.center.client.model.MicroserviceInstanceStatus;
Expand Down Expand Up @@ -70,14 +73,18 @@ public Microservice createMicroservice() {
public MicroserviceInstance createMicroserviceInstance() {
MicroserviceInstance instance = new MicroserviceInstance();
instance.setStatus(MicroserviceInstanceStatus.valueOf(environment.getProperty(KEY_INSTANCE_ENVIRONMENT, "UP")));
HealthCheck healthCheck = new HealthCheck();
healthCheck.setMode(HealthCheckMode.pull);
healthCheck.setInterval(Integer.parseInt(environment.getProperty(KEY_INSTANCE_HEALTH_CHECK_INTERVAL, "15")));
healthCheck.setTimes(Integer.parseInt(environment.getProperty(KEY_INSTANCE_HEALTH_CHECK_TIMES, "3")));
instance.setHealthCheck(healthCheck);
return instance;
}

public AddressManager createAddressManager() {
String address = environment.getProperty(KEY_REGISTRY_ADDRESS, "http://127.0.0.1:30100");
String project = environment.getProperty(KEY_SERVICE_PROJECT, "default");
String type = environment.getProperty(KEY_CONFIG_ADDRESSTYPE, "");
LOGGER.info("initialize config server type={}, address={}.", type, address);
LOGGER.info("Using service center, address={}.", address);
return new AddressManager(project, Arrays.asList(address.split(",")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.Set;

import org.apache.servicecomb.config.common.ConfigurationChangedEvent;
import org.apache.servicecomb.governance.event.GovernanceConfigurationChangedEvent;
import org.apache.servicecomb.governance.event.GovernanceEventManager;
import org.springframework.stereotype.Component;

import com.google.common.eventbus.Subscribe;
Expand All @@ -39,9 +41,9 @@ public void onKieConfigurationChangedEvent(ConfigurationChangedEvent event) {
addMap(changedKeys, event.getAdded());
addMap(changedKeys, event.getUpdated());
addMap(changedKeys, event.getDeleted());
org.apache.servicecomb.governance.event.ConfigurationChangedEvent newEvent =
new org.apache.servicecomb.governance.event.ConfigurationChangedEvent(changedKeys);
org.apache.servicecomb.governance.event.EventManager.post(newEvent);
GovernanceConfigurationChangedEvent newEvent =
new GovernanceConfigurationChangedEvent(changedKeys);
GovernanceEventManager.post(newEvent);
}

private void addMap(Set<String> keys, Map<String, Object> changed) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<java.version>1.8</java.version>
<spring-cloud-huawei.version>1.3.4</spring-cloud-huawei.version>
<dubbo.version>2.7.8</dubbo.version>
<servicecomb.version>2.3.5</servicecomb.version>
<servicecomb.version>2.3.6</servicecomb.version>
<jackson.version>2.10.0</jackson.version>
<spring-boot.version>2.1.6.RELEASE</spring-boot.version>
<spring.version>5.1.14.RELEASE</spring.version>
Expand Down

0 comments on commit 5baa3d6

Please sign in to comment.