use of com.tencent.polaris.api.core.ProviderAPI in project polaris-java-agent by polarismesh.
the class PolarisServiceRegistry method register.
/**
* 服务注册
*
* @param registration
*/
@Override
public void register(Registration registration) {
if (StringUtils.isEmpty(polarisRegistration.getServiceId())) {
log.warn("No service to register for polaris client...");
return;
}
// 注册实例
InstanceRegisterRequest instanceRegisterRequest = new InstanceRegisterRequest();
instanceRegisterRequest.setNamespace(polarisProperties.getNamespace());
instanceRegisterRequest.setService(polarisRegistration.getServiceId());
instanceRegisterRequest.setHost(polarisRegistration.getHost());
instanceRegisterRequest.setPort(polarisRegistration.getPort());
instanceRegisterRequest.setProtocol(polarisProperties.getProtocol());
if (null != heartbeatExecutor) {
instanceRegisterRequest.setTtl(ttl);
}
try {
ProviderAPI providerClient = PolarisAPIFactory.getProviderApi();
providerClient.register(instanceRegisterRequest);
log.info("Polaris register success with address host:{}, port:{}", polarisRegistration.getHost(), polarisRegistration.getPort());
if (null != heartbeatExecutor) {
InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest();
BeanUtils.copyProperties(instanceRegisterRequest, heartbeatRequest);
// 添加反注册Hook
// 注册成功后开始启动心跳线程
heartbeat();
}
} catch (Exception e) {
log.error("polaris registry, {} register failed...{},", polarisRegistration.getServiceId(), polarisRegistration, e);
rethrowRuntimeException(e);
}
}
use of com.tencent.polaris.api.core.ProviderAPI in project polaris-java-agent by polarismesh.
the class PolarisServiceRegistry method deregister.
/**
* 服务反注册
*
* @param registration
*/
@Override
public void deregister(Registration registration) {
log.info("De-registering from Polaris Server now...");
if (StringUtils.isEmpty(polarisRegistration.getServiceId())) {
log.warn("No dom to de-register for polaris client...");
return;
}
InstanceDeregisterRequest deRegisterRequest = new InstanceDeregisterRequest();
deRegisterRequest.setNamespace(polarisProperties.getNamespace());
deRegisterRequest.setService(polarisRegistration.getServiceId());
deRegisterRequest.setHost(polarisRegistration.getHost());
deRegisterRequest.setPort(polarisRegistration.getPort());
try {
ProviderAPI providerClient = PolarisAPIFactory.getProviderApi();
providerClient.deRegister(deRegisterRequest);
} catch (Exception e) {
log.error("ERR_POLARIS_DEREGISTER, de-register failed...{},", polarisRegistration, e);
} finally {
if (null != heartbeatExecutor) {
heartbeatExecutor.shutdown();
}
}
log.info("De-registration finished.");
}
Aggregations