use of com.paascloud.core.registry.base.CoordinatorRegistryCenter in project paascloud-master by paascloud.
the class MqBeanInitRunner method run.
/**
* Run.
*
* @param args the args
*/
@Override
public void run(String... args) throws Exception {
CoordinatorRegistryCenter coordinatorRegistryCenter = RegistryCenterFactory.createCoordinatorRegistryCenter(paascloudProperties.getZk());
List<String> childrenKeys = coordinatorRegistryCenter.getChildrenKeys(GlobalConstant.ZK_REGISTRY_PRODUCER_ROOT_PATH);
this.initMqListener(coordinatorRegistryCenter);
for (final String childrenKey : childrenKeys) {
int count = coordinatorRegistryCenter.getNumChildren(GlobalConstant.ZK_REGISTRY_PRODUCER_ROOT_PATH + GlobalConstant.Symbol.SLASH + childrenKey);
if (count == 0) {
continue;
}
String producerString = coordinatorRegistryCenter.getDirectly(GlobalConstant.ZK_REGISTRY_PRODUCER_ROOT_PATH + GlobalConstant.Symbol.SLASH + childrenKey);
ReliableMessageRegisterDto producerDto = JSON.parseObject(producerString, ReliableMessageRegisterDto.class);
MqProducerBeanFactory.buildProducerBean(producerDto);
try {
tpcMqProducerService.updateOnLineStatusByPid(producerDto.getProducerGroup());
} catch (Exception e) {
log.error("更新生产者状态为离线出现异常, ex={}", e.getMessage(), e);
}
}
}
use of com.paascloud.core.registry.base.CoordinatorRegistryCenter in project paascloud-master by paascloud.
the class RegistryCenterFactory method createCoordinatorRegistryCenter.
/**
* 创建注册中心.
*
* @param zookeeperProperties the zookeeper properties
*
* @return 注册中心对象 coordinator registry center
*/
public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(ZookeeperProperties zookeeperProperties) {
Hasher hasher = Hashing.md5().newHasher().putString(zookeeperProperties.getZkAddressList(), Charsets.UTF_8);
HashCode hashCode = hasher.hash();
CoordinatorRegistryCenter result = REG_CENTER_REGISTRY.get(hashCode);
if (null != result) {
return result;
}
result = new ZookeeperRegistryCenter(zookeeperProperties);
result.init();
REG_CENTER_REGISTRY.put(hashCode, result);
return result;
}
use of com.paascloud.core.registry.base.CoordinatorRegistryCenter in project paascloud-master by paascloud.
the class IncrementIdGenerator method nextId.
/**
* Next id long.
*
* @return the long
*/
@Override
public Long nextId() {
String app = this.registerDto.getApp();
String host = this.registerDto.getHost();
CoordinatorRegistryCenter regCenter = this.registerDto.getCoordinatorRegistryCenter();
String path = GlobalConstant.ZK_REGISTRY_ID_ROOT_PATH + GlobalConstant.Symbol.SLASH + app + GlobalConstant.Symbol.SLASH + host;
if (regCenter.isExisted(path)) {
// 如果已经有该节点,表示已经为当前的host上部署的该app分配的编号(应对某个服务重启之后编号不变的问题),直接获取该id,而无需生成
return Long.valueOf(regCenter.getDirectly(GlobalConstant.ZK_REGISTRY_ID_ROOT_PATH + GlobalConstant.Symbol.SLASH + app + GlobalConstant.Symbol.SLASH + host));
} else {
// 节点不存在,那么需要生成id,利用zk节点的版本号每写一次就自增的机制来实现
regCenter.increment(GlobalConstant.ZK_REGISTRY_SEQ, new RetryNTimes(2000, 3));
// 生成id
Integer id = regCenter.getAtomicValue(GlobalConstant.ZK_REGISTRY_SEQ, new RetryNTimes(2000, 3)).postValue();
// 将数据写入节点
regCenter.persist(path);
regCenter.persist(path, String.valueOf(id));
return Long.valueOf(id);
}
}
use of com.paascloud.core.registry.base.CoordinatorRegistryCenter in project paascloud-master by paascloud.
the class RegistryCenterFactory method registerMq.
private static void registerMq(PaascloudProperties paascloudProperties, String host, String app) {
CoordinatorRegistryCenter coordinatorRegistryCenter = createCoordinatorRegistryCenter(paascloudProperties.getZk());
AliyunProperties.RocketMqProperties rocketMq = paascloudProperties.getAliyun().getRocketMq();
String consumerGroup = rocketMq.isReliableMessageConsumer() ? rocketMq.getConsumerGroup() : null;
String namesrvAddr = rocketMq.getNamesrvAddr();
String producerGroup = rocketMq.isReliableMessageProducer() ? rocketMq.getProducerGroup() : null;
coordinatorRegistryCenter.registerMq(app, host, producerGroup, consumerGroup, namesrvAddr);
}
use of com.paascloud.core.registry.base.CoordinatorRegistryCenter in project paascloud-master by paascloud.
the class RegistryCenterFactory method startup.
/**
* Startup.
*
* @param paascloudProperties the paascloud properties
* @param host the host
* @param app the app
*/
public static void startup(PaascloudProperties paascloudProperties, String host, String app) {
CoordinatorRegistryCenter coordinatorRegistryCenter = createCoordinatorRegistryCenter(paascloudProperties.getZk());
RegisterDto dto = new RegisterDto(app, host, coordinatorRegistryCenter);
Long serviceId = new IncrementIdGenerator(dto).nextId();
IncrementIdGenerator.setServiceId(serviceId);
registerMq(paascloudProperties, host, app);
}
Aggregations