|
|
@ -61,6 +61,7 @@ import org.springframework.http.HttpHeaders;
|
|
|
|
|
|
|
|
|
|
|
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
|
|
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
|
|
|
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
|
|
|
|
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Service registry of Polaris.
|
|
|
|
* Service registry of Polaris.
|
|
|
@ -80,6 +81,12 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
|
|
|
|
private final StaticMetadataManager staticMetadataManager;
|
|
|
|
private final StaticMetadataManager staticMetadataManager;
|
|
|
|
private final PolarisStatProperties polarisStatProperties;
|
|
|
|
private final PolarisStatProperties polarisStatProperties;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${spring.cloud.polaris.discovery.heartbeat-enabled:true}")
|
|
|
|
|
|
|
|
private Boolean heartbeatEnabled = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${spring.cloud.polaris.discovery.heartbeat-interval:5}")
|
|
|
|
|
|
|
|
private Integer heartbeatInterval = 5;
|
|
|
|
|
|
|
|
|
|
|
|
public PolarisServiceRegistry(PolarisDiscoveryProperties polarisDiscoveryProperties,
|
|
|
|
public PolarisServiceRegistry(PolarisDiscoveryProperties polarisDiscoveryProperties,
|
|
|
|
PolarisSDKContextManager polarisSDKContextManager, PolarisDiscoveryHandler polarisDiscoveryHandler,
|
|
|
|
PolarisSDKContextManager polarisSDKContextManager, PolarisDiscoveryHandler polarisDiscoveryHandler,
|
|
|
|
StaticMetadataManager staticMetadataManager, PolarisStatProperties polarisStatProperties) {
|
|
|
|
StaticMetadataManager staticMetadataManager, PolarisStatProperties polarisStatProperties) {
|
|
|
@ -129,12 +136,14 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
|
|
|
|
ProviderAPI providerClient = polarisSDKContextManager.getProviderAPI();
|
|
|
|
ProviderAPI providerClient = polarisSDKContextManager.getProviderAPI();
|
|
|
|
InstanceRegisterResponse instanceRegisterResponse;
|
|
|
|
InstanceRegisterResponse instanceRegisterResponse;
|
|
|
|
|
|
|
|
|
|
|
|
if (!polarisDiscoveryProperties.getHeartbeatEnabled()) {
|
|
|
|
// 结合heartbeatEnabled和healthCheckUrl判断
|
|
|
|
// Use register() when heartbeat is disabled - this doesn't start the SDK's heartbeat
|
|
|
|
if (!polarisDiscoveryProperties.getHeartbeatEnabled()
|
|
|
|
|
|
|
|
|| StringUtils.isBlank(polarisDiscoveryProperties.getHealthCheckUrl())) {
|
|
|
|
|
|
|
|
// 不启用心跳 或 未配置healthCheckUrl
|
|
|
|
instanceRegisterResponse = providerClient.register(instanceRegisterRequest);
|
|
|
|
instanceRegisterResponse = providerClient.register(instanceRegisterRequest);
|
|
|
|
LOGGER.info("Registered instance without heartbeat.");
|
|
|
|
LOGGER.info("Registered instance without heartbeat.");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Use registerInstance() when heartbeat is enabled - this starts the SDK's heartbeat
|
|
|
|
// 启用心跳 且 配置了healthCheckUrl
|
|
|
|
instanceRegisterRequest.setTtl(polarisDiscoveryProperties.getHeartbeatInterval());
|
|
|
|
instanceRegisterRequest.setTtl(polarisDiscoveryProperties.getHeartbeatInterval());
|
|
|
|
instanceRegisterResponse = providerClient.registerInstance(instanceRegisterRequest);
|
|
|
|
instanceRegisterResponse = providerClient.registerInstance(instanceRegisterRequest);
|
|
|
|
LOGGER.info("Registered instance with heartbeat enabled.");
|
|
|
|
LOGGER.info("Registered instance with heartbeat enabled.");
|
|
|
|