use of com.tencent.polaris.api.rpc.InstanceHeartbeatRequest in project polaris-java by polarismesh.
the class Provider method heartbeat.
// do the instance heartbeat
private static void heartbeat(String namespace, String service, String host, int port, ProviderAPI providerAPI) {
// do heartbeat
InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest();
heartbeatRequest.setNamespace(namespace);
heartbeatRequest.setService(service);
heartbeatRequest.setHost(host);
heartbeatRequest.setPort(port);
providerAPI.heartbeat(heartbeatRequest);
System.out.printf("heartbeat instance, address is %s:%d%n", host, port);
}
use of com.tencent.polaris.api.rpc.InstanceHeartbeatRequest in project sofa-rpc by sofastack.
the class PolarisRegistry method heartbeatPolaris.
private void heartbeatPolaris(InstanceRegisterRequest service) {
try {
InstanceHeartbeatRequest instanceHeartbeatRequest = new InstanceHeartbeatRequest();
instanceHeartbeatRequest.setNamespace(service.getNamespace());
instanceHeartbeatRequest.setService(service.getService());
instanceHeartbeatRequest.setHost(service.getHost());
instanceHeartbeatRequest.setPort(service.getPort());
providerAPI.heartbeat(instanceHeartbeatRequest);
} catch (Exception e) {
LOGGER.error(LogCodes.getLog(LogCodes.ERROR_CHECK_PASS, "Polaris"), e);
}
}
use of com.tencent.polaris.api.rpc.InstanceHeartbeatRequest 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.rpc.InstanceHeartbeatRequest in project polaris-java-agent by polarismesh.
the class PolarisServiceRegistry method heartbeat.
private void heartbeat() {
String host = polarisProperties.getHost();
Integer port = polarisProperties.getPort();
InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest();
heartbeatRequest.setNamespace(polarisProperties.getNamespace());
heartbeatRequest.setService(polarisProperties.getService());
heartbeatRequest.setHost(host);
heartbeatRequest.setPort(port);
try {
heartbeatExecutor.scheduleWithFixedDelay(() -> {
PolarisAPIFactory.getProviderApi().heartbeat(heartbeatRequest);
log.info("heartbeat instance, address is {}:{}", host, port);
}, ttl, ttl, TimeUnit.SECONDS);
} catch (PolarisException e) {
log.error(e.getMessage());
}
}
Aggregations